Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 14 | #include <linux/firmware.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 15 | #include <linux/slab.h> |
| 16 | #include <linux/platform_device.h> |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 17 | #include <linux/device.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 18 | #include <linux/printk.h> |
| 19 | #include <linux/ratelimit.h> |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 20 | #include <linux/debugfs.h> |
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> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 36 | #include "wcd9310.h" |
| 37 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 38 | #define WCD9310_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ |
| 39 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\ |
| 40 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000) |
| 41 | |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 42 | |
| 43 | #define NUM_DECIMATORS 10 |
| 44 | #define NUM_INTERPOLATORS 7 |
| 45 | #define BITS_PER_REG 8 |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 46 | #define TABLA_CFILT_FAST_MODE 0x00 |
| 47 | #define TABLA_CFILT_SLOW_MODE 0x40 |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 48 | #define MBHC_FW_READ_ATTEMPTS 15 |
| 49 | #define MBHC_FW_READ_TIMEOUT 2000000 |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 50 | |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 51 | #define SLIM_CLOSE_TIMEOUT 1000 |
| 52 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 53 | enum { |
| 54 | MBHC_USE_HPHL_TRIGGER = 1, |
| 55 | MBHC_USE_MB_TRIGGER = 2 |
| 56 | }; |
| 57 | |
| 58 | #define MBHC_NUM_DCE_PLUG_DETECT 3 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 59 | #define NUM_ATTEMPTS_INSERT_DETECT 25 |
| 60 | #define NUM_ATTEMPTS_TO_REPORT 5 |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 61 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 62 | #define TABLA_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | \ |
| 63 | SND_JACK_OC_HPHR | SND_JACK_UNSUPPORTED) |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 64 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 65 | #define TABLA_I2S_MASTER_MODE_MASK 0x08 |
| 66 | |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 67 | #define TABLA_OCP_ATTEMPT 1 |
| 68 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 69 | #define AIF1_PB 1 |
| 70 | #define AIF1_CAP 2 |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 71 | #define AIF2_PB 3 |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 72 | #define AIF2_CAP 4 |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 73 | #define AIF3_CAP 5 |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 74 | #define AIF3_PB 6 |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 75 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 76 | #define NUM_CODEC_DAIS 6 |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 77 | #define TABLA_COMP_DIGITAL_GAIN_OFFSET 3 |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 78 | |
| 79 | struct tabla_codec_dai_data { |
| 80 | u32 rate; |
| 81 | u32 *ch_num; |
| 82 | u32 ch_act; |
| 83 | u32 ch_tot; |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 84 | u32 ch_mask; |
| 85 | wait_queue_head_t dai_wait; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 86 | }; |
| 87 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 88 | #define TABLA_MCLK_RATE_12288KHZ 12288000 |
| 89 | #define TABLA_MCLK_RATE_9600KHZ 9600000 |
| 90 | |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 91 | #define TABLA_FAKE_INS_THRESHOLD_MS 2500 |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 92 | #define TABLA_FAKE_REMOVAL_MIN_PERIOD_MS 50 |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 93 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 94 | #define TABLA_MBHC_BUTTON_MIN 0x8000 |
| 95 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 96 | #define TABLA_MBHC_FAKE_INSERT_LOW 10 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 97 | #define TABLA_MBHC_FAKE_INSERT_HIGH 80 |
| 98 | #define TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO 150 |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 99 | |
| 100 | #define TABLA_MBHC_STATUS_REL_DETECTION 0x0C |
| 101 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 102 | #define TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS 200 |
| 103 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 104 | #define TABLA_MBHC_FAKE_INS_DELTA_MV 200 |
| 105 | #define TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV 300 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 106 | |
| 107 | #define TABLA_HS_DETECT_PLUG_TIME_MS (5 * 1000) |
| 108 | #define TABLA_HS_DETECT_PLUG_INERVAL_MS 100 |
| 109 | |
| 110 | #define TABLA_GPIO_IRQ_DEBOUNCE_TIME_US 5000 |
| 111 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 112 | #define TABLA_MBHC_GND_MIC_SWAP_THRESHOLD 2 |
| 113 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 114 | #define TABLA_ACQUIRE_LOCK(x) do { mutex_lock(&x); } while (0) |
| 115 | #define TABLA_RELEASE_LOCK(x) do { mutex_unlock(&x); } while (0) |
| 116 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 117 | static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0); |
| 118 | static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1); |
| 119 | static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 120 | static struct snd_soc_dai_driver tabla_dai[]; |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 121 | static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 122 | static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
| 123 | struct snd_kcontrol *kcontrol, int event); |
| 124 | static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
| 125 | struct snd_kcontrol *kcontrol, int event); |
| 126 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 127 | |
| 128 | enum tabla_bandgap_type { |
| 129 | TABLA_BANDGAP_OFF = 0, |
| 130 | TABLA_BANDGAP_AUDIO_MODE, |
| 131 | TABLA_BANDGAP_MBHC_MODE, |
| 132 | }; |
| 133 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 134 | struct mbhc_micbias_regs { |
| 135 | u16 cfilt_val; |
| 136 | u16 cfilt_ctl; |
| 137 | u16 mbhc_reg; |
| 138 | u16 int_rbias; |
| 139 | u16 ctl_reg; |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 140 | u8 cfilt_sel; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 143 | /* Codec supports 2 IIR filters */ |
| 144 | enum { |
| 145 | IIR1 = 0, |
| 146 | IIR2, |
| 147 | IIR_MAX, |
| 148 | }; |
| 149 | /* Codec supports 5 bands */ |
| 150 | enum { |
| 151 | BAND1 = 0, |
| 152 | BAND2, |
| 153 | BAND3, |
| 154 | BAND4, |
| 155 | BAND5, |
| 156 | BAND_MAX, |
| 157 | }; |
| 158 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 159 | enum { |
| 160 | COMPANDER_1 = 0, |
| 161 | COMPANDER_2, |
| 162 | COMPANDER_MAX, |
| 163 | }; |
| 164 | |
| 165 | enum { |
| 166 | COMPANDER_FS_8KHZ = 0, |
| 167 | COMPANDER_FS_16KHZ, |
| 168 | COMPANDER_FS_32KHZ, |
| 169 | COMPANDER_FS_48KHZ, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 170 | COMPANDER_FS_96KHZ, |
| 171 | COMPANDER_FS_192KHZ, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 172 | COMPANDER_FS_MAX, |
| 173 | }; |
| 174 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 175 | /* Flags to track of PA and DAC state. |
| 176 | * PA and DAC should be tracked separately as AUXPGA loopback requires |
| 177 | * only PA to be turned on without DAC being on. */ |
| 178 | enum tabla_priv_ack_flags { |
| 179 | TABLA_HPHL_PA_OFF_ACK = 0, |
| 180 | TABLA_HPHR_PA_OFF_ACK, |
| 181 | TABLA_HPHL_DAC_OFF_ACK, |
| 182 | TABLA_HPHR_DAC_OFF_ACK |
| 183 | }; |
| 184 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 185 | |
| 186 | struct comp_sample_dependent_params { |
| 187 | u32 peak_det_timeout; |
| 188 | u32 rms_meter_div_fact; |
| 189 | u32 rms_meter_resamp_fact; |
| 190 | }; |
| 191 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 192 | /* Data used by MBHC */ |
| 193 | struct mbhc_internal_cal_data { |
| 194 | u16 dce_z; |
| 195 | u16 dce_mb; |
| 196 | u16 sta_z; |
| 197 | u16 sta_mb; |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 198 | u32 t_sta_dce; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 199 | u32 t_dce; |
| 200 | u32 t_sta; |
| 201 | u32 micb_mv; |
| 202 | u16 v_ins_hu; |
| 203 | u16 v_ins_h; |
| 204 | u16 v_b1_hu; |
| 205 | u16 v_b1_h; |
| 206 | u16 v_b1_huc; |
| 207 | u16 v_brh; |
| 208 | u16 v_brl; |
| 209 | u16 v_no_mic; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 210 | u8 npoll; |
| 211 | u8 nbounce_wait; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 212 | s16 adj_v_hs_max; |
| 213 | u16 adj_v_ins_hu; |
| 214 | u16 adj_v_ins_h; |
| 215 | s16 v_inval_ins_low; |
| 216 | s16 v_inval_ins_high; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 217 | }; |
| 218 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 219 | struct tabla_reg_address { |
| 220 | u16 micb_4_ctl; |
| 221 | u16 micb_4_int_rbias; |
| 222 | u16 micb_4_mbhc; |
| 223 | }; |
| 224 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 225 | enum tabla_mbhc_plug_type { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 226 | PLUG_TYPE_INVALID = -1, |
| 227 | PLUG_TYPE_NONE, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 228 | PLUG_TYPE_HEADSET, |
| 229 | PLUG_TYPE_HEADPHONE, |
| 230 | PLUG_TYPE_HIGH_HPH, |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 231 | PLUG_TYPE_GND_MIC_SWAP, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | enum tabla_mbhc_state { |
| 235 | MBHC_STATE_NONE = -1, |
| 236 | MBHC_STATE_POTENTIAL, |
| 237 | MBHC_STATE_POTENTIAL_RECOVERY, |
| 238 | MBHC_STATE_RELEASE, |
| 239 | }; |
| 240 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 241 | struct hpf_work { |
| 242 | struct tabla_priv *tabla; |
| 243 | u32 decimator; |
| 244 | u8 tx_hpf_cut_of_freq; |
| 245 | struct delayed_work dwork; |
| 246 | }; |
| 247 | |
| 248 | static struct hpf_work tx_hpf_work[NUM_DECIMATORS]; |
| 249 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 250 | struct tabla_priv { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 251 | struct snd_soc_codec *codec; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 252 | struct tabla_reg_address reg_addr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 253 | u32 adc_count; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 254 | u32 cfilt1_cnt; |
| 255 | u32 cfilt2_cnt; |
| 256 | u32 cfilt3_cnt; |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 257 | u32 rx_bias_count; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 258 | s32 dmic_1_2_clk_cnt; |
| 259 | s32 dmic_3_4_clk_cnt; |
| 260 | s32 dmic_5_6_clk_cnt; |
| 261 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 262 | enum tabla_bandgap_type bandgap_type; |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 263 | bool mclk_enabled; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 264 | bool clock_active; |
| 265 | bool config_mode_active; |
| 266 | bool mbhc_polling_active; |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 267 | unsigned long mbhc_fake_ins_start; |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 268 | int buttons_pressed; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 269 | enum tabla_mbhc_state mbhc_state; |
| 270 | struct tabla_mbhc_config mbhc_cfg; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 271 | struct mbhc_internal_cal_data mbhc_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 272 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 273 | struct wcd9xxx_pdata *pdata; |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 274 | u32 anc_slot; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 275 | |
| 276 | bool no_mic_headset_override; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 277 | /* Delayed work to report long button press */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 278 | struct delayed_work mbhc_btn_dwork; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 279 | |
| 280 | struct mbhc_micbias_regs mbhc_bias_regs; |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 281 | bool mbhc_micbias_switched; |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 282 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 283 | /* track PA/DAC state */ |
| 284 | unsigned long hph_pa_dac_state; |
| 285 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 286 | /*track tabla interface type*/ |
| 287 | u8 intf_type; |
| 288 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 289 | u32 hph_status; /* track headhpone status */ |
| 290 | /* define separate work for left and right headphone OCP to avoid |
| 291 | * additional checking on which OCP event to report so no locking |
| 292 | * to ensure synchronization is required |
| 293 | */ |
| 294 | struct work_struct hphlocp_work; /* reporting left hph ocp off */ |
| 295 | struct work_struct hphrocp_work; /* reporting right hph ocp off */ |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 296 | |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 297 | u8 hphlocp_cnt; /* headphone left ocp retry */ |
| 298 | u8 hphrocp_cnt; /* headphone right ocp retry */ |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 299 | |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 300 | /* Work to perform MBHC Firmware Read */ |
| 301 | struct delayed_work mbhc_firmware_dwork; |
| 302 | const struct firmware *mbhc_fw; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 303 | |
| 304 | /* num of slim ports required */ |
| 305 | struct tabla_codec_dai_data dai[NUM_CODEC_DAIS]; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 306 | |
| 307 | /*compander*/ |
| 308 | int comp_enabled[COMPANDER_MAX]; |
| 309 | u32 comp_fs[COMPANDER_MAX]; |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 310 | |
| 311 | /* Maintain the status of AUX PGA */ |
| 312 | int aux_pga_cnt; |
| 313 | u8 aux_l_gain; |
| 314 | u8 aux_r_gain; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 315 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 316 | struct delayed_work mbhc_insert_dwork; |
| 317 | unsigned long mbhc_last_resume; /* in jiffies */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 318 | |
| 319 | u8 current_plug; |
| 320 | struct work_struct hs_correct_plug_work; |
| 321 | bool hs_detect_work_stop; |
| 322 | bool hs_polling_irq_prepared; |
| 323 | bool lpi_enabled; /* low power insertion detection */ |
| 324 | bool in_gpio_handler; |
| 325 | /* Currently, only used for mbhc purpose, to protect |
| 326 | * concurrent execution of mbhc threaded irq handlers and |
| 327 | * kill race between DAPM and MBHC.But can serve as a |
| 328 | * general lock to protect codec resource |
| 329 | */ |
| 330 | struct mutex codec_resource_lock; |
| 331 | |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 332 | #ifdef CONFIG_DEBUG_FS |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 333 | struct dentry *debugfs_poke; |
| 334 | struct dentry *debugfs_mbhc; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 335 | #endif |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 336 | }; |
| 337 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 338 | static const u32 comp_shift[] = { |
| 339 | 0, |
| 340 | 2, |
| 341 | }; |
| 342 | |
| 343 | static const int comp_rx_path[] = { |
| 344 | COMPANDER_1, |
| 345 | COMPANDER_1, |
| 346 | COMPANDER_2, |
| 347 | COMPANDER_2, |
| 348 | COMPANDER_2, |
| 349 | COMPANDER_2, |
| 350 | COMPANDER_MAX, |
| 351 | }; |
| 352 | |
| 353 | static const struct comp_sample_dependent_params comp_samp_params[] = { |
| 354 | { |
| 355 | .peak_det_timeout = 0x2, |
| 356 | .rms_meter_div_fact = 0x8 << 4, |
| 357 | .rms_meter_resamp_fact = 0x21, |
| 358 | }, |
| 359 | { |
| 360 | .peak_det_timeout = 0x3, |
| 361 | .rms_meter_div_fact = 0x9 << 4, |
| 362 | .rms_meter_resamp_fact = 0x28, |
| 363 | }, |
| 364 | |
| 365 | { |
| 366 | .peak_det_timeout = 0x5, |
| 367 | .rms_meter_div_fact = 0xB << 4, |
| 368 | .rms_meter_resamp_fact = 0x28, |
| 369 | }, |
| 370 | |
| 371 | { |
| 372 | .peak_det_timeout = 0x5, |
| 373 | .rms_meter_div_fact = 0xB << 4, |
| 374 | .rms_meter_resamp_fact = 0x28, |
| 375 | }, |
| 376 | }; |
| 377 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 378 | static unsigned short rx_digital_gain_reg[] = { |
| 379 | TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 380 | TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 381 | TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 382 | TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 383 | TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 384 | TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 385 | TABLA_A_CDC_RX7_VOL_CTL_B2_CTL, |
| 386 | }; |
| 387 | |
| 388 | |
| 389 | static unsigned short tx_digital_gain_reg[] = { |
| 390 | TABLA_A_CDC_TX1_VOL_CTL_GAIN, |
| 391 | TABLA_A_CDC_TX2_VOL_CTL_GAIN, |
| 392 | TABLA_A_CDC_TX3_VOL_CTL_GAIN, |
| 393 | TABLA_A_CDC_TX4_VOL_CTL_GAIN, |
| 394 | TABLA_A_CDC_TX5_VOL_CTL_GAIN, |
| 395 | TABLA_A_CDC_TX6_VOL_CTL_GAIN, |
| 396 | TABLA_A_CDC_TX7_VOL_CTL_GAIN, |
| 397 | TABLA_A_CDC_TX8_VOL_CTL_GAIN, |
| 398 | TABLA_A_CDC_TX9_VOL_CTL_GAIN, |
| 399 | TABLA_A_CDC_TX10_VOL_CTL_GAIN, |
| 400 | }; |
| 401 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 402 | static int tabla_codec_enable_charge_pump(struct snd_soc_dapm_widget *w, |
| 403 | struct snd_kcontrol *kcontrol, int event) |
| 404 | { |
| 405 | struct snd_soc_codec *codec = w->codec; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 406 | |
| 407 | pr_debug("%s %d\n", __func__, event); |
| 408 | switch (event) { |
| 409 | case SND_SOC_DAPM_POST_PMU: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 410 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01, |
| 411 | 0x01); |
| 412 | snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x08); |
| 413 | usleep_range(200, 200); |
| 414 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x00); |
| 415 | break; |
| 416 | case SND_SOC_DAPM_PRE_PMD: |
| 417 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10, |
| 418 | 0x10); |
| 419 | usleep_range(20, 20); |
| 420 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x08); |
| 421 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x10); |
| 422 | snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x00); |
| 423 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01, |
| 424 | 0x00); |
| 425 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x00); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 426 | break; |
| 427 | } |
| 428 | return 0; |
| 429 | } |
| 430 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 431 | static int tabla_get_anc_slot(struct snd_kcontrol *kcontrol, |
| 432 | struct snd_ctl_elem_value *ucontrol) |
| 433 | { |
| 434 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 435 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 436 | ucontrol->value.integer.value[0] = tabla->anc_slot; |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | static int tabla_put_anc_slot(struct snd_kcontrol *kcontrol, |
| 441 | struct snd_ctl_elem_value *ucontrol) |
| 442 | { |
| 443 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 444 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 445 | tabla->anc_slot = ucontrol->value.integer.value[0]; |
| 446 | return 0; |
| 447 | } |
| 448 | |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 449 | static int tabla_pa_gain_get(struct snd_kcontrol *kcontrol, |
| 450 | struct snd_ctl_elem_value *ucontrol) |
| 451 | { |
| 452 | u8 ear_pa_gain; |
| 453 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 454 | |
| 455 | ear_pa_gain = snd_soc_read(codec, TABLA_A_RX_EAR_GAIN); |
| 456 | |
| 457 | ear_pa_gain = ear_pa_gain >> 5; |
| 458 | |
| 459 | if (ear_pa_gain == 0x00) { |
| 460 | ucontrol->value.integer.value[0] = 0; |
| 461 | } else if (ear_pa_gain == 0x04) { |
| 462 | ucontrol->value.integer.value[0] = 1; |
| 463 | } else { |
| 464 | pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n", |
| 465 | __func__, ear_pa_gain); |
| 466 | return -EINVAL; |
| 467 | } |
| 468 | |
| 469 | pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain); |
| 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | static int tabla_pa_gain_put(struct snd_kcontrol *kcontrol, |
| 475 | struct snd_ctl_elem_value *ucontrol) |
| 476 | { |
| 477 | u8 ear_pa_gain; |
| 478 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 479 | |
| 480 | pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__, |
| 481 | ucontrol->value.integer.value[0]); |
| 482 | |
| 483 | switch (ucontrol->value.integer.value[0]) { |
| 484 | case 0: |
| 485 | ear_pa_gain = 0x00; |
| 486 | break; |
| 487 | case 1: |
| 488 | ear_pa_gain = 0x80; |
| 489 | break; |
| 490 | default: |
| 491 | return -EINVAL; |
| 492 | } |
| 493 | |
| 494 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_GAIN, 0xE0, ear_pa_gain); |
| 495 | return 0; |
| 496 | } |
| 497 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 498 | static int tabla_get_iir_enable_audio_mixer( |
| 499 | struct snd_kcontrol *kcontrol, |
| 500 | struct snd_ctl_elem_value *ucontrol) |
| 501 | { |
| 502 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 503 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 504 | kcontrol->private_value)->reg; |
| 505 | int band_idx = ((struct soc_multi_mixer_control *) |
| 506 | kcontrol->private_value)->shift; |
| 507 | |
| 508 | ucontrol->value.integer.value[0] = |
| 509 | snd_soc_read(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx)) & |
| 510 | (1 << band_idx); |
| 511 | |
| 512 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
| 513 | iir_idx, band_idx, |
| 514 | (uint32_t)ucontrol->value.integer.value[0]); |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | static int tabla_put_iir_enable_audio_mixer( |
| 519 | struct snd_kcontrol *kcontrol, |
| 520 | struct snd_ctl_elem_value *ucontrol) |
| 521 | { |
| 522 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 523 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 524 | kcontrol->private_value)->reg; |
| 525 | int band_idx = ((struct soc_multi_mixer_control *) |
| 526 | kcontrol->private_value)->shift; |
| 527 | int value = ucontrol->value.integer.value[0]; |
| 528 | |
| 529 | /* Mask first 5 bits, 6-8 are reserved */ |
| 530 | snd_soc_update_bits(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx), |
| 531 | (1 << band_idx), (value << band_idx)); |
| 532 | |
| 533 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
| 534 | iir_idx, band_idx, value); |
| 535 | return 0; |
| 536 | } |
| 537 | static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec, |
| 538 | int iir_idx, int band_idx, |
| 539 | int coeff_idx) |
| 540 | { |
| 541 | /* Address does not automatically update if reading */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 542 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 543 | (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 544 | (band_idx * BAND_MAX + coeff_idx) & 0x1F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 545 | |
| 546 | /* Mask bits top 2 bits since they are reserved */ |
| 547 | return ((snd_soc_read(codec, |
| 548 | (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 24) | |
| 549 | (snd_soc_read(codec, |
| 550 | (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx)) << 16) | |
| 551 | (snd_soc_read(codec, |
| 552 | (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx)) << 8) | |
| 553 | (snd_soc_read(codec, |
| 554 | (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx)))) & |
| 555 | 0x3FFFFFFF; |
| 556 | } |
| 557 | |
| 558 | static int tabla_get_iir_band_audio_mixer( |
| 559 | struct snd_kcontrol *kcontrol, |
| 560 | struct snd_ctl_elem_value *ucontrol) |
| 561 | { |
| 562 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 563 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 564 | kcontrol->private_value)->reg; |
| 565 | int band_idx = ((struct soc_multi_mixer_control *) |
| 566 | kcontrol->private_value)->shift; |
| 567 | |
| 568 | ucontrol->value.integer.value[0] = |
| 569 | get_iir_band_coeff(codec, iir_idx, band_idx, 0); |
| 570 | ucontrol->value.integer.value[1] = |
| 571 | get_iir_band_coeff(codec, iir_idx, band_idx, 1); |
| 572 | ucontrol->value.integer.value[2] = |
| 573 | get_iir_band_coeff(codec, iir_idx, band_idx, 2); |
| 574 | ucontrol->value.integer.value[3] = |
| 575 | get_iir_band_coeff(codec, iir_idx, band_idx, 3); |
| 576 | ucontrol->value.integer.value[4] = |
| 577 | get_iir_band_coeff(codec, iir_idx, band_idx, 4); |
| 578 | |
| 579 | pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n" |
| 580 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 581 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 582 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 583 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 584 | __func__, iir_idx, band_idx, |
| 585 | (uint32_t)ucontrol->value.integer.value[0], |
| 586 | __func__, iir_idx, band_idx, |
| 587 | (uint32_t)ucontrol->value.integer.value[1], |
| 588 | __func__, iir_idx, band_idx, |
| 589 | (uint32_t)ucontrol->value.integer.value[2], |
| 590 | __func__, iir_idx, band_idx, |
| 591 | (uint32_t)ucontrol->value.integer.value[3], |
| 592 | __func__, iir_idx, band_idx, |
| 593 | (uint32_t)ucontrol->value.integer.value[4]); |
| 594 | return 0; |
| 595 | } |
| 596 | |
| 597 | static void set_iir_band_coeff(struct snd_soc_codec *codec, |
| 598 | int iir_idx, int band_idx, |
| 599 | int coeff_idx, uint32_t value) |
| 600 | { |
| 601 | /* Mask top 3 bits, 6-8 are reserved */ |
| 602 | /* Update address manually each time */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 603 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 604 | (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 605 | (band_idx * BAND_MAX + coeff_idx) & 0x1F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 606 | |
| 607 | /* Mask top 2 bits, 7-8 are reserved */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 608 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 609 | (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 610 | (value >> 24) & 0x3F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 611 | |
| 612 | /* Isolate 8bits at a time */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 613 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 614 | (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 615 | (value >> 16) & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 616 | |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 617 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 618 | (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 619 | (value >> 8) & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 620 | |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 621 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 622 | (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 623 | value & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | static int tabla_put_iir_band_audio_mixer( |
| 627 | struct snd_kcontrol *kcontrol, |
| 628 | struct snd_ctl_elem_value *ucontrol) |
| 629 | { |
| 630 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 631 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 632 | kcontrol->private_value)->reg; |
| 633 | int band_idx = ((struct soc_multi_mixer_control *) |
| 634 | kcontrol->private_value)->shift; |
| 635 | |
| 636 | set_iir_band_coeff(codec, iir_idx, band_idx, 0, |
| 637 | ucontrol->value.integer.value[0]); |
| 638 | set_iir_band_coeff(codec, iir_idx, band_idx, 1, |
| 639 | ucontrol->value.integer.value[1]); |
| 640 | set_iir_band_coeff(codec, iir_idx, band_idx, 2, |
| 641 | ucontrol->value.integer.value[2]); |
| 642 | set_iir_band_coeff(codec, iir_idx, band_idx, 3, |
| 643 | ucontrol->value.integer.value[3]); |
| 644 | set_iir_band_coeff(codec, iir_idx, band_idx, 4, |
| 645 | ucontrol->value.integer.value[4]); |
| 646 | |
| 647 | pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n" |
| 648 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 649 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 650 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 651 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 652 | __func__, iir_idx, band_idx, |
| 653 | get_iir_band_coeff(codec, iir_idx, band_idx, 0), |
| 654 | __func__, iir_idx, band_idx, |
| 655 | get_iir_band_coeff(codec, iir_idx, band_idx, 1), |
| 656 | __func__, iir_idx, band_idx, |
| 657 | get_iir_band_coeff(codec, iir_idx, band_idx, 2), |
| 658 | __func__, iir_idx, band_idx, |
| 659 | get_iir_band_coeff(codec, iir_idx, band_idx, 3), |
| 660 | __func__, iir_idx, band_idx, |
| 661 | get_iir_band_coeff(codec, iir_idx, band_idx, 4)); |
| 662 | return 0; |
| 663 | } |
| 664 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 665 | static int tabla_compander_gain_offset( |
| 666 | struct snd_soc_codec *codec, u32 enable, |
| 667 | unsigned int reg, int mask, int event) |
| 668 | { |
| 669 | int pa_mode = snd_soc_read(codec, reg) & mask; |
| 670 | int gain_offset = 0; |
| 671 | /* if PMU && enable is 1-> offset is 3 |
| 672 | * if PMU && enable is 0-> offset is 0 |
| 673 | * if PMD && pa_mode is PA -> offset is 0: PMU compander is off |
| 674 | * if PMD && pa_mode is comp -> offset is -3: PMU compander is on. |
| 675 | */ |
| 676 | |
| 677 | if (SND_SOC_DAPM_EVENT_ON(event) && (enable != 0)) |
| 678 | gain_offset = TABLA_COMP_DIGITAL_GAIN_OFFSET; |
| 679 | if (SND_SOC_DAPM_EVENT_OFF(event) && (pa_mode == 0)) |
| 680 | gain_offset = -TABLA_COMP_DIGITAL_GAIN_OFFSET; |
| 681 | return gain_offset; |
| 682 | } |
| 683 | |
| 684 | |
| 685 | static int tabla_config_gain_compander( |
| 686 | struct snd_soc_codec *codec, |
| 687 | u32 compander, u32 enable, int event) |
| 688 | { |
| 689 | int value = 0; |
| 690 | int mask = 1 << 4; |
| 691 | int gain = 0; |
| 692 | int gain_offset; |
| 693 | if (compander >= COMPANDER_MAX) { |
| 694 | pr_err("%s: Error, invalid compander channel\n", __func__); |
| 695 | return -EINVAL; |
| 696 | } |
| 697 | |
| 698 | if ((enable == 0) || SND_SOC_DAPM_EVENT_OFF(event)) |
| 699 | value = 1 << 4; |
| 700 | |
| 701 | if (compander == COMPANDER_1) { |
| 702 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 703 | TABLA_A_RX_HPH_L_GAIN, mask, event); |
| 704 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_GAIN, mask, value); |
| 705 | gain = snd_soc_read(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL); |
| 706 | snd_soc_update_bits(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 707 | 0xFF, gain - gain_offset); |
| 708 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 709 | TABLA_A_RX_HPH_R_GAIN, mask, event); |
| 710 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_GAIN, mask, value); |
| 711 | gain = snd_soc_read(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL); |
| 712 | snd_soc_update_bits(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 713 | 0xFF, gain - gain_offset); |
| 714 | } else if (compander == COMPANDER_2) { |
| 715 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 716 | TABLA_A_RX_LINE_1_GAIN, mask, event); |
| 717 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_1_GAIN, mask, value); |
| 718 | gain = snd_soc_read(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL); |
| 719 | snd_soc_update_bits(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 720 | 0xFF, gain - gain_offset); |
| 721 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 722 | TABLA_A_RX_LINE_3_GAIN, mask, event); |
| 723 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_3_GAIN, mask, value); |
| 724 | gain = snd_soc_read(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL); |
| 725 | snd_soc_update_bits(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 726 | 0xFF, gain - gain_offset); |
| 727 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 728 | TABLA_A_RX_LINE_2_GAIN, mask, event); |
| 729 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_2_GAIN, mask, value); |
| 730 | gain = snd_soc_read(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL); |
| 731 | snd_soc_update_bits(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 732 | 0xFF, gain - gain_offset); |
| 733 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 734 | TABLA_A_RX_LINE_4_GAIN, mask, event); |
| 735 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_4_GAIN, mask, value); |
| 736 | gain = snd_soc_read(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL); |
| 737 | snd_soc_update_bits(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 738 | 0xFF, gain - gain_offset); |
| 739 | } |
| 740 | return 0; |
| 741 | } |
| 742 | static int tabla_get_compander(struct snd_kcontrol *kcontrol, |
| 743 | struct snd_ctl_elem_value *ucontrol) |
| 744 | { |
| 745 | |
| 746 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 747 | int comp = ((struct soc_multi_mixer_control *) |
| 748 | kcontrol->private_value)->max; |
| 749 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 750 | |
| 751 | ucontrol->value.integer.value[0] = tabla->comp_enabled[comp]; |
| 752 | |
| 753 | return 0; |
| 754 | } |
| 755 | |
| 756 | static int tabla_set_compander(struct snd_kcontrol *kcontrol, |
| 757 | struct snd_ctl_elem_value *ucontrol) |
| 758 | { |
| 759 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 760 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 761 | int comp = ((struct soc_multi_mixer_control *) |
| 762 | kcontrol->private_value)->max; |
| 763 | int value = ucontrol->value.integer.value[0]; |
| 764 | |
| 765 | if (value == tabla->comp_enabled[comp]) { |
| 766 | pr_debug("%s: compander #%d enable %d no change\n", |
| 767 | __func__, comp, value); |
| 768 | return 0; |
| 769 | } |
| 770 | tabla->comp_enabled[comp] = value; |
| 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | |
| 775 | static int tabla_config_compander(struct snd_soc_dapm_widget *w, |
| 776 | struct snd_kcontrol *kcontrol, |
| 777 | int event) |
| 778 | { |
| 779 | struct snd_soc_codec *codec = w->codec; |
| 780 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 781 | u32 rate = tabla->comp_fs[w->shift]; |
| 782 | |
| 783 | switch (event) { |
| 784 | case SND_SOC_DAPM_PRE_PMU: |
| 785 | if (tabla->comp_enabled[w->shift] != 0) { |
| 786 | /* Enable both L/R compander clocks */ |
| 787 | snd_soc_update_bits(codec, |
| 788 | TABLA_A_CDC_CLK_RX_B2_CTL, |
| 789 | 0x03 << comp_shift[w->shift], |
| 790 | 0x03 << comp_shift[w->shift]); |
| 791 | /* Clar the HALT for the compander*/ |
| 792 | snd_soc_update_bits(codec, |
| 793 | TABLA_A_CDC_COMP1_B1_CTL + |
| 794 | w->shift * 8, 1 << 2, 0); |
| 795 | /* Toggle compander reset bits*/ |
| 796 | snd_soc_update_bits(codec, |
| 797 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 798 | 0x03 << comp_shift[w->shift], |
| 799 | 0x03 << comp_shift[w->shift]); |
| 800 | snd_soc_update_bits(codec, |
| 801 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 802 | 0x03 << comp_shift[w->shift], 0); |
| 803 | tabla_config_gain_compander(codec, w->shift, 1, event); |
| 804 | /* Update the RMS meter resampling*/ |
| 805 | snd_soc_update_bits(codec, |
| 806 | TABLA_A_CDC_COMP1_B3_CTL + |
| 807 | w->shift * 8, 0xFF, 0x01); |
| 808 | /* Wait for 1ms*/ |
| 809 | usleep_range(1000, 1000); |
| 810 | } |
| 811 | break; |
| 812 | case SND_SOC_DAPM_POST_PMU: |
| 813 | /* Set sample rate dependent paramater*/ |
| 814 | if (tabla->comp_enabled[w->shift] != 0) { |
| 815 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_FS_CFG + |
| 816 | w->shift * 8, 0x03, rate); |
| 817 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL + |
| 818 | w->shift * 8, 0x0F, |
| 819 | comp_samp_params[rate].peak_det_timeout); |
| 820 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL + |
| 821 | w->shift * 8, 0xF0, |
| 822 | comp_samp_params[rate].rms_meter_div_fact); |
| 823 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B3_CTL + |
| 824 | w->shift * 8, 0xFF, |
| 825 | comp_samp_params[rate].rms_meter_resamp_fact); |
| 826 | /* Compander enable -> 0x370/0x378*/ |
| 827 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 828 | w->shift * 8, 0x03, 0x03); |
| 829 | } |
| 830 | break; |
| 831 | case SND_SOC_DAPM_PRE_PMD: |
| 832 | /* Halt the compander*/ |
| 833 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 834 | w->shift * 8, 1 << 2, 1 << 2); |
| 835 | break; |
| 836 | case SND_SOC_DAPM_POST_PMD: |
| 837 | /* Restore the gain */ |
| 838 | tabla_config_gain_compander(codec, w->shift, |
| 839 | tabla->comp_enabled[w->shift], event); |
| 840 | /* Disable the compander*/ |
| 841 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 842 | w->shift * 8, 0x03, 0x00); |
| 843 | /* Turn off the clock for compander in pair*/ |
| 844 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_B2_CTL, |
| 845 | 0x03 << comp_shift[w->shift], 0); |
| 846 | break; |
| 847 | } |
| 848 | return 0; |
| 849 | } |
| 850 | |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 851 | static const char *tabla_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"}; |
| 852 | static const struct soc_enum tabla_ear_pa_gain_enum[] = { |
| 853 | SOC_ENUM_SINGLE_EXT(2, tabla_ear_pa_gain_text), |
| 854 | }; |
| 855 | |
Santosh Mardi | 024010f | 2011-10-18 06:27:21 +0530 | [diff] [blame] | 856 | /*cut of frequency for high pass filter*/ |
| 857 | static const char *cf_text[] = { |
| 858 | "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz" |
| 859 | }; |
| 860 | |
| 861 | static const struct soc_enum cf_dec1_enum = |
| 862 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX1_MUX_CTL, 4, 3, cf_text); |
| 863 | |
| 864 | static const struct soc_enum cf_dec2_enum = |
| 865 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX2_MUX_CTL, 4, 3, cf_text); |
| 866 | |
| 867 | static const struct soc_enum cf_dec3_enum = |
| 868 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX3_MUX_CTL, 4, 3, cf_text); |
| 869 | |
| 870 | static const struct soc_enum cf_dec4_enum = |
| 871 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX4_MUX_CTL, 4, 3, cf_text); |
| 872 | |
| 873 | static const struct soc_enum cf_dec5_enum = |
| 874 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX5_MUX_CTL, 4, 3, cf_text); |
| 875 | |
| 876 | static const struct soc_enum cf_dec6_enum = |
| 877 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX6_MUX_CTL, 4, 3, cf_text); |
| 878 | |
| 879 | static const struct soc_enum cf_dec7_enum = |
| 880 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX7_MUX_CTL, 4, 3, cf_text); |
| 881 | |
| 882 | static const struct soc_enum cf_dec8_enum = |
| 883 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX8_MUX_CTL, 4, 3, cf_text); |
| 884 | |
| 885 | static const struct soc_enum cf_dec9_enum = |
| 886 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX9_MUX_CTL, 4, 3, cf_text); |
| 887 | |
| 888 | static const struct soc_enum cf_dec10_enum = |
| 889 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX10_MUX_CTL, 4, 3, cf_text); |
| 890 | |
| 891 | static const struct soc_enum cf_rxmix1_enum = |
| 892 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX1_B4_CTL, 1, 3, cf_text); |
| 893 | |
| 894 | static const struct soc_enum cf_rxmix2_enum = |
| 895 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX2_B4_CTL, 1, 3, cf_text); |
| 896 | |
| 897 | static const struct soc_enum cf_rxmix3_enum = |
| 898 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX3_B4_CTL, 1, 3, cf_text); |
| 899 | |
| 900 | static const struct soc_enum cf_rxmix4_enum = |
| 901 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B4_CTL, 1, 3, cf_text); |
| 902 | |
| 903 | static const struct soc_enum cf_rxmix5_enum = |
| 904 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX5_B4_CTL, 1, 3, cf_text) |
| 905 | ; |
| 906 | static const struct soc_enum cf_rxmix6_enum = |
| 907 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B4_CTL, 1, 3, cf_text); |
| 908 | |
| 909 | static const struct soc_enum cf_rxmix7_enum = |
| 910 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX7_B4_CTL, 1, 3, cf_text); |
| 911 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 912 | static const struct snd_kcontrol_new tabla_snd_controls[] = { |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 913 | |
| 914 | SOC_ENUM_EXT("EAR PA Gain", tabla_ear_pa_gain_enum[0], |
| 915 | tabla_pa_gain_get, tabla_pa_gain_put), |
| 916 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 917 | SOC_SINGLE_TLV("LINEOUT1 Volume", TABLA_A_RX_LINE_1_GAIN, 0, 12, 1, |
| 918 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 919 | SOC_SINGLE_TLV("LINEOUT2 Volume", TABLA_A_RX_LINE_2_GAIN, 0, 12, 1, |
| 920 | line_gain), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 921 | SOC_SINGLE_TLV("LINEOUT3 Volume", TABLA_A_RX_LINE_3_GAIN, 0, 12, 1, |
| 922 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 923 | SOC_SINGLE_TLV("LINEOUT4 Volume", TABLA_A_RX_LINE_4_GAIN, 0, 12, 1, |
| 924 | line_gain), |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 925 | SOC_SINGLE_TLV("LINEOUT5 Volume", TABLA_A_RX_LINE_5_GAIN, 0, 12, 1, |
| 926 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 927 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 928 | SOC_SINGLE_TLV("HPHL Volume", TABLA_A_RX_HPH_L_GAIN, 0, 12, 1, |
| 929 | line_gain), |
| 930 | SOC_SINGLE_TLV("HPHR Volume", TABLA_A_RX_HPH_R_GAIN, 0, 12, 1, |
| 931 | line_gain), |
| 932 | |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 933 | SOC_SINGLE_S8_TLV("RX1 Digital Volume", TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 934 | -84, 40, digital_gain), |
| 935 | SOC_SINGLE_S8_TLV("RX2 Digital Volume", TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 936 | -84, 40, digital_gain), |
| 937 | SOC_SINGLE_S8_TLV("RX3 Digital Volume", TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 938 | -84, 40, digital_gain), |
| 939 | SOC_SINGLE_S8_TLV("RX4 Digital Volume", TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 940 | -84, 40, digital_gain), |
| 941 | SOC_SINGLE_S8_TLV("RX5 Digital Volume", TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 942 | -84, 40, digital_gain), |
| 943 | SOC_SINGLE_S8_TLV("RX6 Digital Volume", TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 944 | -84, 40, digital_gain), |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 945 | SOC_SINGLE_S8_TLV("RX7 Digital Volume", TABLA_A_CDC_RX7_VOL_CTL_B2_CTL, |
| 946 | -84, 40, digital_gain), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 947 | |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 948 | 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] | 949 | digital_gain), |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 950 | 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] | 951 | digital_gain), |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 952 | SOC_SINGLE_S8_TLV("DEC3 Volume", TABLA_A_CDC_TX3_VOL_CTL_GAIN, -84, 40, |
| 953 | digital_gain), |
| 954 | SOC_SINGLE_S8_TLV("DEC4 Volume", TABLA_A_CDC_TX4_VOL_CTL_GAIN, -84, 40, |
| 955 | digital_gain), |
| 956 | SOC_SINGLE_S8_TLV("DEC5 Volume", TABLA_A_CDC_TX5_VOL_CTL_GAIN, -84, 40, |
| 957 | digital_gain), |
| 958 | SOC_SINGLE_S8_TLV("DEC6 Volume", TABLA_A_CDC_TX6_VOL_CTL_GAIN, -84, 40, |
| 959 | digital_gain), |
| 960 | SOC_SINGLE_S8_TLV("DEC7 Volume", TABLA_A_CDC_TX7_VOL_CTL_GAIN, -84, 40, |
| 961 | digital_gain), |
| 962 | SOC_SINGLE_S8_TLV("DEC8 Volume", TABLA_A_CDC_TX8_VOL_CTL_GAIN, -84, 40, |
| 963 | digital_gain), |
| 964 | SOC_SINGLE_S8_TLV("DEC9 Volume", TABLA_A_CDC_TX9_VOL_CTL_GAIN, -84, 40, |
| 965 | digital_gain), |
| 966 | SOC_SINGLE_S8_TLV("DEC10 Volume", TABLA_A_CDC_TX10_VOL_CTL_GAIN, -84, |
| 967 | 40, digital_gain), |
Patrick Lai | 2900637 | 2011-09-28 17:57:42 -0700 | [diff] [blame] | 968 | SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TABLA_A_CDC_IIR1_GAIN_B1_CTL, -84, |
| 969 | 40, digital_gain), |
| 970 | SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TABLA_A_CDC_IIR1_GAIN_B2_CTL, -84, |
| 971 | 40, digital_gain), |
| 972 | SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TABLA_A_CDC_IIR1_GAIN_B3_CTL, -84, |
| 973 | 40, digital_gain), |
| 974 | SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TABLA_A_CDC_IIR1_GAIN_B4_CTL, -84, |
| 975 | 40, digital_gain), |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 976 | SOC_SINGLE_TLV("ADC1 Volume", TABLA_A_TX_1_2_EN, 5, 3, 0, analog_gain), |
| 977 | 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] | 978 | SOC_SINGLE_TLV("ADC3 Volume", TABLA_A_TX_3_4_EN, 5, 3, 0, analog_gain), |
| 979 | 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] | 980 | SOC_SINGLE_TLV("ADC5 Volume", TABLA_A_TX_5_6_EN, 5, 3, 0, analog_gain), |
| 981 | 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] | 982 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 983 | SOC_SINGLE_TLV("AUX_PGA_LEFT Volume", TABLA_A_AUX_L_GAIN, 0, 39, 0, |
| 984 | aux_pga_gain), |
| 985 | SOC_SINGLE_TLV("AUX_PGA_RIGHT Volume", TABLA_A_AUX_R_GAIN, 0, 39, 0, |
| 986 | aux_pga_gain), |
| 987 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 988 | 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] | 989 | 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] | 990 | 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] | 991 | |
| 992 | SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 0, 100, tabla_get_anc_slot, |
| 993 | tabla_put_anc_slot), |
Santosh Mardi | 024010f | 2011-10-18 06:27:21 +0530 | [diff] [blame] | 994 | SOC_ENUM("TX1 HPF cut off", cf_dec1_enum), |
| 995 | SOC_ENUM("TX2 HPF cut off", cf_dec2_enum), |
| 996 | SOC_ENUM("TX3 HPF cut off", cf_dec3_enum), |
| 997 | SOC_ENUM("TX4 HPF cut off", cf_dec4_enum), |
| 998 | SOC_ENUM("TX5 HPF cut off", cf_dec5_enum), |
| 999 | SOC_ENUM("TX6 HPF cut off", cf_dec6_enum), |
| 1000 | SOC_ENUM("TX7 HPF cut off", cf_dec7_enum), |
| 1001 | SOC_ENUM("TX8 HPF cut off", cf_dec8_enum), |
| 1002 | SOC_ENUM("TX9 HPF cut off", cf_dec9_enum), |
| 1003 | SOC_ENUM("TX10 HPF cut off", cf_dec10_enum), |
| 1004 | |
| 1005 | SOC_SINGLE("TX1 HPF Switch", TABLA_A_CDC_TX1_MUX_CTL, 3, 1, 0), |
| 1006 | SOC_SINGLE("TX2 HPF Switch", TABLA_A_CDC_TX2_MUX_CTL, 3, 1, 0), |
| 1007 | SOC_SINGLE("TX3 HPF Switch", TABLA_A_CDC_TX3_MUX_CTL, 3, 1, 0), |
| 1008 | SOC_SINGLE("TX4 HPF Switch", TABLA_A_CDC_TX4_MUX_CTL, 3, 1, 0), |
| 1009 | SOC_SINGLE("TX5 HPF Switch", TABLA_A_CDC_TX5_MUX_CTL, 3, 1, 0), |
| 1010 | SOC_SINGLE("TX6 HPF Switch", TABLA_A_CDC_TX6_MUX_CTL, 3, 1, 0), |
| 1011 | SOC_SINGLE("TX7 HPF Switch", TABLA_A_CDC_TX7_MUX_CTL, 3, 1, 0), |
| 1012 | SOC_SINGLE("TX8 HPF Switch", TABLA_A_CDC_TX8_MUX_CTL, 3, 1, 0), |
| 1013 | SOC_SINGLE("TX9 HPF Switch", TABLA_A_CDC_TX9_MUX_CTL, 3, 1, 0), |
| 1014 | SOC_SINGLE("TX10 HPF Switch", TABLA_A_CDC_TX10_MUX_CTL, 3, 1, 0), |
| 1015 | |
| 1016 | SOC_SINGLE("RX1 HPF Switch", TABLA_A_CDC_RX1_B5_CTL, 2, 1, 0), |
| 1017 | SOC_SINGLE("RX2 HPF Switch", TABLA_A_CDC_RX2_B5_CTL, 2, 1, 0), |
| 1018 | SOC_SINGLE("RX3 HPF Switch", TABLA_A_CDC_RX3_B5_CTL, 2, 1, 0), |
| 1019 | SOC_SINGLE("RX4 HPF Switch", TABLA_A_CDC_RX4_B5_CTL, 2, 1, 0), |
| 1020 | SOC_SINGLE("RX5 HPF Switch", TABLA_A_CDC_RX5_B5_CTL, 2, 1, 0), |
| 1021 | SOC_SINGLE("RX6 HPF Switch", TABLA_A_CDC_RX6_B5_CTL, 2, 1, 0), |
| 1022 | SOC_SINGLE("RX7 HPF Switch", TABLA_A_CDC_RX7_B5_CTL, 2, 1, 0), |
| 1023 | |
| 1024 | SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum), |
| 1025 | SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum), |
| 1026 | SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum), |
| 1027 | SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum), |
| 1028 | SOC_ENUM("RX5 HPF cut off", cf_rxmix5_enum), |
| 1029 | SOC_ENUM("RX6 HPF cut off", cf_rxmix6_enum), |
| 1030 | SOC_ENUM("RX7 HPF cut off", cf_rxmix7_enum), |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 1031 | |
| 1032 | SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0, |
| 1033 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1034 | SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0, |
| 1035 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1036 | SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0, |
| 1037 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1038 | SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0, |
| 1039 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1040 | SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0, |
| 1041 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1042 | SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0, |
| 1043 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1044 | SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0, |
| 1045 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1046 | SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0, |
| 1047 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1048 | SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0, |
| 1049 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1050 | SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0, |
| 1051 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1052 | |
| 1053 | SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5, |
| 1054 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1055 | SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5, |
| 1056 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1057 | SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5, |
| 1058 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1059 | SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5, |
| 1060 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1061 | SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5, |
| 1062 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1063 | SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5, |
| 1064 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1065 | SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5, |
| 1066 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1067 | SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5, |
| 1068 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1069 | SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5, |
| 1070 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1071 | SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5, |
| 1072 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1073 | SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, 1, COMPANDER_1, 0, |
| 1074 | tabla_get_compander, tabla_set_compander), |
| 1075 | SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, 0, COMPANDER_2, 0, |
| 1076 | tabla_get_compander, tabla_set_compander), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1077 | }; |
| 1078 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 1079 | static const struct snd_kcontrol_new tabla_1_x_snd_controls[] = { |
| 1080 | SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_1_A_MICB_4_CTL, 4, 1, 1), |
| 1081 | }; |
| 1082 | |
| 1083 | static const struct snd_kcontrol_new tabla_2_higher_snd_controls[] = { |
| 1084 | SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_2_A_MICB_4_CTL, 4, 1, 1), |
| 1085 | }; |
| 1086 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1087 | static const char *rx_mix1_text[] = { |
| 1088 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4", |
| 1089 | "RX5", "RX6", "RX7" |
| 1090 | }; |
| 1091 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1092 | static const char *rx_mix2_text[] = { |
| 1093 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2" |
| 1094 | }; |
| 1095 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1096 | static const char *rx_dsm_text[] = { |
| 1097 | "CIC_OUT", "DSM_INV" |
| 1098 | }; |
| 1099 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1100 | static const char *sb_tx1_mux_text[] = { |
| 1101 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1102 | "DEC1" |
| 1103 | }; |
| 1104 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1105 | static const char *sb_tx2_mux_text[] = { |
| 1106 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1107 | "DEC2" |
| 1108 | }; |
| 1109 | |
| 1110 | static const char *sb_tx3_mux_text[] = { |
| 1111 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1112 | "DEC3" |
| 1113 | }; |
| 1114 | |
| 1115 | static const char *sb_tx4_mux_text[] = { |
| 1116 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1117 | "DEC4" |
| 1118 | }; |
| 1119 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1120 | static const char *sb_tx5_mux_text[] = { |
| 1121 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1122 | "DEC5" |
| 1123 | }; |
| 1124 | |
| 1125 | static const char *sb_tx6_mux_text[] = { |
| 1126 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1127 | "DEC6" |
| 1128 | }; |
| 1129 | |
| 1130 | static const char const *sb_tx7_to_tx10_mux_text[] = { |
| 1131 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1132 | "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8", |
| 1133 | "DEC9", "DEC10" |
| 1134 | }; |
| 1135 | |
| 1136 | static const char *dec1_mux_text[] = { |
| 1137 | "ZERO", "DMIC1", "ADC6", |
| 1138 | }; |
| 1139 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1140 | static const char *dec2_mux_text[] = { |
| 1141 | "ZERO", "DMIC2", "ADC5", |
| 1142 | }; |
| 1143 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1144 | static const char *dec3_mux_text[] = { |
| 1145 | "ZERO", "DMIC3", "ADC4", |
| 1146 | }; |
| 1147 | |
| 1148 | static const char *dec4_mux_text[] = { |
| 1149 | "ZERO", "DMIC4", "ADC3", |
| 1150 | }; |
| 1151 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1152 | static const char *dec5_mux_text[] = { |
| 1153 | "ZERO", "DMIC5", "ADC2", |
| 1154 | }; |
| 1155 | |
| 1156 | static const char *dec6_mux_text[] = { |
| 1157 | "ZERO", "DMIC6", "ADC1", |
| 1158 | }; |
| 1159 | |
| 1160 | static const char const *dec7_mux_text[] = { |
| 1161 | "ZERO", "DMIC1", "DMIC6", "ADC1", "ADC6", "ANC1_FB", "ANC2_FB", |
| 1162 | }; |
| 1163 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1164 | static const char *dec8_mux_text[] = { |
| 1165 | "ZERO", "DMIC2", "DMIC5", "ADC2", "ADC5", |
| 1166 | }; |
| 1167 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1168 | static const char *dec9_mux_text[] = { |
| 1169 | "ZERO", "DMIC4", "DMIC5", "ADC2", "ADC3", "ADCMB", "ANC1_FB", "ANC2_FB", |
| 1170 | }; |
| 1171 | |
| 1172 | static const char *dec10_mux_text[] = { |
| 1173 | "ZERO", "DMIC3", "DMIC6", "ADC1", "ADC4", "ADCMB", "ANC1_FB", "ANC2_FB", |
| 1174 | }; |
| 1175 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1176 | static const char const *anc_mux_text[] = { |
| 1177 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6", "ADC_MB", |
| 1178 | "RSVD_1", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", "DMIC6" |
| 1179 | }; |
| 1180 | |
| 1181 | static const char const *anc1_fb_mux_text[] = { |
| 1182 | "ZERO", "EAR_HPH_L", "EAR_LINE_1", |
| 1183 | }; |
| 1184 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1185 | static const char *iir1_inp1_text[] = { |
| 1186 | "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8", |
| 1187 | "DEC9", "DEC10", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7" |
| 1188 | }; |
| 1189 | |
| 1190 | static const struct soc_enum rx_mix1_inp1_chain_enum = |
| 1191 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_mix1_text); |
| 1192 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1193 | static const struct soc_enum rx_mix1_inp2_chain_enum = |
| 1194 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_mix1_text); |
| 1195 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 1196 | static const struct soc_enum rx_mix1_inp3_chain_enum = |
| 1197 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B2_CTL, 0, 12, rx_mix1_text); |
| 1198 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1199 | static const struct soc_enum rx2_mix1_inp1_chain_enum = |
| 1200 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_mix1_text); |
| 1201 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1202 | static const struct soc_enum rx2_mix1_inp2_chain_enum = |
| 1203 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_mix1_text); |
| 1204 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1205 | static const struct soc_enum rx3_mix1_inp1_chain_enum = |
| 1206 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 0, 12, rx_mix1_text); |
| 1207 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1208 | static const struct soc_enum rx3_mix1_inp2_chain_enum = |
| 1209 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 4, 12, rx_mix1_text); |
| 1210 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1211 | static const struct soc_enum rx4_mix1_inp1_chain_enum = |
| 1212 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 0, 12, rx_mix1_text); |
| 1213 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1214 | static const struct soc_enum rx4_mix1_inp2_chain_enum = |
| 1215 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 4, 12, rx_mix1_text); |
| 1216 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1217 | static const struct soc_enum rx5_mix1_inp1_chain_enum = |
| 1218 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 0, 12, rx_mix1_text); |
| 1219 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1220 | static const struct soc_enum rx5_mix1_inp2_chain_enum = |
| 1221 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 4, 12, rx_mix1_text); |
| 1222 | |
| 1223 | static const struct soc_enum rx6_mix1_inp1_chain_enum = |
| 1224 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 0, 12, rx_mix1_text); |
| 1225 | |
| 1226 | static const struct soc_enum rx6_mix1_inp2_chain_enum = |
| 1227 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 4, 12, rx_mix1_text); |
| 1228 | |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 1229 | static const struct soc_enum rx7_mix1_inp1_chain_enum = |
| 1230 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 0, 12, rx_mix1_text); |
| 1231 | |
| 1232 | static const struct soc_enum rx7_mix1_inp2_chain_enum = |
| 1233 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 4, 12, rx_mix1_text); |
| 1234 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1235 | static const struct soc_enum rx1_mix2_inp1_chain_enum = |
| 1236 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text); |
| 1237 | |
| 1238 | static const struct soc_enum rx1_mix2_inp2_chain_enum = |
| 1239 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text); |
| 1240 | |
| 1241 | static const struct soc_enum rx2_mix2_inp1_chain_enum = |
| 1242 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text); |
| 1243 | |
| 1244 | static const struct soc_enum rx2_mix2_inp2_chain_enum = |
| 1245 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text); |
| 1246 | |
| 1247 | static const struct soc_enum rx3_mix2_inp1_chain_enum = |
| 1248 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 0, 5, rx_mix2_text); |
| 1249 | |
| 1250 | static const struct soc_enum rx3_mix2_inp2_chain_enum = |
| 1251 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 3, 5, rx_mix2_text); |
| 1252 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1253 | static const struct soc_enum rx4_dsm_enum = |
| 1254 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B6_CTL, 4, 2, rx_dsm_text); |
| 1255 | |
| 1256 | static const struct soc_enum rx6_dsm_enum = |
| 1257 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B6_CTL, 4, 2, rx_dsm_text); |
| 1258 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1259 | static const struct soc_enum sb_tx1_mux_enum = |
| 1260 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text); |
| 1261 | |
| 1262 | static const struct soc_enum sb_tx2_mux_enum = |
| 1263 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0, 9, sb_tx2_mux_text); |
| 1264 | |
| 1265 | static const struct soc_enum sb_tx3_mux_enum = |
| 1266 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0, 9, sb_tx3_mux_text); |
| 1267 | |
| 1268 | static const struct soc_enum sb_tx4_mux_enum = |
| 1269 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0, 9, sb_tx4_mux_text); |
| 1270 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1271 | static const struct soc_enum sb_tx5_mux_enum = |
| 1272 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text); |
| 1273 | |
| 1274 | static const struct soc_enum sb_tx6_mux_enum = |
| 1275 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0, 9, sb_tx6_mux_text); |
| 1276 | |
| 1277 | static const struct soc_enum sb_tx7_mux_enum = |
| 1278 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0, 18, |
| 1279 | sb_tx7_to_tx10_mux_text); |
| 1280 | |
| 1281 | static const struct soc_enum sb_tx8_mux_enum = |
| 1282 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0, 18, |
| 1283 | sb_tx7_to_tx10_mux_text); |
| 1284 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 1285 | static const struct soc_enum sb_tx9_mux_enum = |
| 1286 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0, 18, |
| 1287 | sb_tx7_to_tx10_mux_text); |
| 1288 | |
| 1289 | static const struct soc_enum sb_tx10_mux_enum = |
| 1290 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0, 18, |
| 1291 | sb_tx7_to_tx10_mux_text); |
| 1292 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1293 | static const struct soc_enum dec1_mux_enum = |
| 1294 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 0, 3, dec1_mux_text); |
| 1295 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1296 | static const struct soc_enum dec2_mux_enum = |
| 1297 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 2, 3, dec2_mux_text); |
| 1298 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1299 | static const struct soc_enum dec3_mux_enum = |
| 1300 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 4, 3, dec3_mux_text); |
| 1301 | |
| 1302 | static const struct soc_enum dec4_mux_enum = |
| 1303 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 6, 3, dec4_mux_text); |
| 1304 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1305 | static const struct soc_enum dec5_mux_enum = |
| 1306 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 0, 3, dec5_mux_text); |
| 1307 | |
| 1308 | static const struct soc_enum dec6_mux_enum = |
| 1309 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 2, 3, dec6_mux_text); |
| 1310 | |
| 1311 | static const struct soc_enum dec7_mux_enum = |
| 1312 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 4, 7, dec7_mux_text); |
| 1313 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1314 | static const struct soc_enum dec8_mux_enum = |
| 1315 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 0, 7, dec8_mux_text); |
| 1316 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1317 | static const struct soc_enum dec9_mux_enum = |
| 1318 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 3, 8, dec9_mux_text); |
| 1319 | |
| 1320 | static const struct soc_enum dec10_mux_enum = |
| 1321 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B4_CTL, 0, 8, dec10_mux_text); |
| 1322 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1323 | static const struct soc_enum anc1_mux_enum = |
| 1324 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 0, 16, anc_mux_text); |
| 1325 | |
| 1326 | static const struct soc_enum anc2_mux_enum = |
| 1327 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 4, 16, anc_mux_text); |
| 1328 | |
| 1329 | static const struct soc_enum anc1_fb_mux_enum = |
| 1330 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text); |
| 1331 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1332 | static const struct soc_enum iir1_inp1_mux_enum = |
| 1333 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ1_B1_CTL, 0, 18, iir1_inp1_text); |
| 1334 | |
| 1335 | static const struct snd_kcontrol_new rx_mix1_inp1_mux = |
| 1336 | SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum); |
| 1337 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1338 | static const struct snd_kcontrol_new rx_mix1_inp2_mux = |
| 1339 | SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum); |
| 1340 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 1341 | static const struct snd_kcontrol_new rx_mix1_inp3_mux = |
| 1342 | SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum); |
| 1343 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1344 | static const struct snd_kcontrol_new rx2_mix1_inp1_mux = |
| 1345 | SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum); |
| 1346 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1347 | static const struct snd_kcontrol_new rx2_mix1_inp2_mux = |
| 1348 | SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum); |
| 1349 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1350 | static const struct snd_kcontrol_new rx3_mix1_inp1_mux = |
| 1351 | SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum); |
| 1352 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1353 | static const struct snd_kcontrol_new rx3_mix1_inp2_mux = |
| 1354 | SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum); |
| 1355 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1356 | static const struct snd_kcontrol_new rx4_mix1_inp1_mux = |
| 1357 | SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum); |
| 1358 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1359 | static const struct snd_kcontrol_new rx4_mix1_inp2_mux = |
| 1360 | SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum); |
| 1361 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1362 | static const struct snd_kcontrol_new rx5_mix1_inp1_mux = |
| 1363 | SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum); |
| 1364 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1365 | static const struct snd_kcontrol_new rx5_mix1_inp2_mux = |
| 1366 | SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum); |
| 1367 | |
| 1368 | static const struct snd_kcontrol_new rx6_mix1_inp1_mux = |
| 1369 | SOC_DAPM_ENUM("RX6 MIX1 INP1 Mux", rx6_mix1_inp1_chain_enum); |
| 1370 | |
| 1371 | static const struct snd_kcontrol_new rx6_mix1_inp2_mux = |
| 1372 | SOC_DAPM_ENUM("RX6 MIX1 INP2 Mux", rx6_mix1_inp2_chain_enum); |
| 1373 | |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 1374 | static const struct snd_kcontrol_new rx7_mix1_inp1_mux = |
| 1375 | SOC_DAPM_ENUM("RX7 MIX1 INP1 Mux", rx7_mix1_inp1_chain_enum); |
| 1376 | |
| 1377 | static const struct snd_kcontrol_new rx7_mix1_inp2_mux = |
| 1378 | SOC_DAPM_ENUM("RX7 MIX1 INP2 Mux", rx7_mix1_inp2_chain_enum); |
| 1379 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1380 | static const struct snd_kcontrol_new rx1_mix2_inp1_mux = |
| 1381 | SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum); |
| 1382 | |
| 1383 | static const struct snd_kcontrol_new rx1_mix2_inp2_mux = |
| 1384 | SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum); |
| 1385 | |
| 1386 | static const struct snd_kcontrol_new rx2_mix2_inp1_mux = |
| 1387 | SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum); |
| 1388 | |
| 1389 | static const struct snd_kcontrol_new rx2_mix2_inp2_mux = |
| 1390 | SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum); |
| 1391 | |
| 1392 | static const struct snd_kcontrol_new rx3_mix2_inp1_mux = |
| 1393 | SOC_DAPM_ENUM("RX3 MIX2 INP1 Mux", rx3_mix2_inp1_chain_enum); |
| 1394 | |
| 1395 | static const struct snd_kcontrol_new rx3_mix2_inp2_mux = |
| 1396 | SOC_DAPM_ENUM("RX3 MIX2 INP2 Mux", rx3_mix2_inp2_chain_enum); |
| 1397 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1398 | static const struct snd_kcontrol_new rx4_dsm_mux = |
| 1399 | SOC_DAPM_ENUM("RX4 DSM MUX Mux", rx4_dsm_enum); |
| 1400 | |
| 1401 | static const struct snd_kcontrol_new rx6_dsm_mux = |
| 1402 | SOC_DAPM_ENUM("RX6 DSM MUX Mux", rx6_dsm_enum); |
| 1403 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1404 | static const struct snd_kcontrol_new sb_tx1_mux = |
| 1405 | SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum); |
| 1406 | |
| 1407 | static const struct snd_kcontrol_new sb_tx2_mux = |
| 1408 | SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum); |
| 1409 | |
| 1410 | static const struct snd_kcontrol_new sb_tx3_mux = |
| 1411 | SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum); |
| 1412 | |
| 1413 | static const struct snd_kcontrol_new sb_tx4_mux = |
| 1414 | SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum); |
| 1415 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1416 | static const struct snd_kcontrol_new sb_tx5_mux = |
| 1417 | SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum); |
| 1418 | |
| 1419 | static const struct snd_kcontrol_new sb_tx6_mux = |
| 1420 | SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum); |
| 1421 | |
| 1422 | static const struct snd_kcontrol_new sb_tx7_mux = |
| 1423 | SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum); |
| 1424 | |
| 1425 | static const struct snd_kcontrol_new sb_tx8_mux = |
| 1426 | SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum); |
| 1427 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 1428 | static const struct snd_kcontrol_new sb_tx9_mux = |
| 1429 | SOC_DAPM_ENUM("SLIM TX9 MUX Mux", sb_tx9_mux_enum); |
| 1430 | |
| 1431 | static const struct snd_kcontrol_new sb_tx10_mux = |
| 1432 | SOC_DAPM_ENUM("SLIM TX10 MUX Mux", sb_tx10_mux_enum); |
| 1433 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1434 | |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1435 | static int wcd9310_put_dec_enum(struct snd_kcontrol *kcontrol, |
| 1436 | struct snd_ctl_elem_value *ucontrol) |
| 1437 | { |
| 1438 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1439 | struct snd_soc_dapm_widget *w = wlist->widgets[0]; |
| 1440 | struct snd_soc_codec *codec = w->codec; |
| 1441 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1442 | unsigned int dec_mux, decimator; |
| 1443 | char *dec_name = NULL; |
| 1444 | char *widget_name = NULL; |
| 1445 | char *temp; |
| 1446 | u16 tx_mux_ctl_reg; |
| 1447 | u8 adc_dmic_sel = 0x0; |
| 1448 | int ret = 0; |
| 1449 | |
| 1450 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 1451 | return -EINVAL; |
| 1452 | |
| 1453 | dec_mux = ucontrol->value.enumerated.item[0]; |
| 1454 | |
| 1455 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 1456 | if (!widget_name) |
| 1457 | return -ENOMEM; |
| 1458 | temp = widget_name; |
| 1459 | |
| 1460 | dec_name = strsep(&widget_name, " "); |
| 1461 | widget_name = temp; |
| 1462 | if (!dec_name) { |
| 1463 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 1464 | ret = -EINVAL; |
| 1465 | goto out; |
| 1466 | } |
| 1467 | |
| 1468 | ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator); |
| 1469 | if (ret < 0) { |
| 1470 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 1471 | ret = -EINVAL; |
| 1472 | goto out; |
| 1473 | } |
| 1474 | |
| 1475 | dev_dbg(w->dapm->dev, "%s(): widget = %s dec_name = %s decimator = %u" |
| 1476 | " dec_mux = %u\n", __func__, w->name, dec_name, decimator, |
| 1477 | dec_mux); |
| 1478 | |
| 1479 | |
| 1480 | switch (decimator) { |
| 1481 | case 1: |
| 1482 | case 2: |
| 1483 | case 3: |
| 1484 | case 4: |
| 1485 | case 5: |
| 1486 | case 6: |
| 1487 | if (dec_mux == 1) |
| 1488 | adc_dmic_sel = 0x1; |
| 1489 | else |
| 1490 | adc_dmic_sel = 0x0; |
| 1491 | break; |
| 1492 | case 7: |
| 1493 | case 8: |
| 1494 | case 9: |
| 1495 | case 10: |
| 1496 | if ((dec_mux == 1) || (dec_mux == 2)) |
| 1497 | adc_dmic_sel = 0x1; |
| 1498 | else |
| 1499 | adc_dmic_sel = 0x0; |
| 1500 | break; |
| 1501 | default: |
| 1502 | pr_err("%s: Invalid Decimator = %u\n", __func__, decimator); |
| 1503 | ret = -EINVAL; |
| 1504 | goto out; |
| 1505 | } |
| 1506 | |
| 1507 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 1508 | |
| 1509 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel); |
| 1510 | |
| 1511 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 1512 | |
| 1513 | out: |
| 1514 | kfree(widget_name); |
| 1515 | return ret; |
| 1516 | } |
| 1517 | |
| 1518 | #define WCD9310_DEC_ENUM(xname, xenum) \ |
| 1519 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 1520 | .info = snd_soc_info_enum_double, \ |
| 1521 | .get = snd_soc_dapm_get_enum_double, \ |
| 1522 | .put = wcd9310_put_dec_enum, \ |
| 1523 | .private_value = (unsigned long)&xenum } |
| 1524 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1525 | static const struct snd_kcontrol_new dec1_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1526 | WCD9310_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1527 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1528 | static const struct snd_kcontrol_new dec2_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1529 | WCD9310_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum); |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1530 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1531 | static const struct snd_kcontrol_new dec3_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1532 | WCD9310_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1533 | |
| 1534 | static const struct snd_kcontrol_new dec4_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1535 | WCD9310_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1536 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1537 | static const struct snd_kcontrol_new dec5_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1538 | WCD9310_DEC_ENUM("DEC5 MUX Mux", dec5_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1539 | |
| 1540 | static const struct snd_kcontrol_new dec6_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1541 | WCD9310_DEC_ENUM("DEC6 MUX Mux", dec6_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1542 | |
| 1543 | static const struct snd_kcontrol_new dec7_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1544 | WCD9310_DEC_ENUM("DEC7 MUX Mux", dec7_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1545 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1546 | static const struct snd_kcontrol_new dec8_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1547 | WCD9310_DEC_ENUM("DEC8 MUX Mux", dec8_mux_enum); |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1548 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1549 | static const struct snd_kcontrol_new dec9_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1550 | WCD9310_DEC_ENUM("DEC9 MUX Mux", dec9_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1551 | |
| 1552 | static const struct snd_kcontrol_new dec10_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1553 | WCD9310_DEC_ENUM("DEC10 MUX Mux", dec10_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1554 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1555 | static const struct snd_kcontrol_new iir1_inp1_mux = |
| 1556 | SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum); |
| 1557 | |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1558 | static const struct snd_kcontrol_new anc1_mux = |
| 1559 | SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum); |
| 1560 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1561 | static const struct snd_kcontrol_new anc2_mux = |
| 1562 | SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1563 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1564 | static const struct snd_kcontrol_new anc1_fb_mux = |
| 1565 | SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1566 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1567 | static const struct snd_kcontrol_new dac1_switch[] = { |
| 1568 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_EAR_EN, 5, 1, 0) |
| 1569 | }; |
| 1570 | static const struct snd_kcontrol_new hphl_switch[] = { |
| 1571 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_HPH_L_DAC_CTL, 6, 1, 0) |
| 1572 | }; |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1573 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1574 | static const struct snd_kcontrol_new hphl_pa_mix[] = { |
| 1575 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1576 | 7, 1, 0), |
| 1577 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1578 | 7, 1, 0), |
| 1579 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1580 | TABLA_A_AUX_L_PA_CONN_INV, 7, 1, 0), |
| 1581 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1582 | TABLA_A_AUX_R_PA_CONN_INV, 7, 1, 0), |
| 1583 | }; |
| 1584 | |
| 1585 | static const struct snd_kcontrol_new hphr_pa_mix[] = { |
| 1586 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1587 | 6, 1, 0), |
| 1588 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1589 | 6, 1, 0), |
| 1590 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1591 | TABLA_A_AUX_L_PA_CONN_INV, 6, 1, 0), |
| 1592 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1593 | TABLA_A_AUX_R_PA_CONN_INV, 6, 1, 0), |
| 1594 | }; |
| 1595 | |
| 1596 | static const struct snd_kcontrol_new lineout1_pa_mix[] = { |
| 1597 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1598 | 5, 1, 0), |
| 1599 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1600 | 5, 1, 0), |
| 1601 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1602 | TABLA_A_AUX_L_PA_CONN_INV, 5, 1, 0), |
| 1603 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1604 | TABLA_A_AUX_R_PA_CONN_INV, 5, 1, 0), |
| 1605 | }; |
| 1606 | |
| 1607 | static const struct snd_kcontrol_new lineout2_pa_mix[] = { |
| 1608 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1609 | 4, 1, 0), |
| 1610 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1611 | 4, 1, 0), |
| 1612 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1613 | TABLA_A_AUX_L_PA_CONN_INV, 4, 1, 0), |
| 1614 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1615 | TABLA_A_AUX_R_PA_CONN_INV, 4, 1, 0), |
| 1616 | }; |
| 1617 | |
| 1618 | static const struct snd_kcontrol_new lineout3_pa_mix[] = { |
| 1619 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1620 | 3, 1, 0), |
| 1621 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1622 | 3, 1, 0), |
| 1623 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1624 | TABLA_A_AUX_L_PA_CONN_INV, 3, 1, 0), |
| 1625 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1626 | TABLA_A_AUX_R_PA_CONN_INV, 3, 1, 0), |
| 1627 | }; |
| 1628 | |
| 1629 | static const struct snd_kcontrol_new lineout4_pa_mix[] = { |
| 1630 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1631 | 2, 1, 0), |
| 1632 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1633 | 2, 1, 0), |
| 1634 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1635 | TABLA_A_AUX_L_PA_CONN_INV, 2, 1, 0), |
| 1636 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1637 | TABLA_A_AUX_R_PA_CONN_INV, 2, 1, 0), |
| 1638 | }; |
| 1639 | |
| 1640 | static const struct snd_kcontrol_new lineout5_pa_mix[] = { |
| 1641 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1642 | 1, 1, 0), |
| 1643 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1644 | 1, 1, 0), |
| 1645 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1646 | TABLA_A_AUX_L_PA_CONN_INV, 1, 1, 0), |
| 1647 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1648 | TABLA_A_AUX_R_PA_CONN_INV, 1, 1, 0), |
| 1649 | }; |
| 1650 | |
| 1651 | static const struct snd_kcontrol_new ear_pa_mix[] = { |
| 1652 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1653 | 0, 1, 0), |
| 1654 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1655 | 0, 1, 0), |
| 1656 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1657 | TABLA_A_AUX_L_PA_CONN_INV, 0, 1, 0), |
| 1658 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1659 | TABLA_A_AUX_R_PA_CONN_INV, 0, 1, 0), |
| 1660 | }; |
| 1661 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1662 | static const struct snd_kcontrol_new lineout3_ground_switch = |
| 1663 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_3_DAC_CTL, 6, 1, 0); |
| 1664 | |
| 1665 | static const struct snd_kcontrol_new lineout4_ground_switch = |
| 1666 | 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] | 1667 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1668 | static void tabla_codec_enable_adc_block(struct snd_soc_codec *codec, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 1669 | int enable) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1670 | { |
| 1671 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1672 | |
| 1673 | pr_debug("%s %d\n", __func__, enable); |
| 1674 | |
| 1675 | if (enable) { |
| 1676 | tabla->adc_count++; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1677 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x2, 0x2); |
| 1678 | } else { |
| 1679 | tabla->adc_count--; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 1680 | if (!tabla->adc_count) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1681 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 1682 | 0x2, 0x0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | static int tabla_codec_enable_adc(struct snd_soc_dapm_widget *w, |
| 1687 | struct snd_kcontrol *kcontrol, int event) |
| 1688 | { |
| 1689 | struct snd_soc_codec *codec = w->codec; |
| 1690 | u16 adc_reg; |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 1691 | u8 init_bit_shift; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1692 | |
| 1693 | pr_debug("%s %d\n", __func__, event); |
| 1694 | |
| 1695 | if (w->reg == TABLA_A_TX_1_2_EN) |
| 1696 | adc_reg = TABLA_A_TX_1_2_TEST_CTL; |
| 1697 | else if (w->reg == TABLA_A_TX_3_4_EN) |
| 1698 | adc_reg = TABLA_A_TX_3_4_TEST_CTL; |
| 1699 | else if (w->reg == TABLA_A_TX_5_6_EN) |
| 1700 | adc_reg = TABLA_A_TX_5_6_TEST_CTL; |
| 1701 | else { |
| 1702 | pr_err("%s: Error, invalid adc register\n", __func__); |
| 1703 | return -EINVAL; |
| 1704 | } |
| 1705 | |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 1706 | if (w->shift == 3) |
| 1707 | init_bit_shift = 6; |
| 1708 | else if (w->shift == 7) |
| 1709 | init_bit_shift = 7; |
| 1710 | else { |
| 1711 | pr_err("%s: Error, invalid init bit postion adc register\n", |
| 1712 | __func__); |
| 1713 | return -EINVAL; |
| 1714 | } |
| 1715 | |
| 1716 | |
| 1717 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1718 | switch (event) { |
| 1719 | case SND_SOC_DAPM_PRE_PMU: |
| 1720 | tabla_codec_enable_adc_block(codec, 1); |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 1721 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, |
| 1722 | 1 << init_bit_shift); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1723 | break; |
| 1724 | case SND_SOC_DAPM_POST_PMU: |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 1725 | |
| 1726 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00); |
| 1727 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1728 | break; |
| 1729 | case SND_SOC_DAPM_POST_PMD: |
| 1730 | tabla_codec_enable_adc_block(codec, 0); |
| 1731 | break; |
| 1732 | } |
| 1733 | return 0; |
| 1734 | } |
| 1735 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1736 | static void tabla_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec) |
| 1737 | { |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1738 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 1739 | 0x80); |
| 1740 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x04, |
| 1741 | 0x04); |
| 1742 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 1743 | 0x01); |
| 1744 | usleep_range(1000, 1000); |
| 1745 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 1746 | 0x00); |
| 1747 | } |
| 1748 | |
| 1749 | static void tabla_codec_enable_bandgap(struct snd_soc_codec *codec, |
| 1750 | enum tabla_bandgap_type choice) |
| 1751 | { |
| 1752 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1753 | |
| 1754 | /* TODO lock resources accessed by audio streams and threaded |
| 1755 | * interrupt handlers |
| 1756 | */ |
| 1757 | |
| 1758 | pr_debug("%s, choice is %d, current is %d\n", __func__, choice, |
| 1759 | tabla->bandgap_type); |
| 1760 | |
| 1761 | if (tabla->bandgap_type == choice) |
| 1762 | return; |
| 1763 | |
| 1764 | if ((tabla->bandgap_type == TABLA_BANDGAP_OFF) && |
| 1765 | (choice == TABLA_BANDGAP_AUDIO_MODE)) { |
| 1766 | tabla_codec_enable_audio_mode_bandgap(codec); |
| 1767 | } else if (choice == TABLA_BANDGAP_MBHC_MODE) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1768 | /* bandgap mode becomes fast, |
| 1769 | * mclk should be off or clk buff source souldn't be VBG |
| 1770 | * Let's turn off mclk always */ |
| 1771 | 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] | 1772 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x2, |
| 1773 | 0x2); |
| 1774 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 1775 | 0x80); |
| 1776 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x4, |
| 1777 | 0x4); |
| 1778 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 1779 | 0x01); |
| 1780 | usleep_range(1000, 1000); |
| 1781 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 1782 | 0x00); |
| 1783 | } else if ((tabla->bandgap_type == TABLA_BANDGAP_MBHC_MODE) && |
| 1784 | (choice == TABLA_BANDGAP_AUDIO_MODE)) { |
| 1785 | snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x00); |
| 1786 | usleep_range(100, 100); |
| 1787 | tabla_codec_enable_audio_mode_bandgap(codec); |
| 1788 | } else if (choice == TABLA_BANDGAP_OFF) { |
| 1789 | snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x00); |
| 1790 | } else { |
| 1791 | pr_err("%s: Error, Invalid bandgap settings\n", __func__); |
| 1792 | } |
| 1793 | tabla->bandgap_type = choice; |
| 1794 | } |
| 1795 | |
| 1796 | static void tabla_codec_disable_clock_block(struct snd_soc_codec *codec) |
| 1797 | { |
| 1798 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1799 | pr_debug("%s\n", __func__); |
| 1800 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x00); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1801 | usleep_range(50, 50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1802 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x02); |
| 1803 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x00); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1804 | usleep_range(50, 50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1805 | tabla->clock_active = false; |
| 1806 | } |
| 1807 | |
| 1808 | static int tabla_codec_mclk_index(const struct tabla_priv *tabla) |
| 1809 | { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 1810 | if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1811 | return 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 1812 | else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1813 | return 1; |
| 1814 | else { |
| 1815 | BUG_ON(1); |
| 1816 | return -EINVAL; |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | static void tabla_enable_rx_bias(struct snd_soc_codec *codec, u32 enable) |
| 1821 | { |
| 1822 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1823 | |
| 1824 | if (enable) { |
| 1825 | tabla->rx_bias_count++; |
| 1826 | if (tabla->rx_bias_count == 1) |
| 1827 | snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, |
| 1828 | 0x80, 0x80); |
| 1829 | } else { |
| 1830 | tabla->rx_bias_count--; |
| 1831 | if (!tabla->rx_bias_count) |
| 1832 | snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, |
| 1833 | 0x80, 0x00); |
| 1834 | } |
| 1835 | } |
| 1836 | |
| 1837 | static int tabla_codec_enable_config_mode(struct snd_soc_codec *codec, |
| 1838 | int enable) |
| 1839 | { |
| 1840 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1841 | |
| 1842 | pr_debug("%s: enable = %d\n", __func__, enable); |
| 1843 | if (enable) { |
| 1844 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x10, 0); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1845 | /* bandgap mode to fast */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1846 | snd_soc_write(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x17); |
| 1847 | usleep_range(5, 5); |
| 1848 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1849 | 0x80); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1850 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1851 | 0x80); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1852 | usleep_range(10, 10); |
| 1853 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, 0); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1854 | usleep_range(10000, 10000); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1855 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x08); |
| 1856 | } else { |
| 1857 | 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] | 1858 | 0); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1859 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, 0); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1860 | /* clk source to ext clk and clk buff ref to VBG */ |
| 1861 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x0C, 0x04); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1862 | } |
| 1863 | tabla->config_mode_active = enable ? true : false; |
| 1864 | |
| 1865 | return 0; |
| 1866 | } |
| 1867 | |
| 1868 | static int tabla_codec_enable_clock_block(struct snd_soc_codec *codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1869 | int config_mode) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1870 | { |
| 1871 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1872 | |
| 1873 | pr_debug("%s: config_mode = %d\n", __func__, config_mode); |
| 1874 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1875 | /* transit to RCO requires mclk off */ |
| 1876 | 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] | 1877 | if (config_mode) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1878 | /* enable RCO and switch to it */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1879 | tabla_codec_enable_config_mode(codec, 1); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1880 | snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1881 | usleep_range(1000, 1000); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1882 | } else { |
| 1883 | /* switch to MCLK */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1884 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00); |
| 1885 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1886 | if (tabla->mbhc_polling_active) { |
| 1887 | snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02); |
| 1888 | tabla_codec_enable_config_mode(codec, 0); |
| 1889 | } |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1890 | } |
| 1891 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1892 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x01, 0x01); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1893 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x00); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 1894 | /* on MCLK */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1895 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x04); |
| 1896 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_MCLK_CTL, 0x01, 0x01); |
| 1897 | usleep_range(50, 50); |
| 1898 | tabla->clock_active = true; |
| 1899 | return 0; |
| 1900 | } |
| 1901 | |
| 1902 | static int tabla_codec_enable_aux_pga(struct snd_soc_dapm_widget *w, |
| 1903 | struct snd_kcontrol *kcontrol, int event) |
| 1904 | { |
| 1905 | struct snd_soc_codec *codec = w->codec; |
| 1906 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1907 | |
| 1908 | pr_debug("%s: %d\n", __func__, event); |
| 1909 | |
| 1910 | switch (event) { |
| 1911 | case SND_SOC_DAPM_PRE_PMU: |
| 1912 | tabla_codec_enable_bandgap(codec, |
| 1913 | TABLA_BANDGAP_AUDIO_MODE); |
| 1914 | tabla_enable_rx_bias(codec, 1); |
| 1915 | |
| 1916 | snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL, |
| 1917 | 0x08, 0x08); |
| 1918 | /* Enable Zero Cross detect for AUX PGA channel |
| 1919 | * and set the initial AUX PGA gain to NEG_0P0_DB |
| 1920 | * to avoid glitches. |
| 1921 | */ |
| 1922 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 1923 | snd_soc_update_bits(codec, TABLA_A_AUX_L_EN, |
| 1924 | 0x20, 0x20); |
| 1925 | tabla->aux_l_gain = snd_soc_read(codec, |
| 1926 | TABLA_A_AUX_L_GAIN); |
| 1927 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F); |
| 1928 | } else { |
| 1929 | snd_soc_update_bits(codec, TABLA_A_AUX_R_EN, |
| 1930 | 0x20, 0x20); |
| 1931 | tabla->aux_r_gain = snd_soc_read(codec, |
| 1932 | TABLA_A_AUX_R_GAIN); |
| 1933 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F); |
| 1934 | } |
| 1935 | if (tabla->aux_pga_cnt++ == 1 |
| 1936 | && !tabla->mclk_enabled) { |
| 1937 | tabla_codec_enable_clock_block(codec, 1); |
| 1938 | pr_debug("AUX PGA enabled RC osc\n"); |
| 1939 | } |
| 1940 | break; |
| 1941 | |
| 1942 | case SND_SOC_DAPM_POST_PMU: |
| 1943 | if (w->reg == TABLA_A_AUX_L_EN) |
| 1944 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, |
| 1945 | tabla->aux_l_gain); |
| 1946 | else |
| 1947 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, |
| 1948 | tabla->aux_r_gain); |
| 1949 | break; |
| 1950 | |
| 1951 | case SND_SOC_DAPM_PRE_PMD: |
| 1952 | /* Mute AUX PGA channel in use before disabling AUX PGA */ |
| 1953 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 1954 | tabla->aux_l_gain = snd_soc_read(codec, |
| 1955 | TABLA_A_AUX_L_GAIN); |
| 1956 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F); |
| 1957 | } else { |
| 1958 | tabla->aux_r_gain = snd_soc_read(codec, |
| 1959 | TABLA_A_AUX_R_GAIN); |
| 1960 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F); |
| 1961 | } |
| 1962 | break; |
| 1963 | |
| 1964 | case SND_SOC_DAPM_POST_PMD: |
| 1965 | tabla_enable_rx_bias(codec, 0); |
| 1966 | |
| 1967 | snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL, |
| 1968 | 0x08, 0x00); |
| 1969 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 1970 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, |
| 1971 | tabla->aux_l_gain); |
| 1972 | snd_soc_update_bits(codec, TABLA_A_AUX_L_EN, |
| 1973 | 0x20, 0x00); |
| 1974 | } else { |
| 1975 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, |
| 1976 | tabla->aux_r_gain); |
| 1977 | snd_soc_update_bits(codec, TABLA_A_AUX_R_EN, |
| 1978 | 0x20, 0x00); |
| 1979 | } |
| 1980 | |
| 1981 | if (tabla->aux_pga_cnt-- == 0) { |
| 1982 | if (tabla->mbhc_polling_active) |
| 1983 | tabla_codec_enable_bandgap(codec, |
| 1984 | TABLA_BANDGAP_MBHC_MODE); |
| 1985 | else |
| 1986 | tabla_codec_enable_bandgap(codec, |
| 1987 | TABLA_BANDGAP_OFF); |
| 1988 | |
| 1989 | if (!tabla->mclk_enabled && |
| 1990 | !tabla->mbhc_polling_active) { |
| 1991 | tabla_codec_enable_clock_block(codec, 0); |
| 1992 | } |
| 1993 | } |
| 1994 | break; |
| 1995 | } |
| 1996 | return 0; |
| 1997 | } |
| 1998 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1999 | static int tabla_codec_enable_lineout(struct snd_soc_dapm_widget *w, |
| 2000 | struct snd_kcontrol *kcontrol, int event) |
| 2001 | { |
| 2002 | struct snd_soc_codec *codec = w->codec; |
| 2003 | u16 lineout_gain_reg; |
| 2004 | |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 2005 | pr_debug("%s %d %s\n", __func__, event, w->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2006 | |
| 2007 | switch (w->shift) { |
| 2008 | case 0: |
| 2009 | lineout_gain_reg = TABLA_A_RX_LINE_1_GAIN; |
| 2010 | break; |
| 2011 | case 1: |
| 2012 | lineout_gain_reg = TABLA_A_RX_LINE_2_GAIN; |
| 2013 | break; |
| 2014 | case 2: |
| 2015 | lineout_gain_reg = TABLA_A_RX_LINE_3_GAIN; |
| 2016 | break; |
| 2017 | case 3: |
| 2018 | lineout_gain_reg = TABLA_A_RX_LINE_4_GAIN; |
| 2019 | break; |
| 2020 | case 4: |
| 2021 | lineout_gain_reg = TABLA_A_RX_LINE_5_GAIN; |
| 2022 | break; |
| 2023 | default: |
| 2024 | pr_err("%s: Error, incorrect lineout register value\n", |
| 2025 | __func__); |
| 2026 | return -EINVAL; |
| 2027 | } |
| 2028 | |
| 2029 | switch (event) { |
| 2030 | case SND_SOC_DAPM_PRE_PMU: |
| 2031 | snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40); |
| 2032 | break; |
| 2033 | case SND_SOC_DAPM_POST_PMU: |
Krishnankutty Kolathappilly | 31169f4 | 2011-11-17 10:33:11 -0800 | [diff] [blame] | 2034 | pr_debug("%s: sleeping 16 ms after %s PA turn on\n", |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 2035 | __func__, w->name); |
Krishnankutty Kolathappilly | 31169f4 | 2011-11-17 10:33:11 -0800 | [diff] [blame] | 2036 | usleep_range(16000, 16000); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2037 | break; |
| 2038 | case SND_SOC_DAPM_POST_PMD: |
| 2039 | snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00); |
| 2040 | break; |
| 2041 | } |
| 2042 | return 0; |
| 2043 | } |
| 2044 | |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2045 | |
| 2046 | static int tabla_codec_enable_dmic(struct snd_soc_dapm_widget *w, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2047 | struct snd_kcontrol *kcontrol, int event) |
| 2048 | { |
| 2049 | struct snd_soc_codec *codec = w->codec; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2050 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2051 | u8 dmic_clk_en; |
| 2052 | s32 *dmic_clk_cnt; |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2053 | unsigned int dmic; |
| 2054 | int ret; |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2055 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2056 | ret = kstrtouint(strpbrk(w->name, "123456"), 10, &dmic); |
| 2057 | if (ret < 0) { |
| 2058 | pr_err("%s: Invalid DMIC line on the codec\n", __func__); |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2059 | return -EINVAL; |
| 2060 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2061 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2062 | switch (dmic) { |
| 2063 | case 1: |
| 2064 | case 2: |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2065 | dmic_clk_en = 0x01; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2066 | dmic_clk_cnt = &(tabla->dmic_1_2_clk_cnt); |
| 2067 | |
| 2068 | pr_debug("%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n", |
| 2069 | __func__, event, dmic, *dmic_clk_cnt); |
| 2070 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2071 | break; |
| 2072 | |
| 2073 | case 3: |
| 2074 | case 4: |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2075 | dmic_clk_en = 0x04; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2076 | dmic_clk_cnt = &(tabla->dmic_3_4_clk_cnt); |
| 2077 | |
| 2078 | pr_debug("%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n", |
| 2079 | __func__, event, dmic, *dmic_clk_cnt); |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2080 | break; |
| 2081 | |
| 2082 | case 5: |
| 2083 | case 6: |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2084 | dmic_clk_en = 0x10; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2085 | dmic_clk_cnt = &(tabla->dmic_5_6_clk_cnt); |
| 2086 | |
| 2087 | pr_debug("%s() event %d DMIC%d dmic_5_6_clk_cnt %d\n", |
| 2088 | __func__, event, dmic, *dmic_clk_cnt); |
| 2089 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2090 | break; |
| 2091 | |
| 2092 | default: |
| 2093 | pr_err("%s: Invalid DMIC Selection\n", __func__); |
| 2094 | return -EINVAL; |
| 2095 | } |
| 2096 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2097 | switch (event) { |
| 2098 | case SND_SOC_DAPM_PRE_PMU: |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2099 | |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2100 | (*dmic_clk_cnt)++; |
| 2101 | if (*dmic_clk_cnt == 1) |
| 2102 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL, |
| 2103 | dmic_clk_en, dmic_clk_en); |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2104 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2105 | break; |
| 2106 | case SND_SOC_DAPM_POST_PMD: |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2107 | |
| 2108 | (*dmic_clk_cnt)--; |
| 2109 | if (*dmic_clk_cnt == 0) |
| 2110 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL, |
| 2111 | dmic_clk_en, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2112 | break; |
| 2113 | } |
| 2114 | return 0; |
| 2115 | } |
| 2116 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2117 | static int tabla_codec_enable_anc(struct snd_soc_dapm_widget *w, |
| 2118 | struct snd_kcontrol *kcontrol, int event) |
| 2119 | { |
| 2120 | struct snd_soc_codec *codec = w->codec; |
| 2121 | const char *filename; |
| 2122 | const struct firmware *fw; |
| 2123 | int i; |
| 2124 | int ret; |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2125 | int num_anc_slots; |
| 2126 | struct anc_header *anc_head; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2127 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2128 | u32 anc_writes_size = 0; |
| 2129 | int anc_size_remaining; |
| 2130 | u32 *anc_ptr; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2131 | u16 reg; |
| 2132 | u8 mask, val, old_val; |
| 2133 | |
| 2134 | pr_debug("%s %d\n", __func__, event); |
| 2135 | switch (event) { |
| 2136 | case SND_SOC_DAPM_PRE_PMU: |
| 2137 | |
Bradley Rubin | 4283a4c | 2011-07-29 16:18:54 -0700 | [diff] [blame] | 2138 | filename = "wcd9310/wcd9310_anc.bin"; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2139 | |
| 2140 | ret = request_firmware(&fw, filename, codec->dev); |
| 2141 | if (ret != 0) { |
| 2142 | dev_err(codec->dev, "Failed to acquire ANC data: %d\n", |
| 2143 | ret); |
| 2144 | return -ENODEV; |
| 2145 | } |
| 2146 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2147 | if (fw->size < sizeof(struct anc_header)) { |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2148 | dev_err(codec->dev, "Not enough data\n"); |
| 2149 | release_firmware(fw); |
| 2150 | return -ENOMEM; |
| 2151 | } |
| 2152 | |
| 2153 | /* First number is the number of register writes */ |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2154 | anc_head = (struct anc_header *)(fw->data); |
| 2155 | anc_ptr = (u32 *)((u32)fw->data + sizeof(struct anc_header)); |
| 2156 | anc_size_remaining = fw->size - sizeof(struct anc_header); |
| 2157 | num_anc_slots = anc_head->num_anc_slots; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2158 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2159 | if (tabla->anc_slot >= num_anc_slots) { |
| 2160 | dev_err(codec->dev, "Invalid ANC slot selected\n"); |
| 2161 | release_firmware(fw); |
| 2162 | return -EINVAL; |
| 2163 | } |
| 2164 | |
| 2165 | for (i = 0; i < num_anc_slots; i++) { |
| 2166 | |
| 2167 | if (anc_size_remaining < TABLA_PACKED_REG_SIZE) { |
| 2168 | dev_err(codec->dev, "Invalid register format\n"); |
| 2169 | release_firmware(fw); |
| 2170 | return -EINVAL; |
| 2171 | } |
| 2172 | anc_writes_size = (u32)(*anc_ptr); |
| 2173 | anc_size_remaining -= sizeof(u32); |
| 2174 | anc_ptr += 1; |
| 2175 | |
| 2176 | if (anc_writes_size * TABLA_PACKED_REG_SIZE |
| 2177 | > anc_size_remaining) { |
| 2178 | dev_err(codec->dev, "Invalid register format\n"); |
| 2179 | release_firmware(fw); |
| 2180 | return -ENOMEM; |
| 2181 | } |
| 2182 | |
| 2183 | if (tabla->anc_slot == i) |
| 2184 | break; |
| 2185 | |
| 2186 | anc_size_remaining -= (anc_writes_size * |
| 2187 | TABLA_PACKED_REG_SIZE); |
Bradley Rubin | 939ff3f | 2011-08-26 17:19:34 -0700 | [diff] [blame] | 2188 | anc_ptr += anc_writes_size; |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2189 | } |
| 2190 | if (i == num_anc_slots) { |
| 2191 | dev_err(codec->dev, "Selected ANC slot not present\n"); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2192 | release_firmware(fw); |
| 2193 | return -ENOMEM; |
| 2194 | } |
| 2195 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2196 | for (i = 0; i < anc_writes_size; i++) { |
| 2197 | TABLA_CODEC_UNPACK_ENTRY(anc_ptr[i], reg, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2198 | mask, val); |
| 2199 | old_val = snd_soc_read(codec, reg); |
Bradley Rubin | 4283a4c | 2011-07-29 16:18:54 -0700 | [diff] [blame] | 2200 | snd_soc_write(codec, reg, (old_val & ~mask) | |
| 2201 | (val & mask)); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2202 | } |
| 2203 | release_firmware(fw); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2204 | |
Joonwoo Park | 743d0e3 | 2012-05-17 15:11:58 -0700 | [diff] [blame^] | 2205 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 2206 | /* if MBHC polling is active, set TX7_MBHC_EN bit 7 */ |
| 2207 | if (tabla->mbhc_polling_active) |
| 2208 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, |
| 2209 | 0x80); |
| 2210 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2211 | break; |
| 2212 | case SND_SOC_DAPM_POST_PMD: |
Joonwoo Park | 743d0e3 | 2012-05-17 15:11:58 -0700 | [diff] [blame^] | 2213 | /* unset TX7_MBHC_EN bit 7 */ |
| 2214 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00); |
| 2215 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2216 | snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0xFF); |
| 2217 | snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_CLK_EN_CTL, 0); |
| 2218 | break; |
| 2219 | } |
| 2220 | return 0; |
| 2221 | } |
| 2222 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2223 | /* called under codec_resource_lock acquisition */ |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2224 | static void tabla_codec_start_hs_polling(struct snd_soc_codec *codec) |
| 2225 | { |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2226 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2227 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
| 2228 | int mbhc_state = tabla->mbhc_state; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2229 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2230 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2231 | if (!tabla->mbhc_polling_active) { |
| 2232 | pr_debug("Polling is not active, do not start polling\n"); |
| 2233 | return; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2234 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2235 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2236 | |
| 2237 | if (!tabla->no_mic_headset_override) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2238 | if (mbhc_state == MBHC_STATE_POTENTIAL) { |
| 2239 | pr_debug("%s recovering MBHC state macine\n", __func__); |
| 2240 | tabla->mbhc_state = MBHC_STATE_POTENTIAL_RECOVERY; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2241 | /* set to max button press threshold */ |
| 2242 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 2243 | 0x7F); |
| 2244 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 2245 | 0xFF); |
| 2246 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, |
| 2247 | (TABLA_IS_1_X(tabla_core->version) ? |
| 2248 | 0x07 : 0x7F)); |
| 2249 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, |
| 2250 | 0xFF); |
| 2251 | /* set to max */ |
| 2252 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, |
| 2253 | 0x7F); |
| 2254 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, |
| 2255 | 0xFF); |
| 2256 | } |
| 2257 | } |
| 2258 | |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2259 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1); |
| 2260 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0); |
| 2261 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2262 | pr_debug("%s: leave\n", __func__); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2265 | /* called under codec_resource_lock acquisition */ |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2266 | static void tabla_codec_pause_hs_polling(struct snd_soc_codec *codec) |
| 2267 | { |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2268 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2269 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2270 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2271 | if (!tabla->mbhc_polling_active) { |
| 2272 | pr_debug("polling not active, nothing to pause\n"); |
| 2273 | return; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2274 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2275 | |
| 2276 | 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] | 2277 | pr_debug("%s: leave\n", __func__); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2278 | } |
| 2279 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2280 | 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] | 2281 | { |
| 2282 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2283 | u8 reg_mode_val, cur_mode_val; |
| 2284 | bool mbhc_was_polling = false; |
| 2285 | |
| 2286 | if (mode) |
| 2287 | reg_mode_val = TABLA_CFILT_FAST_MODE; |
| 2288 | else |
| 2289 | reg_mode_val = TABLA_CFILT_SLOW_MODE; |
| 2290 | |
| 2291 | cur_mode_val = snd_soc_read(codec, |
| 2292 | tabla->mbhc_bias_regs.cfilt_ctl) & 0x40; |
| 2293 | |
| 2294 | if (cur_mode_val != reg_mode_val) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2295 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 2296 | if (tabla->mbhc_polling_active) { |
| 2297 | tabla_codec_pause_hs_polling(codec); |
| 2298 | mbhc_was_polling = true; |
| 2299 | } |
| 2300 | snd_soc_update_bits(codec, |
| 2301 | tabla->mbhc_bias_regs.cfilt_ctl, 0x40, reg_mode_val); |
| 2302 | if (mbhc_was_polling) |
| 2303 | tabla_codec_start_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2304 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 2305 | pr_debug("%s: CFILT mode change (%x to %x)\n", __func__, |
| 2306 | cur_mode_val, reg_mode_val); |
| 2307 | } else { |
| 2308 | pr_debug("%s: CFILT Value is already %x\n", |
| 2309 | __func__, cur_mode_val); |
| 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | static void tabla_codec_update_cfilt_usage(struct snd_soc_codec *codec, |
| 2314 | u8 cfilt_sel, int inc) |
| 2315 | { |
| 2316 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2317 | u32 *cfilt_cnt_ptr = NULL; |
| 2318 | u16 micb_cfilt_reg; |
| 2319 | |
| 2320 | switch (cfilt_sel) { |
| 2321 | case TABLA_CFILT1_SEL: |
| 2322 | cfilt_cnt_ptr = &tabla->cfilt1_cnt; |
| 2323 | micb_cfilt_reg = TABLA_A_MICB_CFILT_1_CTL; |
| 2324 | break; |
| 2325 | case TABLA_CFILT2_SEL: |
| 2326 | cfilt_cnt_ptr = &tabla->cfilt2_cnt; |
| 2327 | micb_cfilt_reg = TABLA_A_MICB_CFILT_2_CTL; |
| 2328 | break; |
| 2329 | case TABLA_CFILT3_SEL: |
| 2330 | cfilt_cnt_ptr = &tabla->cfilt3_cnt; |
| 2331 | micb_cfilt_reg = TABLA_A_MICB_CFILT_3_CTL; |
| 2332 | break; |
| 2333 | default: |
| 2334 | return; /* should not happen */ |
| 2335 | } |
| 2336 | |
| 2337 | if (inc) { |
| 2338 | if (!(*cfilt_cnt_ptr)++) { |
| 2339 | /* Switch CFILT to slow mode if MBHC CFILT being used */ |
| 2340 | if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel) |
| 2341 | tabla_codec_switch_cfilt_mode(codec, 0); |
| 2342 | |
| 2343 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80); |
| 2344 | } |
| 2345 | } else { |
| 2346 | /* check if count not zero, decrement |
| 2347 | * then check if zero, go ahead disable cfilter |
| 2348 | */ |
| 2349 | if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr)) { |
| 2350 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0); |
| 2351 | |
| 2352 | /* Switch CFILT to fast mode if MBHC CFILT being used */ |
| 2353 | if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel) |
| 2354 | tabla_codec_switch_cfilt_mode(codec, 1); |
| 2355 | } |
| 2356 | } |
| 2357 | } |
| 2358 | |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2359 | static int tabla_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv) |
| 2360 | { |
| 2361 | int rc = -EINVAL; |
| 2362 | unsigned min_mv, max_mv; |
| 2363 | |
| 2364 | switch (ldoh_v) { |
| 2365 | case TABLA_LDOH_1P95_V: |
| 2366 | min_mv = 160; |
| 2367 | max_mv = 1800; |
| 2368 | break; |
| 2369 | case TABLA_LDOH_2P35_V: |
| 2370 | min_mv = 200; |
| 2371 | max_mv = 2200; |
| 2372 | break; |
| 2373 | case TABLA_LDOH_2P75_V: |
| 2374 | min_mv = 240; |
| 2375 | max_mv = 2600; |
| 2376 | break; |
| 2377 | case TABLA_LDOH_2P85_V: |
| 2378 | min_mv = 250; |
| 2379 | max_mv = 2700; |
| 2380 | break; |
| 2381 | default: |
| 2382 | goto done; |
| 2383 | } |
| 2384 | |
| 2385 | if (cfilt_mv < min_mv || cfilt_mv > max_mv) |
| 2386 | goto done; |
| 2387 | |
| 2388 | for (rc = 4; rc <= 44; rc++) { |
| 2389 | min_mv = max_mv * (rc) / 44; |
| 2390 | if (min_mv >= cfilt_mv) { |
| 2391 | rc -= 4; |
| 2392 | break; |
| 2393 | } |
| 2394 | } |
| 2395 | done: |
| 2396 | return rc; |
| 2397 | } |
| 2398 | |
| 2399 | static bool tabla_is_hph_pa_on(struct snd_soc_codec *codec) |
| 2400 | { |
| 2401 | u8 hph_reg_val = 0; |
| 2402 | hph_reg_val = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_EN); |
| 2403 | |
| 2404 | return (hph_reg_val & 0x30) ? true : false; |
| 2405 | } |
| 2406 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 2407 | static bool tabla_is_hph_dac_on(struct snd_soc_codec *codec, int left) |
| 2408 | { |
| 2409 | u8 hph_reg_val = 0; |
| 2410 | if (left) |
| 2411 | hph_reg_val = snd_soc_read(codec, |
| 2412 | TABLA_A_RX_HPH_L_DAC_CTL); |
| 2413 | else |
| 2414 | hph_reg_val = snd_soc_read(codec, |
| 2415 | TABLA_A_RX_HPH_R_DAC_CTL); |
| 2416 | |
| 2417 | return (hph_reg_val & 0xC0) ? true : false; |
| 2418 | } |
| 2419 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2420 | static void tabla_turn_onoff_override(struct snd_soc_codec *codec, bool on) |
| 2421 | { |
| 2422 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, on << 2); |
| 2423 | } |
| 2424 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2425 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2426 | static void tabla_codec_drive_v_to_micbias(struct snd_soc_codec *codec, |
| 2427 | int usec) |
| 2428 | { |
| 2429 | int cfilt_k_val; |
| 2430 | bool set = true; |
| 2431 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2432 | |
| 2433 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
| 2434 | tabla->mbhc_micbias_switched) { |
| 2435 | pr_debug("%s: set mic V to micbias V\n", __func__); |
| 2436 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 2437 | tabla_turn_onoff_override(codec, true); |
| 2438 | while (1) { |
| 2439 | cfilt_k_val = tabla_find_k_value( |
| 2440 | tabla->pdata->micbias.ldoh_v, |
| 2441 | set ? tabla->mbhc_data.micb_mv : |
| 2442 | VDDIO_MICBIAS_MV); |
| 2443 | snd_soc_update_bits(codec, |
| 2444 | tabla->mbhc_bias_regs.cfilt_val, |
| 2445 | 0xFC, (cfilt_k_val << 2)); |
| 2446 | if (!set) |
| 2447 | break; |
| 2448 | usleep_range(usec, usec); |
| 2449 | set = false; |
| 2450 | } |
| 2451 | tabla_turn_onoff_override(codec, false); |
| 2452 | } |
| 2453 | } |
| 2454 | |
| 2455 | /* called under codec_resource_lock acquisition */ |
| 2456 | static void __tabla_codec_switch_micbias(struct snd_soc_codec *codec, |
| 2457 | int vddio_switch, bool restartpolling, |
| 2458 | bool checkpolling) |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2459 | { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2460 | int cfilt_k_val; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 2461 | bool override; |
| 2462 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2463 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2464 | if (vddio_switch && !tabla->mbhc_micbias_switched && |
| 2465 | (!checkpolling || tabla->mbhc_polling_active)) { |
| 2466 | if (restartpolling) |
Bhalchandra Gajare | c1e19c4 | 2011-11-18 11:22:56 -0800 | [diff] [blame] | 2467 | tabla_codec_pause_hs_polling(codec); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 2468 | override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04; |
| 2469 | if (!override) |
| 2470 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2471 | /* Adjust threshold if Mic Bias voltage changes */ |
| 2472 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2473 | cfilt_k_val = tabla_find_k_value( |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2474 | tabla->pdata->micbias.ldoh_v, |
| 2475 | VDDIO_MICBIAS_MV); |
| 2476 | usleep_range(10000, 10000); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2477 | snd_soc_update_bits(codec, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2478 | tabla->mbhc_bias_regs.cfilt_val, |
| 2479 | 0xFC, (cfilt_k_val << 2)); |
| 2480 | usleep_range(10000, 10000); |
| 2481 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 2482 | tabla->mbhc_data.adj_v_ins_hu & 0xFF); |
| 2483 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 2484 | (tabla->mbhc_data.adj_v_ins_hu >> 8) & |
| 2485 | 0xFF); |
| 2486 | pr_debug("%s: Programmed MBHC thresholds to VDDIO\n", |
| 2487 | __func__); |
| 2488 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2489 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2490 | /* enable MIC BIAS Switch to VDDIO */ |
| 2491 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2492 | 0x80, 0x80); |
| 2493 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2494 | 0x10, 0x00); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 2495 | if (!override) |
| 2496 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2497 | if (restartpolling) |
Bhalchandra Gajare | c1e19c4 | 2011-11-18 11:22:56 -0800 | [diff] [blame] | 2498 | tabla_codec_start_hs_polling(codec); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2499 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2500 | tabla->mbhc_micbias_switched = true; |
| 2501 | pr_debug("%s: VDDIO switch enabled\n", __func__); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2502 | } else if (!vddio_switch && tabla->mbhc_micbias_switched) { |
| 2503 | if ((!checkpolling || tabla->mbhc_polling_active) && |
| 2504 | restartpolling) |
| 2505 | tabla_codec_pause_hs_polling(codec); |
| 2506 | /* Reprogram thresholds */ |
| 2507 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
| 2508 | cfilt_k_val = tabla_find_k_value( |
| 2509 | tabla->pdata->micbias.ldoh_v, |
| 2510 | tabla->mbhc_data.micb_mv); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2511 | snd_soc_update_bits(codec, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2512 | tabla->mbhc_bias_regs.cfilt_val, |
| 2513 | 0xFC, (cfilt_k_val << 2)); |
| 2514 | usleep_range(10000, 10000); |
| 2515 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 2516 | tabla->mbhc_data.v_ins_hu & 0xFF); |
| 2517 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 2518 | (tabla->mbhc_data.v_ins_hu >> 8) & 0xFF); |
| 2519 | pr_debug("%s: Programmed MBHC thresholds to MICBIAS\n", |
| 2520 | __func__); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2521 | } |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2522 | |
| 2523 | /* Disable MIC BIAS Switch to VDDIO */ |
| 2524 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2525 | 0x80, 0x00); |
| 2526 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2527 | 0x10, 0x00); |
| 2528 | |
| 2529 | if ((!checkpolling || tabla->mbhc_polling_active) && |
| 2530 | restartpolling) |
| 2531 | tabla_codec_start_hs_polling(codec); |
| 2532 | |
| 2533 | tabla->mbhc_micbias_switched = false; |
| 2534 | pr_debug("%s: VDDIO switch disabled\n", __func__); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2535 | } |
| 2536 | } |
| 2537 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2538 | static void tabla_codec_switch_micbias(struct snd_soc_codec *codec, |
| 2539 | int vddio_switch) |
| 2540 | { |
| 2541 | return __tabla_codec_switch_micbias(codec, vddio_switch, true, true); |
| 2542 | } |
| 2543 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2544 | static int tabla_codec_enable_micbias(struct snd_soc_dapm_widget *w, |
| 2545 | struct snd_kcontrol *kcontrol, int event) |
| 2546 | { |
| 2547 | struct snd_soc_codec *codec = w->codec; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2548 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2549 | u16 micb_int_reg; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2550 | int micb_line; |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 2551 | u8 cfilt_sel_val = 0; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2552 | char *internal1_text = "Internal1"; |
| 2553 | char *internal2_text = "Internal2"; |
| 2554 | char *internal3_text = "Internal3"; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2555 | |
| 2556 | pr_debug("%s %d\n", __func__, event); |
| 2557 | switch (w->reg) { |
| 2558 | case TABLA_A_MICB_1_CTL: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2559 | micb_int_reg = TABLA_A_MICB_1_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2560 | cfilt_sel_val = tabla->pdata->micbias.bias1_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2561 | micb_line = TABLA_MICBIAS1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2562 | break; |
| 2563 | case TABLA_A_MICB_2_CTL: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2564 | micb_int_reg = TABLA_A_MICB_2_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2565 | cfilt_sel_val = tabla->pdata->micbias.bias2_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2566 | micb_line = TABLA_MICBIAS2; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2567 | break; |
| 2568 | case TABLA_A_MICB_3_CTL: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2569 | micb_int_reg = TABLA_A_MICB_3_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2570 | cfilt_sel_val = tabla->pdata->micbias.bias3_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2571 | micb_line = TABLA_MICBIAS3; |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 2572 | break; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 2573 | case TABLA_1_A_MICB_4_CTL: |
| 2574 | case TABLA_2_A_MICB_4_CTL: |
| 2575 | micb_int_reg = tabla->reg_addr.micb_4_int_rbias; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2576 | cfilt_sel_val = tabla->pdata->micbias.bias4_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2577 | micb_line = TABLA_MICBIAS4; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2578 | break; |
| 2579 | default: |
| 2580 | pr_err("%s: Error, invalid micbias register\n", __func__); |
| 2581 | return -EINVAL; |
| 2582 | } |
| 2583 | |
| 2584 | switch (event) { |
| 2585 | case SND_SOC_DAPM_PRE_PMU: |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2586 | /* Decide whether to switch the micbias for MBHC */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2587 | if (w->reg == tabla->mbhc_bias_regs.ctl_reg) { |
| 2588 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2589 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2590 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 2591 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2592 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 2593 | snd_soc_update_bits(codec, w->reg, 0x0E, 0x0A); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2594 | tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 1); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2595 | |
| 2596 | if (strnstr(w->name, internal1_text, 30)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2597 | snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2598 | else if (strnstr(w->name, internal2_text, 30)) |
| 2599 | snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C); |
| 2600 | else if (strnstr(w->name, internal3_text, 30)) |
| 2601 | snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3); |
| 2602 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2603 | break; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2604 | case SND_SOC_DAPM_POST_PMU: |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2605 | |
| 2606 | usleep_range(20000, 20000); |
| 2607 | |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2608 | if (tabla->mbhc_polling_active && |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2609 | tabla->mbhc_cfg.micbias == micb_line) { |
| 2610 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2611 | tabla_codec_pause_hs_polling(codec); |
| 2612 | tabla_codec_start_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2613 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2614 | } |
| 2615 | break; |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2616 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2617 | case SND_SOC_DAPM_POST_PMD: |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2618 | if ((w->reg == tabla->mbhc_bias_regs.ctl_reg) && |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2619 | tabla_is_hph_pa_on(codec)) { |
| 2620 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2621 | tabla_codec_switch_micbias(codec, 1); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2622 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 2623 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2624 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2625 | if (strnstr(w->name, internal1_text, 30)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2626 | snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2627 | else if (strnstr(w->name, internal2_text, 30)) |
| 2628 | snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00); |
| 2629 | else if (strnstr(w->name, internal3_text, 30)) |
| 2630 | snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0); |
| 2631 | |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2632 | tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2633 | break; |
| 2634 | } |
| 2635 | |
| 2636 | return 0; |
| 2637 | } |
| 2638 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2639 | |
| 2640 | static void tx_hpf_corner_freq_callback(struct work_struct *work) |
| 2641 | { |
| 2642 | struct delayed_work *hpf_delayed_work; |
| 2643 | struct hpf_work *hpf_work; |
| 2644 | struct tabla_priv *tabla; |
| 2645 | struct snd_soc_codec *codec; |
| 2646 | u16 tx_mux_ctl_reg; |
| 2647 | u8 hpf_cut_of_freq; |
| 2648 | |
| 2649 | hpf_delayed_work = to_delayed_work(work); |
| 2650 | hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork); |
| 2651 | tabla = hpf_work->tabla; |
| 2652 | codec = hpf_work->tabla->codec; |
| 2653 | hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq; |
| 2654 | |
| 2655 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + |
| 2656 | (hpf_work->decimator - 1) * 8; |
| 2657 | |
| 2658 | pr_debug("%s(): decimator %u hpf_cut_of_freq 0x%x\n", __func__, |
| 2659 | hpf_work->decimator, (unsigned int)hpf_cut_of_freq); |
| 2660 | |
| 2661 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4); |
| 2662 | } |
| 2663 | |
| 2664 | #define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30 |
| 2665 | #define CF_MIN_3DB_4HZ 0x0 |
| 2666 | #define CF_MIN_3DB_75HZ 0x1 |
| 2667 | #define CF_MIN_3DB_150HZ 0x2 |
| 2668 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2669 | static int tabla_codec_enable_dec(struct snd_soc_dapm_widget *w, |
| 2670 | struct snd_kcontrol *kcontrol, int event) |
| 2671 | { |
| 2672 | struct snd_soc_codec *codec = w->codec; |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2673 | unsigned int decimator; |
| 2674 | char *dec_name = NULL; |
| 2675 | char *widget_name = NULL; |
| 2676 | char *temp; |
| 2677 | int ret = 0; |
| 2678 | u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg; |
| 2679 | u8 dec_hpf_cut_of_freq; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2680 | int offset; |
| 2681 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2682 | |
| 2683 | pr_debug("%s %d\n", __func__, event); |
| 2684 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2685 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 2686 | if (!widget_name) |
| 2687 | return -ENOMEM; |
| 2688 | temp = widget_name; |
| 2689 | |
| 2690 | dec_name = strsep(&widget_name, " "); |
| 2691 | widget_name = temp; |
| 2692 | if (!dec_name) { |
| 2693 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 2694 | ret = -EINVAL; |
| 2695 | goto out; |
| 2696 | } |
| 2697 | |
| 2698 | ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator); |
| 2699 | if (ret < 0) { |
| 2700 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 2701 | ret = -EINVAL; |
| 2702 | goto out; |
| 2703 | } |
| 2704 | |
| 2705 | pr_debug("%s(): widget = %s dec_name = %s decimator = %u\n", __func__, |
| 2706 | w->name, dec_name, decimator); |
| 2707 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2708 | if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2709 | dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B1_CTL; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2710 | offset = 0; |
| 2711 | } 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] | 2712 | dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B2_CTL; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2713 | offset = 8; |
| 2714 | } else { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2715 | pr_err("%s: Error, incorrect dec\n", __func__); |
| 2716 | return -EINVAL; |
| 2717 | } |
| 2718 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2719 | tx_vol_ctl_reg = TABLA_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator -1); |
| 2720 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 2721 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2722 | switch (event) { |
| 2723 | case SND_SOC_DAPM_PRE_PMU: |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2724 | |
| 2725 | // Enableable TX digital mute */ |
| 2726 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 2727 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2728 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, |
| 2729 | 1 << w->shift); |
| 2730 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0); |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2731 | |
| 2732 | dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg); |
| 2733 | |
| 2734 | dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4; |
| 2735 | |
| 2736 | tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq = |
| 2737 | dec_hpf_cut_of_freq; |
| 2738 | |
| 2739 | if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) { |
| 2740 | |
| 2741 | /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */ |
| 2742 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 2743 | CF_MIN_3DB_150HZ << 4); |
| 2744 | } |
| 2745 | |
| 2746 | /* enable HPF */ |
| 2747 | snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00); |
| 2748 | |
| 2749 | break; |
| 2750 | |
| 2751 | case SND_SOC_DAPM_POST_PMU: |
| 2752 | |
| 2753 | /* Disable TX digital mute */ |
| 2754 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00); |
| 2755 | |
| 2756 | if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq != |
| 2757 | CF_MIN_3DB_150HZ) { |
| 2758 | |
| 2759 | schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork, |
| 2760 | msecs_to_jiffies(300)); |
| 2761 | } |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2762 | /* apply the digital gain after the decimator is enabled*/ |
| 2763 | if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg)) |
| 2764 | snd_soc_write(codec, |
| 2765 | tx_digital_gain_reg[w->shift + offset], |
| 2766 | snd_soc_read(codec, |
| 2767 | tx_digital_gain_reg[w->shift + offset]) |
| 2768 | ); |
| 2769 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2770 | break; |
| 2771 | |
| 2772 | case SND_SOC_DAPM_PRE_PMD: |
| 2773 | |
| 2774 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 2775 | cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork); |
| 2776 | break; |
| 2777 | |
| 2778 | case SND_SOC_DAPM_POST_PMD: |
| 2779 | |
| 2780 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08); |
| 2781 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 2782 | (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4); |
| 2783 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2784 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2785 | } |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2786 | out: |
| 2787 | kfree(widget_name); |
| 2788 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 2791 | static int tabla_codec_reset_interpolator(struct snd_soc_dapm_widget *w, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2792 | struct snd_kcontrol *kcontrol, int event) |
| 2793 | { |
| 2794 | struct snd_soc_codec *codec = w->codec; |
| 2795 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 2796 | pr_debug("%s %d %s\n", __func__, event, w->name); |
| 2797 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2798 | switch (event) { |
| 2799 | case SND_SOC_DAPM_PRE_PMU: |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 2800 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL, |
| 2801 | 1 << w->shift, 1 << w->shift); |
| 2802 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL, |
| 2803 | 1 << w->shift, 0x0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2804 | break; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2805 | case SND_SOC_DAPM_POST_PMU: |
| 2806 | /* apply the digital gain after the interpolator is enabled*/ |
| 2807 | if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg)) |
| 2808 | snd_soc_write(codec, |
| 2809 | rx_digital_gain_reg[w->shift], |
| 2810 | snd_soc_read(codec, |
| 2811 | rx_digital_gain_reg[w->shift]) |
| 2812 | ); |
| 2813 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2814 | } |
| 2815 | return 0; |
| 2816 | } |
| 2817 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2818 | static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w, |
| 2819 | struct snd_kcontrol *kcontrol, int event) |
| 2820 | { |
| 2821 | switch (event) { |
| 2822 | case SND_SOC_DAPM_POST_PMU: |
| 2823 | case SND_SOC_DAPM_POST_PMD: |
| 2824 | usleep_range(1000, 1000); |
| 2825 | break; |
| 2826 | } |
| 2827 | return 0; |
| 2828 | } |
| 2829 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 2830 | static int tabla_codec_enable_rx_bias(struct snd_soc_dapm_widget *w, |
| 2831 | struct snd_kcontrol *kcontrol, int event) |
| 2832 | { |
| 2833 | struct snd_soc_codec *codec = w->codec; |
| 2834 | |
| 2835 | pr_debug("%s %d\n", __func__, event); |
| 2836 | |
| 2837 | switch (event) { |
| 2838 | case SND_SOC_DAPM_PRE_PMU: |
| 2839 | tabla_enable_rx_bias(codec, 1); |
| 2840 | break; |
| 2841 | case SND_SOC_DAPM_POST_PMD: |
| 2842 | tabla_enable_rx_bias(codec, 0); |
| 2843 | break; |
| 2844 | } |
| 2845 | return 0; |
| 2846 | } |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 2847 | static int tabla_hphr_dac_event(struct snd_soc_dapm_widget *w, |
| 2848 | struct snd_kcontrol *kcontrol, int event) |
| 2849 | { |
| 2850 | struct snd_soc_codec *codec = w->codec; |
| 2851 | |
| 2852 | pr_debug("%s %s %d\n", __func__, w->name, event); |
| 2853 | |
| 2854 | switch (event) { |
| 2855 | case SND_SOC_DAPM_PRE_PMU: |
| 2856 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 2857 | break; |
| 2858 | case SND_SOC_DAPM_POST_PMD: |
| 2859 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 2860 | break; |
| 2861 | } |
| 2862 | return 0; |
| 2863 | } |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 2864 | |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 2865 | static void tabla_snd_soc_jack_report(struct tabla_priv *tabla, |
| 2866 | struct snd_soc_jack *jack, int status, |
| 2867 | int mask) |
| 2868 | { |
| 2869 | /* XXX: wake_lock_timeout()? */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2870 | snd_soc_jack_report_no_dapm(jack, status, mask); |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 2871 | } |
| 2872 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 2873 | static void hphocp_off_report(struct tabla_priv *tabla, |
| 2874 | u32 jack_status, int irq) |
| 2875 | { |
| 2876 | struct snd_soc_codec *codec; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2877 | if (!tabla) { |
| 2878 | pr_err("%s: Bad tabla private data\n", __func__); |
| 2879 | return; |
| 2880 | } |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 2881 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2882 | pr_debug("%s: clear ocp status %x\n", __func__, jack_status); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2883 | codec = tabla->codec; |
| 2884 | if (tabla->hph_status & jack_status) { |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 2885 | tabla->hph_status &= ~jack_status; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2886 | if (tabla->mbhc_cfg.headset_jack) |
| 2887 | tabla_snd_soc_jack_report(tabla, |
| 2888 | tabla->mbhc_cfg.headset_jack, |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 2889 | tabla->hph_status, |
| 2890 | TABLA_JACK_MASK); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 2891 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x00); |
| 2892 | 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] | 2893 | /* reset retry counter as PA is turned off signifying |
| 2894 | * start of new OCP detection session |
| 2895 | */ |
| 2896 | if (TABLA_IRQ_HPH_PA_OCPL_FAULT) |
| 2897 | tabla->hphlocp_cnt = 0; |
| 2898 | else |
| 2899 | tabla->hphrocp_cnt = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 2900 | wcd9xxx_enable_irq(codec->control_data, irq); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 2901 | } |
| 2902 | } |
| 2903 | |
| 2904 | static void hphlocp_off_report(struct work_struct *work) |
| 2905 | { |
| 2906 | struct tabla_priv *tabla = container_of(work, struct tabla_priv, |
| 2907 | hphlocp_work); |
| 2908 | hphocp_off_report(tabla, SND_JACK_OC_HPHL, TABLA_IRQ_HPH_PA_OCPL_FAULT); |
| 2909 | } |
| 2910 | |
| 2911 | static void hphrocp_off_report(struct work_struct *work) |
| 2912 | { |
| 2913 | struct tabla_priv *tabla = container_of(work, struct tabla_priv, |
| 2914 | hphrocp_work); |
| 2915 | hphocp_off_report(tabla, SND_JACK_OC_HPHR, TABLA_IRQ_HPH_PA_OCPR_FAULT); |
| 2916 | } |
| 2917 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 2918 | static int tabla_hph_pa_event(struct snd_soc_dapm_widget *w, |
| 2919 | struct snd_kcontrol *kcontrol, int event) |
| 2920 | { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2921 | struct snd_soc_codec *codec = w->codec; |
| 2922 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2923 | u8 mbhc_micb_ctl_val; |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 2924 | pr_debug("%s: event = %d\n", __func__, event); |
| 2925 | |
| 2926 | switch (event) { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2927 | case SND_SOC_DAPM_PRE_PMU: |
| 2928 | mbhc_micb_ctl_val = snd_soc_read(codec, |
| 2929 | tabla->mbhc_bias_regs.ctl_reg); |
| 2930 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2931 | if (!(mbhc_micb_ctl_val & 0x80)) { |
| 2932 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2933 | tabla_codec_switch_micbias(codec, 1); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2934 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 2935 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2936 | break; |
| 2937 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 2938 | case SND_SOC_DAPM_POST_PMD: |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 2939 | /* schedule work is required because at the time HPH PA DAPM |
| 2940 | * event callback is called by DAPM framework, CODEC dapm mutex |
| 2941 | * would have been locked while snd_soc_jack_report also |
| 2942 | * attempts to acquire same lock. |
| 2943 | */ |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 2944 | if (w->shift == 5) { |
| 2945 | clear_bit(TABLA_HPHL_PA_OFF_ACK, |
| 2946 | &tabla->hph_pa_dac_state); |
| 2947 | clear_bit(TABLA_HPHL_DAC_OFF_ACK, |
| 2948 | &tabla->hph_pa_dac_state); |
| 2949 | if (tabla->hph_status & SND_JACK_OC_HPHL) |
| 2950 | schedule_work(&tabla->hphlocp_work); |
| 2951 | } else if (w->shift == 4) { |
| 2952 | clear_bit(TABLA_HPHR_PA_OFF_ACK, |
| 2953 | &tabla->hph_pa_dac_state); |
| 2954 | clear_bit(TABLA_HPHR_DAC_OFF_ACK, |
| 2955 | &tabla->hph_pa_dac_state); |
| 2956 | if (tabla->hph_status & SND_JACK_OC_HPHR) |
| 2957 | schedule_work(&tabla->hphrocp_work); |
| 2958 | } |
| 2959 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2960 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2961 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2962 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2963 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 2964 | pr_debug("%s: sleep 10 ms after %s PA disable.\n", __func__, |
| 2965 | w->name); |
| 2966 | usleep_range(10000, 10000); |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 2967 | break; |
| 2968 | } |
| 2969 | return 0; |
| 2970 | } |
| 2971 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2972 | static void tabla_get_mbhc_micbias_regs(struct snd_soc_codec *codec, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 2973 | struct mbhc_micbias_regs *micbias_regs) |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2974 | { |
| 2975 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2976 | unsigned int cfilt; |
| 2977 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2978 | switch (tabla->mbhc_cfg.micbias) { |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2979 | case TABLA_MICBIAS1: |
| 2980 | cfilt = tabla->pdata->micbias.bias1_cfilt_sel; |
| 2981 | micbias_regs->mbhc_reg = TABLA_A_MICB_1_MBHC; |
| 2982 | micbias_regs->int_rbias = TABLA_A_MICB_1_INT_RBIAS; |
| 2983 | micbias_regs->ctl_reg = TABLA_A_MICB_1_CTL; |
| 2984 | break; |
| 2985 | case TABLA_MICBIAS2: |
| 2986 | cfilt = tabla->pdata->micbias.bias2_cfilt_sel; |
| 2987 | micbias_regs->mbhc_reg = TABLA_A_MICB_2_MBHC; |
| 2988 | micbias_regs->int_rbias = TABLA_A_MICB_2_INT_RBIAS; |
| 2989 | micbias_regs->ctl_reg = TABLA_A_MICB_2_CTL; |
| 2990 | break; |
| 2991 | case TABLA_MICBIAS3: |
| 2992 | cfilt = tabla->pdata->micbias.bias3_cfilt_sel; |
| 2993 | micbias_regs->mbhc_reg = TABLA_A_MICB_3_MBHC; |
| 2994 | micbias_regs->int_rbias = TABLA_A_MICB_3_INT_RBIAS; |
| 2995 | micbias_regs->ctl_reg = TABLA_A_MICB_3_CTL; |
| 2996 | break; |
| 2997 | case TABLA_MICBIAS4: |
| 2998 | cfilt = tabla->pdata->micbias.bias4_cfilt_sel; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 2999 | micbias_regs->mbhc_reg = tabla->reg_addr.micb_4_mbhc; |
| 3000 | micbias_regs->int_rbias = tabla->reg_addr.micb_4_int_rbias; |
| 3001 | micbias_regs->ctl_reg = tabla->reg_addr.micb_4_ctl; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3002 | break; |
| 3003 | default: |
| 3004 | /* Should never reach here */ |
| 3005 | pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__); |
Jordan Crouse | 239d841 | 2011-11-23 11:47:02 -0700 | [diff] [blame] | 3006 | return; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3007 | } |
| 3008 | |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 3009 | micbias_regs->cfilt_sel = cfilt; |
| 3010 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3011 | switch (cfilt) { |
| 3012 | case TABLA_CFILT1_SEL: |
| 3013 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_1_VAL; |
| 3014 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_1_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3015 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt1_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3016 | break; |
| 3017 | case TABLA_CFILT2_SEL: |
| 3018 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_2_VAL; |
| 3019 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_2_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3020 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt2_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3021 | break; |
| 3022 | case TABLA_CFILT3_SEL: |
| 3023 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_3_VAL; |
| 3024 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_3_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3025 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt3_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3026 | break; |
| 3027 | } |
| 3028 | } |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3029 | static const struct snd_soc_dapm_widget tabla_dapm_i2s_widgets[] = { |
| 3030 | SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", TABLA_A_CDC_CLK_RX_I2S_CTL, |
| 3031 | 4, 0, NULL, 0), |
| 3032 | SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", TABLA_A_CDC_CLK_TX_I2S_CTL, 4, |
| 3033 | 0, NULL, 0), |
| 3034 | }; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3035 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3036 | static int tabla_lineout_dac_event(struct snd_soc_dapm_widget *w, |
| 3037 | struct snd_kcontrol *kcontrol, int event) |
| 3038 | { |
| 3039 | struct snd_soc_codec *codec = w->codec; |
| 3040 | |
| 3041 | pr_debug("%s %s %d\n", __func__, w->name, event); |
| 3042 | |
| 3043 | switch (event) { |
| 3044 | case SND_SOC_DAPM_PRE_PMU: |
| 3045 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 3046 | break; |
| 3047 | |
| 3048 | case SND_SOC_DAPM_POST_PMD: |
| 3049 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 3050 | break; |
| 3051 | } |
| 3052 | return 0; |
| 3053 | } |
| 3054 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3055 | static const struct snd_soc_dapm_widget tabla_1_x_dapm_widgets[] = { |
| 3056 | 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] | 3057 | 0, tabla_codec_enable_micbias, |
| 3058 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3059 | SND_SOC_DAPM_POST_PMD), |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3060 | }; |
| 3061 | |
| 3062 | static const struct snd_soc_dapm_widget tabla_2_higher_dapm_widgets[] = { |
| 3063 | 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] | 3064 | 0, tabla_codec_enable_micbias, |
| 3065 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3066 | SND_SOC_DAPM_POST_PMD), |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3067 | }; |
| 3068 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3069 | static const struct snd_soc_dapm_route audio_i2s_map[] = { |
| 3070 | {"RX_I2S_CLK", NULL, "CDC_CONN"}, |
| 3071 | {"SLIM RX1", NULL, "RX_I2S_CLK"}, |
| 3072 | {"SLIM RX2", NULL, "RX_I2S_CLK"}, |
| 3073 | {"SLIM RX3", NULL, "RX_I2S_CLK"}, |
| 3074 | {"SLIM RX4", NULL, "RX_I2S_CLK"}, |
| 3075 | |
| 3076 | {"SLIM TX7", NULL, "TX_I2S_CLK"}, |
| 3077 | {"SLIM TX8", NULL, "TX_I2S_CLK"}, |
| 3078 | {"SLIM TX9", NULL, "TX_I2S_CLK"}, |
| 3079 | {"SLIM TX10", NULL, "TX_I2S_CLK"}, |
| 3080 | }; |
| 3081 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3082 | static const struct snd_soc_dapm_route audio_map[] = { |
| 3083 | /* SLIMBUS Connections */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3084 | |
| 3085 | {"SLIM TX1", NULL, "SLIM TX1 MUX"}, |
| 3086 | {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"}, |
| 3087 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3088 | {"SLIM TX2", NULL, "SLIM TX2 MUX"}, |
| 3089 | {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"}, |
| 3090 | |
| 3091 | {"SLIM TX3", NULL, "SLIM TX3 MUX"}, |
| 3092 | {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"}, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3093 | {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"}, |
| 3094 | {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"}, |
| 3095 | {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"}, |
| 3096 | {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"}, |
| 3097 | {"SLIM TX3 MUX", "RMIX5", "RX5 MIX1"}, |
| 3098 | {"SLIM TX3 MUX", "RMIX6", "RX6 MIX1"}, |
| 3099 | {"SLIM TX3 MUX", "RMIX7", "RX7 MIX1"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3100 | |
| 3101 | {"SLIM TX4", NULL, "SLIM TX4 MUX"}, |
| 3102 | {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"}, |
| 3103 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3104 | {"SLIM TX5", NULL, "SLIM TX5 MUX"}, |
| 3105 | {"SLIM TX5 MUX", "DEC5", "DEC5 MUX"}, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3106 | {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"}, |
| 3107 | {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"}, |
| 3108 | {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"}, |
| 3109 | {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"}, |
| 3110 | {"SLIM TX5 MUX", "RMIX5", "RX5 MIX1"}, |
| 3111 | {"SLIM TX5 MUX", "RMIX6", "RX6 MIX1"}, |
| 3112 | {"SLIM TX5 MUX", "RMIX7", "RX7 MIX1"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3113 | |
| 3114 | {"SLIM TX6", NULL, "SLIM TX6 MUX"}, |
| 3115 | {"SLIM TX6 MUX", "DEC6", "DEC6 MUX"}, |
| 3116 | |
| 3117 | {"SLIM TX7", NULL, "SLIM TX7 MUX"}, |
| 3118 | {"SLIM TX7 MUX", "DEC1", "DEC1 MUX"}, |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 3119 | {"SLIM TX7 MUX", "DEC2", "DEC2 MUX"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3120 | {"SLIM TX7 MUX", "DEC3", "DEC3 MUX"}, |
| 3121 | {"SLIM TX7 MUX", "DEC4", "DEC4 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3122 | {"SLIM TX7 MUX", "DEC5", "DEC5 MUX"}, |
| 3123 | {"SLIM TX7 MUX", "DEC6", "DEC6 MUX"}, |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 3124 | {"SLIM TX7 MUX", "DEC7", "DEC7 MUX"}, |
| 3125 | {"SLIM TX7 MUX", "DEC8", "DEC8 MUX"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3126 | {"SLIM TX7 MUX", "DEC9", "DEC9 MUX"}, |
| 3127 | {"SLIM TX7 MUX", "DEC10", "DEC10 MUX"}, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3128 | {"SLIM TX7 MUX", "RMIX1", "RX1 MIX1"}, |
| 3129 | {"SLIM TX7 MUX", "RMIX2", "RX2 MIX1"}, |
| 3130 | {"SLIM TX7 MUX", "RMIX3", "RX3 MIX1"}, |
| 3131 | {"SLIM TX7 MUX", "RMIX4", "RX4 MIX1"}, |
| 3132 | {"SLIM TX7 MUX", "RMIX5", "RX5 MIX1"}, |
| 3133 | {"SLIM TX7 MUX", "RMIX6", "RX6 MIX1"}, |
| 3134 | {"SLIM TX7 MUX", "RMIX7", "RX7 MIX1"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3135 | |
| 3136 | {"SLIM TX8", NULL, "SLIM TX8 MUX"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3137 | {"SLIM TX8 MUX", "DEC1", "DEC1 MUX"}, |
| 3138 | {"SLIM TX8 MUX", "DEC2", "DEC2 MUX"}, |
| 3139 | {"SLIM TX8 MUX", "DEC3", "DEC3 MUX"}, |
Bhalchandra Gajare | 9ec83cd | 2011-09-23 17:25:07 -0700 | [diff] [blame] | 3140 | {"SLIM TX8 MUX", "DEC4", "DEC4 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3141 | {"SLIM TX8 MUX", "DEC5", "DEC5 MUX"}, |
| 3142 | {"SLIM TX8 MUX", "DEC6", "DEC6 MUX"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3143 | {"SLIM TX8 MUX", "DEC7", "DEC7 MUX"}, |
| 3144 | {"SLIM TX8 MUX", "DEC8", "DEC8 MUX"}, |
| 3145 | {"SLIM TX8 MUX", "DEC9", "DEC9 MUX"}, |
| 3146 | {"SLIM TX8 MUX", "DEC10", "DEC10 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3147 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 3148 | {"SLIM TX9", NULL, "SLIM TX9 MUX"}, |
| 3149 | {"SLIM TX9 MUX", "DEC1", "DEC1 MUX"}, |
| 3150 | {"SLIM TX9 MUX", "DEC2", "DEC2 MUX"}, |
| 3151 | {"SLIM TX9 MUX", "DEC3", "DEC3 MUX"}, |
| 3152 | {"SLIM TX9 MUX", "DEC4", "DEC4 MUX"}, |
| 3153 | {"SLIM TX9 MUX", "DEC5", "DEC5 MUX"}, |
| 3154 | {"SLIM TX9 MUX", "DEC6", "DEC6 MUX"}, |
| 3155 | {"SLIM TX9 MUX", "DEC7", "DEC7 MUX"}, |
| 3156 | {"SLIM TX9 MUX", "DEC8", "DEC8 MUX"}, |
| 3157 | {"SLIM TX9 MUX", "DEC9", "DEC9 MUX"}, |
| 3158 | {"SLIM TX9 MUX", "DEC10", "DEC10 MUX"}, |
| 3159 | |
| 3160 | {"SLIM TX10", NULL, "SLIM TX10 MUX"}, |
| 3161 | {"SLIM TX10 MUX", "DEC1", "DEC1 MUX"}, |
| 3162 | {"SLIM TX10 MUX", "DEC2", "DEC2 MUX"}, |
| 3163 | {"SLIM TX10 MUX", "DEC3", "DEC3 MUX"}, |
| 3164 | {"SLIM TX10 MUX", "DEC4", "DEC4 MUX"}, |
| 3165 | {"SLIM TX10 MUX", "DEC5", "DEC5 MUX"}, |
| 3166 | {"SLIM TX10 MUX", "DEC6", "DEC6 MUX"}, |
| 3167 | {"SLIM TX10 MUX", "DEC7", "DEC7 MUX"}, |
| 3168 | {"SLIM TX10 MUX", "DEC8", "DEC8 MUX"}, |
| 3169 | {"SLIM TX10 MUX", "DEC9", "DEC9 MUX"}, |
| 3170 | {"SLIM TX10 MUX", "DEC10", "DEC10 MUX"}, |
| 3171 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3172 | /* Earpiece (RX MIX1) */ |
| 3173 | {"EAR", NULL, "EAR PA"}, |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3174 | {"EAR PA", NULL, "EAR_PA_MIXER"}, |
| 3175 | {"EAR_PA_MIXER", NULL, "DAC1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3176 | {"DAC1", NULL, "CP"}, |
| 3177 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3178 | {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"}, |
| 3179 | {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3180 | {"ANC", NULL, "ANC1 FB MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3181 | |
| 3182 | /* Headset (RX MIX1 and RX MIX2) */ |
| 3183 | {"HEADPHONE", NULL, "HPHL"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3184 | {"HEADPHONE", NULL, "HPHR"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3185 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3186 | {"HPHL", NULL, "HPHL_PA_MIXER"}, |
| 3187 | {"HPHL_PA_MIXER", NULL, "HPHL DAC"}, |
| 3188 | |
| 3189 | {"HPHR", NULL, "HPHR_PA_MIXER"}, |
| 3190 | {"HPHR_PA_MIXER", NULL, "HPHR DAC"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3191 | |
| 3192 | {"HPHL DAC", NULL, "CP"}, |
| 3193 | {"HPHR DAC", NULL, "CP"}, |
| 3194 | |
| 3195 | {"ANC", NULL, "ANC1 MUX"}, |
| 3196 | {"ANC", NULL, "ANC2 MUX"}, |
| 3197 | {"ANC1 MUX", "ADC1", "ADC1"}, |
| 3198 | {"ANC1 MUX", "ADC2", "ADC2"}, |
| 3199 | {"ANC1 MUX", "ADC3", "ADC3"}, |
| 3200 | {"ANC1 MUX", "ADC4", "ADC4"}, |
| 3201 | {"ANC2 MUX", "ADC1", "ADC1"}, |
| 3202 | {"ANC2 MUX", "ADC2", "ADC2"}, |
| 3203 | {"ANC2 MUX", "ADC3", "ADC3"}, |
| 3204 | {"ANC2 MUX", "ADC4", "ADC4"}, |
| 3205 | |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3206 | {"ANC", NULL, "CDC_CONN"}, |
| 3207 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3208 | {"DAC1", "Switch", "RX1 CHAIN"}, |
| 3209 | {"HPHL DAC", "Switch", "RX1 CHAIN"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3210 | {"HPHR DAC", NULL, "RX2 CHAIN"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3211 | |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 3212 | {"LINEOUT1", NULL, "LINEOUT1 PA"}, |
| 3213 | {"LINEOUT2", NULL, "LINEOUT2 PA"}, |
| 3214 | {"LINEOUT3", NULL, "LINEOUT3 PA"}, |
| 3215 | {"LINEOUT4", NULL, "LINEOUT4 PA"}, |
| 3216 | {"LINEOUT5", NULL, "LINEOUT5 PA"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3217 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3218 | {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"}, |
| 3219 | {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"}, |
| 3220 | {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"}, |
| 3221 | {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"}, |
| 3222 | {"LINEOUT3 PA", NULL, "LINEOUT3_PA_MIXER"}, |
| 3223 | {"LINEOUT3_PA_MIXER", NULL, "LINEOUT3 DAC"}, |
| 3224 | {"LINEOUT4 PA", NULL, "LINEOUT4_PA_MIXER"}, |
| 3225 | {"LINEOUT4_PA_MIXER", NULL, "LINEOUT4 DAC"}, |
| 3226 | {"LINEOUT5 PA", NULL, "LINEOUT5_PA_MIXER"}, |
| 3227 | {"LINEOUT5_PA_MIXER", NULL, "LINEOUT5 DAC"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3228 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3229 | {"LINEOUT1 DAC", NULL, "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3230 | {"LINEOUT5 DAC", NULL, "RX7 MIX1"}, |
| 3231 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3232 | {"RX1 CHAIN", NULL, "RX1 MIX2"}, |
| 3233 | {"RX2 CHAIN", NULL, "RX2 MIX2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3234 | {"RX1 CHAIN", NULL, "ANC"}, |
| 3235 | {"RX2 CHAIN", NULL, "ANC"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3236 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3237 | {"CP", NULL, "RX_BIAS"}, |
| 3238 | {"LINEOUT1 DAC", NULL, "RX_BIAS"}, |
| 3239 | {"LINEOUT2 DAC", NULL, "RX_BIAS"}, |
| 3240 | {"LINEOUT3 DAC", NULL, "RX_BIAS"}, |
| 3241 | {"LINEOUT4 DAC", NULL, "RX_BIAS"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3242 | {"LINEOUT5 DAC", NULL, "RX_BIAS"}, |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3243 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 3244 | {"RX1 MIX1", NULL, "COMP1_CLK"}, |
| 3245 | {"RX2 MIX1", NULL, "COMP1_CLK"}, |
| 3246 | {"RX3 MIX1", NULL, "COMP2_CLK"}, |
| 3247 | {"RX5 MIX1", NULL, "COMP2_CLK"}, |
| 3248 | |
| 3249 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3250 | {"RX1 MIX1", NULL, "RX1 MIX1 INP1"}, |
| 3251 | {"RX1 MIX1", NULL, "RX1 MIX1 INP2"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3252 | {"RX1 MIX1", NULL, "RX1 MIX1 INP3"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3253 | {"RX2 MIX1", NULL, "RX2 MIX1 INP1"}, |
| 3254 | {"RX2 MIX1", NULL, "RX2 MIX1 INP2"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3255 | {"RX3 MIX1", NULL, "RX3 MIX1 INP1"}, |
| 3256 | {"RX3 MIX1", NULL, "RX3 MIX1 INP2"}, |
| 3257 | {"RX4 MIX1", NULL, "RX4 MIX1 INP1"}, |
| 3258 | {"RX4 MIX1", NULL, "RX4 MIX1 INP2"}, |
| 3259 | {"RX5 MIX1", NULL, "RX5 MIX1 INP1"}, |
| 3260 | {"RX5 MIX1", NULL, "RX5 MIX1 INP2"}, |
| 3261 | {"RX6 MIX1", NULL, "RX6 MIX1 INP1"}, |
| 3262 | {"RX6 MIX1", NULL, "RX6 MIX1 INP2"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 3263 | {"RX7 MIX1", NULL, "RX7 MIX1 INP1"}, |
| 3264 | {"RX7 MIX1", NULL, "RX7 MIX1 INP2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3265 | {"RX1 MIX2", NULL, "RX1 MIX1"}, |
| 3266 | {"RX1 MIX2", NULL, "RX1 MIX2 INP1"}, |
| 3267 | {"RX1 MIX2", NULL, "RX1 MIX2 INP2"}, |
| 3268 | {"RX2 MIX2", NULL, "RX2 MIX1"}, |
| 3269 | {"RX2 MIX2", NULL, "RX2 MIX2 INP1"}, |
| 3270 | {"RX2 MIX2", NULL, "RX2 MIX2 INP2"}, |
| 3271 | {"RX3 MIX2", NULL, "RX3 MIX1"}, |
| 3272 | {"RX3 MIX2", NULL, "RX3 MIX2 INP1"}, |
| 3273 | {"RX3 MIX2", NULL, "RX3 MIX2 INP2"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3274 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3275 | {"RX1 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3276 | {"RX1 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3277 | {"RX1 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3278 | {"RX1 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3279 | {"RX1 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3280 | {"RX1 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3281 | {"RX1 MIX1 INP1", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3282 | {"RX1 MIX1 INP1", "IIR1", "IIR1"}, |
| 3283 | {"RX1 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3284 | {"RX1 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3285 | {"RX1 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3286 | {"RX1 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3287 | {"RX1 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3288 | {"RX1 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3289 | {"RX1 MIX1 INP2", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3290 | {"RX1 MIX1 INP2", "IIR1", "IIR1"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3291 | {"RX1 MIX1 INP3", "RX1", "SLIM RX1"}, |
| 3292 | {"RX1 MIX1 INP3", "RX2", "SLIM RX2"}, |
| 3293 | {"RX1 MIX1 INP3", "RX3", "SLIM RX3"}, |
| 3294 | {"RX1 MIX1 INP3", "RX4", "SLIM RX4"}, |
| 3295 | {"RX1 MIX1 INP3", "RX5", "SLIM RX5"}, |
| 3296 | {"RX1 MIX1 INP3", "RX6", "SLIM RX6"}, |
| 3297 | {"RX1 MIX1 INP3", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3298 | {"RX2 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3299 | {"RX2 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3300 | {"RX2 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3301 | {"RX2 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3302 | {"RX2 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3303 | {"RX2 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3304 | {"RX2 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3305 | {"RX2 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3306 | {"RX2 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3307 | {"RX2 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3308 | {"RX2 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3309 | {"RX2 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3310 | {"RX2 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3311 | {"RX2 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3312 | {"RX2 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3313 | {"RX2 MIX1 INP2", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3314 | {"RX3 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3315 | {"RX3 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3316 | {"RX3 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3317 | {"RX3 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3318 | {"RX3 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3319 | {"RX3 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3320 | {"RX3 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3321 | {"RX3 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3322 | {"RX3 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3323 | {"RX3 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3324 | {"RX3 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3325 | {"RX3 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3326 | {"RX3 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3327 | {"RX3 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3328 | {"RX3 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3329 | {"RX3 MIX1 INP2", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3330 | {"RX4 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3331 | {"RX4 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3332 | {"RX4 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3333 | {"RX4 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3334 | {"RX4 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3335 | {"RX4 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3336 | {"RX4 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3337 | {"RX4 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3338 | {"RX4 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3339 | {"RX4 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3340 | {"RX4 MIX1 INP2", "RX3", "SLIM RX3"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3341 | {"RX4 MIX1 INP2", "RX5", "SLIM RX5"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3342 | {"RX4 MIX1 INP2", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3343 | {"RX4 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3344 | {"RX4 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3345 | {"RX4 MIX1 INP2", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3346 | {"RX5 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3347 | {"RX5 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3348 | {"RX5 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3349 | {"RX5 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3350 | {"RX5 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3351 | {"RX5 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3352 | {"RX5 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3353 | {"RX5 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3354 | {"RX5 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3355 | {"RX5 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3356 | {"RX5 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3357 | {"RX5 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3358 | {"RX5 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3359 | {"RX5 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3360 | {"RX5 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3361 | {"RX5 MIX1 INP2", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3362 | {"RX6 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3363 | {"RX6 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3364 | {"RX6 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3365 | {"RX6 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3366 | {"RX6 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3367 | {"RX6 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3368 | {"RX6 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3369 | {"RX6 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3370 | {"RX6 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3371 | {"RX6 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3372 | {"RX6 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3373 | {"RX6 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3374 | {"RX6 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3375 | {"RX6 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3376 | {"RX6 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3377 | {"RX6 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 3378 | {"RX7 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3379 | {"RX7 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3380 | {"RX7 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3381 | {"RX7 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3382 | {"RX7 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3383 | {"RX7 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3384 | {"RX7 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3385 | {"RX7 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 3386 | {"RX7 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3387 | {"RX7 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3388 | {"RX7 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3389 | {"RX7 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3390 | {"RX7 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3391 | {"RX7 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3392 | {"RX7 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3393 | {"RX7 MIX1 INP2", "IIR1", "IIR1"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3394 | {"RX1 MIX2 INP1", "IIR1", "IIR1"}, |
| 3395 | {"RX1 MIX2 INP2", "IIR1", "IIR1"}, |
| 3396 | {"RX2 MIX2 INP1", "IIR1", "IIR1"}, |
| 3397 | {"RX2 MIX2 INP2", "IIR1", "IIR1"}, |
| 3398 | {"RX3 MIX2 INP1", "IIR1", "IIR1"}, |
| 3399 | {"RX3 MIX2 INP2", "IIR1", "IIR1"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3400 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3401 | /* Decimator Inputs */ |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3402 | {"DEC1 MUX", "DMIC1", "DMIC1"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3403 | {"DEC1 MUX", "ADC6", "ADC6"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3404 | {"DEC1 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3405 | {"DEC2 MUX", "DMIC2", "DMIC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3406 | {"DEC2 MUX", "ADC5", "ADC5"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3407 | {"DEC2 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3408 | {"DEC3 MUX", "DMIC3", "DMIC3"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3409 | {"DEC3 MUX", "ADC4", "ADC4"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3410 | {"DEC3 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 3411 | {"DEC4 MUX", "DMIC4", "DMIC4"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3412 | {"DEC4 MUX", "ADC3", "ADC3"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3413 | {"DEC4 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 3414 | {"DEC5 MUX", "DMIC5", "DMIC5"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3415 | {"DEC5 MUX", "ADC2", "ADC2"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3416 | {"DEC5 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 3417 | {"DEC6 MUX", "DMIC6", "DMIC6"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3418 | {"DEC6 MUX", "ADC1", "ADC1"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3419 | {"DEC6 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3420 | {"DEC7 MUX", "DMIC1", "DMIC1"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3421 | {"DEC7 MUX", "DMIC6", "DMIC6"}, |
| 3422 | {"DEC7 MUX", "ADC1", "ADC1"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3423 | {"DEC7 MUX", "ADC6", "ADC6"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3424 | {"DEC7 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3425 | {"DEC8 MUX", "DMIC2", "DMIC2"}, |
| 3426 | {"DEC8 MUX", "DMIC5", "DMIC5"}, |
| 3427 | {"DEC8 MUX", "ADC2", "ADC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3428 | {"DEC8 MUX", "ADC5", "ADC5"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3429 | {"DEC8 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3430 | {"DEC9 MUX", "DMIC4", "DMIC4"}, |
| 3431 | {"DEC9 MUX", "DMIC5", "DMIC5"}, |
| 3432 | {"DEC9 MUX", "ADC2", "ADC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3433 | {"DEC9 MUX", "ADC3", "ADC3"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3434 | {"DEC9 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3435 | {"DEC10 MUX", "DMIC3", "DMIC3"}, |
| 3436 | {"DEC10 MUX", "DMIC6", "DMIC6"}, |
| 3437 | {"DEC10 MUX", "ADC1", "ADC1"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3438 | {"DEC10 MUX", "ADC4", "ADC4"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3439 | {"DEC10 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3440 | |
| 3441 | /* ADC Connections */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3442 | {"ADC1", NULL, "AMIC1"}, |
| 3443 | {"ADC2", NULL, "AMIC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3444 | {"ADC3", NULL, "AMIC3"}, |
| 3445 | {"ADC4", NULL, "AMIC4"}, |
| 3446 | {"ADC5", NULL, "AMIC5"}, |
| 3447 | {"ADC6", NULL, "AMIC6"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3448 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3449 | /* AUX PGA Connections */ |
| 3450 | {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3451 | {"HPHL_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3452 | {"HPHL_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3453 | {"HPHL_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3454 | {"HPHR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3455 | {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3456 | {"HPHR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3457 | {"HPHR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3458 | {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3459 | {"LINEOUT1_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3460 | {"LINEOUT1_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3461 | {"LINEOUT1_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3462 | {"LINEOUT2_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3463 | {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3464 | {"LINEOUT2_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3465 | {"LINEOUT2_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3466 | {"LINEOUT3_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3467 | {"LINEOUT3_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3468 | {"LINEOUT3_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3469 | {"LINEOUT3_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3470 | {"LINEOUT4_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3471 | {"LINEOUT4_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3472 | {"LINEOUT4_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3473 | {"LINEOUT4_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3474 | {"LINEOUT5_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3475 | {"LINEOUT5_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3476 | {"LINEOUT5_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3477 | {"LINEOUT5_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3478 | {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3479 | {"EAR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3480 | {"EAR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3481 | {"EAR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3482 | {"AUX_PGA_Left", NULL, "AMIC5"}, |
| 3483 | {"AUX_PGA_Right", NULL, "AMIC6"}, |
| 3484 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3485 | {"IIR1", NULL, "IIR1 INP1 MUX"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3486 | {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"}, |
| 3487 | {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"}, |
| 3488 | {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"}, |
| 3489 | {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"}, |
| 3490 | {"IIR1 INP1 MUX", "DEC5", "DEC5 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3491 | {"IIR1 INP1 MUX", "DEC6", "DEC6 MUX"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3492 | {"IIR1 INP1 MUX", "DEC7", "DEC7 MUX"}, |
| 3493 | {"IIR1 INP1 MUX", "DEC8", "DEC8 MUX"}, |
| 3494 | {"IIR1 INP1 MUX", "DEC9", "DEC9 MUX"}, |
| 3495 | {"IIR1 INP1 MUX", "DEC10", "DEC10 MUX"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3496 | |
| 3497 | {"MIC BIAS1 Internal1", NULL, "LDO_H"}, |
| 3498 | {"MIC BIAS1 Internal2", NULL, "LDO_H"}, |
| 3499 | {"MIC BIAS1 External", NULL, "LDO_H"}, |
| 3500 | {"MIC BIAS2 Internal1", NULL, "LDO_H"}, |
| 3501 | {"MIC BIAS2 Internal2", NULL, "LDO_H"}, |
| 3502 | {"MIC BIAS2 Internal3", NULL, "LDO_H"}, |
| 3503 | {"MIC BIAS2 External", NULL, "LDO_H"}, |
| 3504 | {"MIC BIAS3 Internal1", NULL, "LDO_H"}, |
| 3505 | {"MIC BIAS3 Internal2", NULL, "LDO_H"}, |
| 3506 | {"MIC BIAS3 External", NULL, "LDO_H"}, |
| 3507 | {"MIC BIAS4 External", NULL, "LDO_H"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3508 | }; |
| 3509 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3510 | static const struct snd_soc_dapm_route tabla_1_x_lineout_2_to_4_map[] = { |
| 3511 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3512 | {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3513 | {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"}, |
| 3514 | |
| 3515 | {"LINEOUT2 DAC", NULL, "RX4 DSM MUX"}, |
| 3516 | |
| 3517 | {"LINEOUT3 DAC", NULL, "RX5 MIX1"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3518 | {"LINEOUT3 DAC GROUND", "Switch", "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3519 | {"LINEOUT3 DAC", NULL, "LINEOUT3 DAC GROUND"}, |
| 3520 | |
| 3521 | {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"}, |
| 3522 | {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"}, |
| 3523 | |
| 3524 | {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"}, |
| 3525 | {"LINEOUT4 DAC GROUND", "Switch", "RX4 DSM MUX"}, |
| 3526 | {"LINEOUT4 DAC", NULL, "LINEOUT4 DAC GROUND"}, |
| 3527 | }; |
| 3528 | |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 3529 | |
| 3530 | static const struct snd_soc_dapm_route tabla_2_x_lineout_2_to_4_map[] = { |
| 3531 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3532 | {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"}, |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 3533 | {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"}, |
| 3534 | |
| 3535 | {"LINEOUT3 DAC", NULL, "RX4 DSM MUX"}, |
| 3536 | |
| 3537 | {"LINEOUT2 DAC", NULL, "RX5 MIX1"}, |
| 3538 | |
| 3539 | {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"}, |
| 3540 | {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"}, |
| 3541 | |
| 3542 | {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"}, |
| 3543 | }; |
| 3544 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3545 | static int tabla_readable(struct snd_soc_codec *ssc, unsigned int reg) |
| 3546 | { |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3547 | int i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3548 | struct wcd9xxx *tabla_core = dev_get_drvdata(ssc->dev->parent); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3549 | |
| 3550 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 3551 | for (i = 0; i < ARRAY_SIZE(tabla_1_reg_readable); i++) { |
| 3552 | if (tabla_1_reg_readable[i] == reg) |
| 3553 | return 1; |
| 3554 | } |
| 3555 | } else { |
| 3556 | for (i = 0; i < ARRAY_SIZE(tabla_2_reg_readable); i++) { |
| 3557 | if (tabla_2_reg_readable[i] == reg) |
| 3558 | return 1; |
| 3559 | } |
| 3560 | } |
| 3561 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3562 | return tabla_reg_readable[reg]; |
| 3563 | } |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3564 | static bool tabla_is_digital_gain_register(unsigned int reg) |
| 3565 | { |
| 3566 | bool rtn = false; |
| 3567 | switch (reg) { |
| 3568 | case TABLA_A_CDC_RX1_VOL_CTL_B2_CTL: |
| 3569 | case TABLA_A_CDC_RX2_VOL_CTL_B2_CTL: |
| 3570 | case TABLA_A_CDC_RX3_VOL_CTL_B2_CTL: |
| 3571 | case TABLA_A_CDC_RX4_VOL_CTL_B2_CTL: |
| 3572 | case TABLA_A_CDC_RX5_VOL_CTL_B2_CTL: |
| 3573 | case TABLA_A_CDC_RX6_VOL_CTL_B2_CTL: |
| 3574 | case TABLA_A_CDC_RX7_VOL_CTL_B2_CTL: |
| 3575 | case TABLA_A_CDC_TX1_VOL_CTL_GAIN: |
| 3576 | case TABLA_A_CDC_TX2_VOL_CTL_GAIN: |
| 3577 | case TABLA_A_CDC_TX3_VOL_CTL_GAIN: |
| 3578 | case TABLA_A_CDC_TX4_VOL_CTL_GAIN: |
| 3579 | case TABLA_A_CDC_TX5_VOL_CTL_GAIN: |
| 3580 | case TABLA_A_CDC_TX6_VOL_CTL_GAIN: |
| 3581 | case TABLA_A_CDC_TX7_VOL_CTL_GAIN: |
| 3582 | case TABLA_A_CDC_TX8_VOL_CTL_GAIN: |
| 3583 | case TABLA_A_CDC_TX9_VOL_CTL_GAIN: |
| 3584 | case TABLA_A_CDC_TX10_VOL_CTL_GAIN: |
| 3585 | rtn = true; |
| 3586 | break; |
| 3587 | default: |
| 3588 | break; |
| 3589 | } |
| 3590 | return rtn; |
| 3591 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3592 | static int tabla_volatile(struct snd_soc_codec *ssc, unsigned int reg) |
| 3593 | { |
| 3594 | /* Registers lower than 0x100 are top level registers which can be |
| 3595 | * written by the Tabla core driver. |
| 3596 | */ |
| 3597 | |
| 3598 | if ((reg >= TABLA_A_CDC_MBHC_EN_CTL) || (reg < 0x100)) |
| 3599 | return 1; |
| 3600 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 3601 | /* IIR Coeff registers are not cacheable */ |
| 3602 | if ((reg >= TABLA_A_CDC_IIR1_COEF_B1_CTL) && |
| 3603 | (reg <= TABLA_A_CDC_IIR2_COEF_B5_CTL)) |
| 3604 | return 1; |
| 3605 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3606 | /* Digital gain register is not cacheable so we have to write |
| 3607 | * the setting even it is the same |
| 3608 | */ |
| 3609 | if (tabla_is_digital_gain_register(reg)) |
| 3610 | return 1; |
| 3611 | |
Joonwoo Park | ab2c587 | 2012-05-03 15:16:02 -0700 | [diff] [blame] | 3612 | /* HPH status registers */ |
| 3613 | if (reg == TABLA_A_RX_HPH_L_STATUS || reg == TABLA_A_RX_HPH_R_STATUS) |
| 3614 | return 1; |
| 3615 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3616 | return 0; |
| 3617 | } |
| 3618 | |
| 3619 | #define TABLA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) |
| 3620 | static int tabla_write(struct snd_soc_codec *codec, unsigned int reg, |
| 3621 | unsigned int value) |
| 3622 | { |
| 3623 | int ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3624 | BUG_ON(reg > TABLA_MAX_REGISTER); |
| 3625 | |
| 3626 | if (!tabla_volatile(codec, reg)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3627 | ret = snd_soc_cache_write(codec, reg, value); |
| 3628 | if (ret != 0) |
| 3629 | dev_err(codec->dev, "Cache write to %x failed: %d\n", |
| 3630 | reg, ret); |
| 3631 | } |
| 3632 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3633 | return wcd9xxx_reg_write(codec->control_data, reg, value); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3634 | } |
| 3635 | static unsigned int tabla_read(struct snd_soc_codec *codec, |
| 3636 | unsigned int reg) |
| 3637 | { |
| 3638 | unsigned int val; |
| 3639 | int ret; |
| 3640 | |
| 3641 | BUG_ON(reg > TABLA_MAX_REGISTER); |
| 3642 | |
| 3643 | if (!tabla_volatile(codec, reg) && tabla_readable(codec, reg) && |
| 3644 | reg < codec->driver->reg_cache_size) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3645 | ret = snd_soc_cache_read(codec, reg, &val); |
| 3646 | if (ret >= 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3647 | return val; |
| 3648 | } else |
| 3649 | dev_err(codec->dev, "Cache read from %x failed: %d\n", |
| 3650 | reg, ret); |
| 3651 | } |
| 3652 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3653 | val = wcd9xxx_reg_read(codec->control_data, reg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3654 | return val; |
| 3655 | } |
| 3656 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 3657 | static s16 tabla_get_current_v_ins(struct tabla_priv *tabla, bool hu) |
| 3658 | { |
| 3659 | s16 v_ins; |
| 3660 | if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) && |
| 3661 | tabla->mbhc_micbias_switched) |
| 3662 | v_ins = hu ? (s16)tabla->mbhc_data.adj_v_ins_hu : |
| 3663 | (s16)tabla->mbhc_data.adj_v_ins_h; |
| 3664 | else |
| 3665 | v_ins = hu ? (s16)tabla->mbhc_data.v_ins_hu : |
| 3666 | (s16)tabla->mbhc_data.v_ins_h; |
| 3667 | return v_ins; |
| 3668 | } |
| 3669 | |
| 3670 | static s16 tabla_get_current_v_hs_max(struct tabla_priv *tabla) |
| 3671 | { |
| 3672 | s16 v_hs_max; |
| 3673 | struct tabla_mbhc_plug_type_cfg *plug_type; |
| 3674 | |
| 3675 | plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 3676 | if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) && |
| 3677 | tabla->mbhc_micbias_switched) |
| 3678 | v_hs_max = tabla->mbhc_data.adj_v_hs_max; |
| 3679 | else |
| 3680 | v_hs_max = plug_type->v_hs_max; |
| 3681 | return v_hs_max; |
| 3682 | } |
| 3683 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 3684 | static void tabla_codec_calibrate_hs_polling(struct snd_soc_codec *codec) |
| 3685 | { |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 3686 | u8 *n_ready, *n_cic; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3687 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 3688 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 3689 | const s16 v_ins_hu = tabla_get_current_v_ins(tabla, true); |
| 3690 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3691 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 3692 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3693 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 3694 | v_ins_hu & 0xFF); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3695 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 3696 | (v_ins_hu >> 8) & 0xFF); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 3697 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3698 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, |
| 3699 | tabla->mbhc_data.v_b1_hu & 0xFF); |
| 3700 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, |
| 3701 | (tabla->mbhc_data.v_b1_hu >> 8) & 0xFF); |
| 3702 | |
| 3703 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, |
| 3704 | tabla->mbhc_data.v_b1_h & 0xFF); |
| 3705 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, |
| 3706 | (tabla->mbhc_data.v_b1_h >> 8) & 0xFF); |
| 3707 | |
| 3708 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B9_CTL, |
| 3709 | tabla->mbhc_data.v_brh & 0xFF); |
| 3710 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B10_CTL, |
| 3711 | (tabla->mbhc_data.v_brh >> 8) & 0xFF); |
| 3712 | |
| 3713 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B11_CTL, |
| 3714 | tabla->mbhc_data.v_brl & 0xFF); |
| 3715 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B12_CTL, |
| 3716 | (tabla->mbhc_data.v_brl >> 8) & 0xFF); |
| 3717 | |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 3718 | 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] | 3719 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL, |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 3720 | n_ready[tabla_codec_mclk_index(tabla)]); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3721 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B2_CTL, |
| 3722 | tabla->mbhc_data.npoll); |
| 3723 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B3_CTL, |
| 3724 | tabla->mbhc_data.nbounce_wait); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3725 | 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] | 3726 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL, |
| 3727 | n_cic[tabla_codec_mclk_index(tabla)]); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 3728 | } |
| 3729 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3730 | static int tabla_startup(struct snd_pcm_substream *substream, |
| 3731 | struct snd_soc_dai *dai) |
| 3732 | { |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 3733 | struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3734 | pr_debug("%s(): substream = %s stream = %d\n" , __func__, |
| 3735 | substream->name, substream->stream); |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 3736 | if ((tabla_core != NULL) && |
| 3737 | (tabla_core->dev != NULL) && |
| 3738 | (tabla_core->dev->parent != NULL)) |
| 3739 | pm_runtime_get_sync(tabla_core->dev->parent); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3740 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3741 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | static void tabla_shutdown(struct snd_pcm_substream *substream, |
| 3745 | struct snd_soc_dai *dai) |
| 3746 | { |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 3747 | struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3748 | pr_debug("%s(): substream = %s stream = %d\n" , __func__, |
| 3749 | substream->name, substream->stream); |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 3750 | if ((tabla_core != NULL) && |
| 3751 | (tabla_core->dev != NULL) && |
| 3752 | (tabla_core->dev->parent != NULL)) { |
| 3753 | pm_runtime_mark_last_busy(tabla_core->dev->parent); |
| 3754 | pm_runtime_put(tabla_core->dev->parent); |
| 3755 | } |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3756 | } |
| 3757 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3758 | 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] | 3759 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3760 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 3761 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 3762 | pr_debug("%s: mclk_enable = %u, dapm = %d\n", __func__, mclk_enable, |
| 3763 | dapm); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3764 | if (dapm) |
| 3765 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3766 | if (mclk_enable) { |
| 3767 | tabla->mclk_enabled = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3768 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 3769 | if (tabla->mbhc_polling_active) { |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 3770 | tabla_codec_pause_hs_polling(codec); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 3771 | tabla_codec_disable_clock_block(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3772 | tabla_codec_enable_bandgap(codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 3773 | TABLA_BANDGAP_AUDIO_MODE); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3774 | tabla_codec_enable_clock_block(codec, 0); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 3775 | tabla_codec_calibrate_hs_polling(codec); |
| 3776 | tabla_codec_start_hs_polling(codec); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 3777 | } else { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 3778 | tabla_codec_disable_clock_block(codec); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 3779 | tabla_codec_enable_bandgap(codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 3780 | TABLA_BANDGAP_AUDIO_MODE); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 3781 | tabla_codec_enable_clock_block(codec, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3782 | } |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3783 | } else { |
| 3784 | |
| 3785 | if (!tabla->mclk_enabled) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3786 | if (dapm) |
| 3787 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3788 | pr_err("Error, MCLK already diabled\n"); |
| 3789 | return -EINVAL; |
| 3790 | } |
| 3791 | tabla->mclk_enabled = false; |
| 3792 | |
| 3793 | if (tabla->mbhc_polling_active) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 3794 | tabla_codec_pause_hs_polling(codec); |
| 3795 | tabla_codec_disable_clock_block(codec); |
| 3796 | tabla_codec_enable_bandgap(codec, |
| 3797 | TABLA_BANDGAP_MBHC_MODE); |
| 3798 | tabla_enable_rx_bias(codec, 1); |
| 3799 | tabla_codec_enable_clock_block(codec, 1); |
| 3800 | tabla_codec_calibrate_hs_polling(codec); |
| 3801 | tabla_codec_start_hs_polling(codec); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3802 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, |
| 3803 | 0x05, 0x01); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 3804 | } else { |
| 3805 | tabla_codec_disable_clock_block(codec); |
| 3806 | tabla_codec_enable_bandgap(codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 3807 | TABLA_BANDGAP_OFF); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3808 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3809 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3810 | if (dapm) |
| 3811 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3812 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3813 | } |
| 3814 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3815 | static int tabla_set_dai_sysclk(struct snd_soc_dai *dai, |
| 3816 | int clk_id, unsigned int freq, int dir) |
| 3817 | { |
| 3818 | pr_debug("%s\n", __func__); |
| 3819 | return 0; |
| 3820 | } |
| 3821 | |
| 3822 | static int tabla_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 3823 | { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3824 | u8 val = 0; |
| 3825 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
| 3826 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3827 | pr_debug("%s\n", __func__); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3828 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 3829 | case SND_SOC_DAIFMT_CBS_CFS: |
| 3830 | /* CPU is master */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3831 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3832 | if (dai->id == AIF1_CAP) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3833 | snd_soc_update_bits(dai->codec, |
| 3834 | TABLA_A_CDC_CLK_TX_I2S_CTL, |
| 3835 | TABLA_I2S_MASTER_MODE_MASK, 0); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3836 | else if (dai->id == AIF1_PB) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3837 | snd_soc_update_bits(dai->codec, |
| 3838 | TABLA_A_CDC_CLK_RX_I2S_CTL, |
| 3839 | TABLA_I2S_MASTER_MODE_MASK, 0); |
| 3840 | } |
| 3841 | break; |
| 3842 | case SND_SOC_DAIFMT_CBM_CFM: |
| 3843 | /* CPU is slave */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3844 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3845 | val = TABLA_I2S_MASTER_MODE_MASK; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3846 | if (dai->id == AIF1_CAP) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3847 | snd_soc_update_bits(dai->codec, |
| 3848 | TABLA_A_CDC_CLK_TX_I2S_CTL, val, val); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3849 | else if (dai->id == AIF1_PB) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3850 | snd_soc_update_bits(dai->codec, |
| 3851 | TABLA_A_CDC_CLK_RX_I2S_CTL, val, val); |
| 3852 | } |
| 3853 | break; |
| 3854 | default: |
| 3855 | return -EINVAL; |
| 3856 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3857 | return 0; |
| 3858 | } |
| 3859 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3860 | static int tabla_set_channel_map(struct snd_soc_dai *dai, |
| 3861 | unsigned int tx_num, unsigned int *tx_slot, |
| 3862 | unsigned int rx_num, unsigned int *rx_slot) |
| 3863 | |
| 3864 | { |
| 3865 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
| 3866 | u32 i = 0; |
| 3867 | if (!tx_slot && !rx_slot) { |
| 3868 | pr_err("%s: Invalid\n", __func__); |
| 3869 | return -EINVAL; |
| 3870 | } |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3871 | pr_debug("%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n", |
| 3872 | __func__, dai->name, dai->id, tx_num, rx_num); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3873 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3874 | if (dai->id == AIF1_PB || dai->id == AIF2_PB || dai->id == AIF3_PB) { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3875 | for (i = 0; i < rx_num; i++) { |
| 3876 | tabla->dai[dai->id - 1].ch_num[i] = rx_slot[i]; |
| 3877 | tabla->dai[dai->id - 1].ch_act = 0; |
| 3878 | tabla->dai[dai->id - 1].ch_tot = rx_num; |
| 3879 | } |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3880 | } else if (dai->id == AIF1_CAP || dai->id == AIF2_CAP || |
| 3881 | dai->id == AIF3_CAP) { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3882 | for (i = 0; i < tx_num; i++) { |
| 3883 | tabla->dai[dai->id - 1].ch_num[i] = tx_slot[i]; |
| 3884 | tabla->dai[dai->id - 1].ch_act = 0; |
| 3885 | tabla->dai[dai->id - 1].ch_tot = tx_num; |
| 3886 | } |
| 3887 | } |
| 3888 | return 0; |
| 3889 | } |
| 3890 | |
| 3891 | static int tabla_get_channel_map(struct snd_soc_dai *dai, |
| 3892 | unsigned int *tx_num, unsigned int *tx_slot, |
| 3893 | unsigned int *rx_num, unsigned int *rx_slot) |
| 3894 | |
| 3895 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3896 | struct wcd9xxx *tabla = dev_get_drvdata(dai->codec->control_data); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3897 | |
| 3898 | u32 cnt = 0; |
| 3899 | u32 tx_ch[SLIM_MAX_TX_PORTS]; |
| 3900 | u32 rx_ch[SLIM_MAX_RX_PORTS]; |
| 3901 | |
| 3902 | if (!rx_slot && !tx_slot) { |
| 3903 | pr_err("%s: Invalid\n", __func__); |
| 3904 | return -EINVAL; |
| 3905 | } |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3906 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3907 | /* for virtual port, codec driver needs to do |
| 3908 | * housekeeping, for now should be ok |
| 3909 | */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3910 | wcd9xxx_get_channel(tabla, rx_ch, tx_ch); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3911 | if (dai->id == AIF1_PB) { |
| 3912 | *rx_num = tabla_dai[dai->id - 1].playback.channels_max; |
| 3913 | while (cnt < *rx_num) { |
| 3914 | rx_slot[cnt] = rx_ch[cnt]; |
| 3915 | cnt++; |
| 3916 | } |
| 3917 | } else if (dai->id == AIF1_CAP) { |
| 3918 | *tx_num = tabla_dai[dai->id - 1].capture.channels_max; |
| 3919 | while (cnt < *tx_num) { |
| 3920 | tx_slot[cnt] = tx_ch[6 + cnt]; |
| 3921 | cnt++; |
| 3922 | } |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3923 | } else if (dai->id == AIF2_PB) { |
| 3924 | *rx_num = tabla_dai[dai->id - 1].playback.channels_max; |
| 3925 | while (cnt < *rx_num) { |
| 3926 | rx_slot[cnt] = rx_ch[5 + cnt]; |
| 3927 | cnt++; |
| 3928 | } |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3929 | } else if (dai->id == AIF2_CAP) { |
| 3930 | *tx_num = tabla_dai[dai->id - 1].capture.channels_max; |
| 3931 | tx_slot[0] = tx_ch[cnt]; |
| 3932 | tx_slot[1] = tx_ch[1 + cnt]; |
Kiran Kandi | 323d710 | 2012-04-18 19:56:14 -0700 | [diff] [blame] | 3933 | tx_slot[2] = tx_ch[5 + cnt]; |
Kiran Kandi | e408b84 | 2012-05-17 19:48:04 -0700 | [diff] [blame] | 3934 | tx_slot[3] = tx_ch[3 + cnt]; |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3935 | |
| 3936 | } else if (dai->id == AIF3_PB) { |
| 3937 | *rx_num = tabla_dai[dai->id - 1].playback.channels_max; |
| 3938 | rx_slot[0] = rx_ch[3]; |
| 3939 | rx_slot[1] = rx_ch[4]; |
| 3940 | |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3941 | } else if (dai->id == AIF3_CAP) { |
| 3942 | *tx_num = tabla_dai[dai->id - 1].capture.channels_max; |
| 3943 | tx_slot[cnt] = tx_ch[2 + cnt]; |
| 3944 | tx_slot[cnt + 1] = tx_ch[4 + cnt]; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3945 | } |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3946 | pr_debug("%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n", |
| 3947 | __func__, dai->name, dai->id, *tx_num, *rx_num); |
| 3948 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3949 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3950 | return 0; |
| 3951 | } |
| 3952 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 3953 | |
| 3954 | static struct snd_soc_dapm_widget tabla_dapm_aif_in_widgets[] = { |
| 3955 | |
| 3956 | SND_SOC_DAPM_AIF_IN_E("SLIM RX1", "AIF1 Playback", 0, SND_SOC_NOPM, 1, |
| 3957 | 0, tabla_codec_enable_slimrx, |
| 3958 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3959 | |
| 3960 | SND_SOC_DAPM_AIF_IN_E("SLIM RX2", "AIF1 Playback", 0, SND_SOC_NOPM, 2, |
| 3961 | 0, tabla_codec_enable_slimrx, |
| 3962 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3963 | |
| 3964 | SND_SOC_DAPM_AIF_IN_E("SLIM RX3", "AIF1 Playback", 0, SND_SOC_NOPM, 3, |
| 3965 | 0, tabla_codec_enable_slimrx, |
| 3966 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3967 | |
| 3968 | SND_SOC_DAPM_AIF_IN_E("SLIM RX4", "AIF3 Playback", 0, SND_SOC_NOPM, 4, |
| 3969 | 0, tabla_codec_enable_slimrx, |
| 3970 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3971 | |
| 3972 | SND_SOC_DAPM_AIF_IN_E("SLIM RX5", "AIF3 Playback", 0, SND_SOC_NOPM, 5, |
| 3973 | 0, tabla_codec_enable_slimrx, |
| 3974 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3975 | |
| 3976 | SND_SOC_DAPM_AIF_IN_E("SLIM RX6", "AIF2 Playback", 0, SND_SOC_NOPM, 6, |
| 3977 | 0, tabla_codec_enable_slimrx, |
| 3978 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3979 | |
| 3980 | SND_SOC_DAPM_AIF_IN_E("SLIM RX7", "AIF2 Playback", 0, SND_SOC_NOPM, 7, |
| 3981 | 0, tabla_codec_enable_slimrx, |
| 3982 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3983 | }; |
| 3984 | |
| 3985 | static struct snd_soc_dapm_widget tabla_dapm_aif_out_widgets[] = { |
| 3986 | |
| 3987 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX1", "AIF2 Capture", 0, SND_SOC_NOPM, 1, |
| 3988 | 0, tabla_codec_enable_slimtx, |
| 3989 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3990 | |
| 3991 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX2", "AIF2 Capture", 0, SND_SOC_NOPM, 2, |
| 3992 | 0, tabla_codec_enable_slimtx, |
| 3993 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3994 | |
| 3995 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX3", "AIF3 Capture", 0, SND_SOC_NOPM, 3, |
| 3996 | 0, tabla_codec_enable_slimtx, |
| 3997 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3998 | |
| 3999 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX4", "AIF2 Capture", 0, SND_SOC_NOPM, 4, |
| 4000 | 0, tabla_codec_enable_slimtx, |
| 4001 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4002 | |
| 4003 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX5", "AIF3 Capture", 0, SND_SOC_NOPM, 5, |
| 4004 | 0, tabla_codec_enable_slimtx, |
| 4005 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4006 | |
| 4007 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX6", "AIF2 Capture", 0, SND_SOC_NOPM, 6, |
| 4008 | 0, tabla_codec_enable_slimtx, |
| 4009 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4010 | |
| 4011 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX7", "AIF1 Capture", 0, SND_SOC_NOPM, 7, |
| 4012 | 0, tabla_codec_enable_slimtx, |
| 4013 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4014 | |
| 4015 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX8", "AIF1 Capture", 0, SND_SOC_NOPM, 8, |
| 4016 | 0, tabla_codec_enable_slimtx, |
| 4017 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4018 | |
| 4019 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX9", "AIF1 Capture", 0, SND_SOC_NOPM, 9, |
| 4020 | 0, tabla_codec_enable_slimtx, |
| 4021 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4022 | |
| 4023 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX10", "AIF1 Capture", 0, SND_SOC_NOPM, 10, |
| 4024 | 0, tabla_codec_enable_slimtx, |
| 4025 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4026 | }; |
| 4027 | |
| 4028 | static int tabla_set_interpolator_rate(struct snd_soc_dai *dai, |
| 4029 | u8 rx_fs_rate_reg_val, u32 compander_fs, u32 sample_rate) |
| 4030 | { |
| 4031 | u32 i, j; |
| 4032 | u8 rx_mix1_inp; |
| 4033 | u16 rx_mix_1_reg_1, rx_mix_1_reg_2; |
| 4034 | u16 rx_fs_reg; |
| 4035 | u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val; |
| 4036 | struct snd_soc_codec *codec = dai->codec; |
| 4037 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 4038 | struct snd_soc_dapm_widget *w = tabla_dapm_aif_in_widgets; |
| 4039 | |
| 4040 | for (i = 0; i < ARRAY_SIZE(tabla_dapm_aif_in_widgets); i++) { |
| 4041 | |
| 4042 | if (strncmp(dai->driver->playback.stream_name, w[i].sname, 13)) |
| 4043 | continue; |
| 4044 | |
| 4045 | rx_mix1_inp = w[i].shift + 4; |
| 4046 | |
| 4047 | if ((rx_mix1_inp < 0x5) || (rx_mix1_inp > 0xB)) { |
| 4048 | |
| 4049 | pr_err("%s: Invalid SLIM RX%u port. widget = %s\n", |
| 4050 | __func__, rx_mix1_inp - 4 , w[i].name); |
| 4051 | return -EINVAL; |
| 4052 | } |
| 4053 | |
| 4054 | rx_mix_1_reg_1 = TABLA_A_CDC_CONN_RX1_B1_CTL; |
| 4055 | |
| 4056 | for (j = 0; j < NUM_INTERPOLATORS; j++) { |
| 4057 | |
| 4058 | rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1; |
| 4059 | |
| 4060 | rx_mix_1_reg_1_val = snd_soc_read(codec, |
| 4061 | rx_mix_1_reg_1); |
| 4062 | rx_mix_1_reg_2_val = snd_soc_read(codec, |
| 4063 | rx_mix_1_reg_2); |
| 4064 | |
| 4065 | if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) || |
| 4066 | (((rx_mix_1_reg_1_val >> 4) & 0x0F) == rx_mix1_inp) |
| 4067 | || ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) { |
| 4068 | |
| 4069 | rx_fs_reg = TABLA_A_CDC_RX1_B5_CTL + 8 * j; |
| 4070 | |
| 4071 | pr_debug("%s: %s connected to RX%u\n", __func__, |
| 4072 | w[i].name, j + 1); |
| 4073 | |
| 4074 | pr_debug("%s: set RX%u sample rate to %u\n", |
| 4075 | __func__, j + 1, sample_rate); |
| 4076 | |
| 4077 | snd_soc_update_bits(codec, rx_fs_reg, |
| 4078 | 0xE0, rx_fs_rate_reg_val); |
| 4079 | |
| 4080 | if (comp_rx_path[j] < COMPANDER_MAX) |
| 4081 | tabla->comp_fs[comp_rx_path[j]] |
| 4082 | = compander_fs; |
| 4083 | } |
| 4084 | if (j <= 2) |
| 4085 | rx_mix_1_reg_1 += 3; |
| 4086 | else |
| 4087 | rx_mix_1_reg_1 += 2; |
| 4088 | } |
| 4089 | } |
| 4090 | return 0; |
| 4091 | } |
| 4092 | |
| 4093 | static int tabla_set_decimator_rate(struct snd_soc_dai *dai, |
| 4094 | u8 tx_fs_rate_reg_val, u32 sample_rate) |
| 4095 | { |
| 4096 | struct snd_soc_codec *codec = dai->codec; |
| 4097 | struct snd_soc_dapm_widget *w = tabla_dapm_aif_out_widgets; |
| 4098 | |
| 4099 | u32 i, tx_port; |
| 4100 | u16 tx_port_reg, tx_fs_reg; |
| 4101 | u8 tx_port_reg_val; |
| 4102 | s8 decimator; |
| 4103 | |
| 4104 | for (i = 0; i < ARRAY_SIZE(tabla_dapm_aif_out_widgets); i++) { |
| 4105 | |
| 4106 | if (strncmp(dai->driver->capture.stream_name, w[i].sname, 12)) |
| 4107 | continue; |
| 4108 | |
| 4109 | tx_port = w[i].shift; |
| 4110 | |
| 4111 | if ((tx_port < 1) || (tx_port > NUM_DECIMATORS)) { |
| 4112 | pr_err("%s: Invalid SLIM TX%u port. widget = %s\n", |
| 4113 | __func__, tx_port, w[i].name); |
| 4114 | return -EINVAL; |
| 4115 | } |
| 4116 | |
| 4117 | tx_port_reg = TABLA_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1); |
| 4118 | tx_port_reg_val = snd_soc_read(codec, tx_port_reg); |
| 4119 | |
| 4120 | decimator = 0; |
| 4121 | |
| 4122 | if ((tx_port >= 1) && (tx_port <= 6)) { |
| 4123 | |
| 4124 | tx_port_reg_val = tx_port_reg_val & 0x0F; |
| 4125 | if (tx_port_reg_val == 0x8) |
| 4126 | decimator = tx_port; |
| 4127 | |
| 4128 | } else if ((tx_port >= 7) && (tx_port <= NUM_DECIMATORS)) { |
| 4129 | |
| 4130 | tx_port_reg_val = tx_port_reg_val & 0x1F; |
| 4131 | |
| 4132 | if ((tx_port_reg_val >= 0x8) && |
| 4133 | (tx_port_reg_val <= 0x11)) { |
| 4134 | |
| 4135 | decimator = (tx_port_reg_val - 0x8) + 1; |
| 4136 | } |
| 4137 | } |
| 4138 | |
| 4139 | if (decimator) { /* SLIM_TX port has a DEC as input */ |
| 4140 | |
| 4141 | tx_fs_reg = TABLA_A_CDC_TX1_CLK_FS_CTL + |
| 4142 | 8 * (decimator - 1); |
| 4143 | |
| 4144 | pr_debug("%s: set DEC%u (-> SLIM_TX%u) rate to %u\n", |
| 4145 | __func__, decimator, tx_port, sample_rate); |
| 4146 | |
| 4147 | snd_soc_update_bits(codec, tx_fs_reg, 0x07, |
| 4148 | tx_fs_rate_reg_val); |
| 4149 | |
| 4150 | } else { |
| 4151 | if ((tx_port_reg_val >= 0x1) && |
| 4152 | (tx_port_reg_val <= 0x7)) { |
| 4153 | |
| 4154 | pr_debug("%s: RMIX%u going to SLIM TX%u\n", |
| 4155 | __func__, tx_port_reg_val, tx_port); |
| 4156 | |
| 4157 | } else if ((tx_port_reg_val >= 0x8) && |
| 4158 | (tx_port_reg_val <= 0x11)) { |
| 4159 | |
| 4160 | pr_err("%s: ERROR: Should not be here\n", |
| 4161 | __func__); |
| 4162 | pr_err("%s: ERROR: DEC connected to SLIM TX%u\n" |
| 4163 | , __func__, tx_port); |
| 4164 | return -EINVAL; |
| 4165 | |
| 4166 | } else if (tx_port_reg_val == 0) { |
| 4167 | pr_debug("%s: no signal to SLIM TX%u\n", |
| 4168 | __func__, tx_port); |
| 4169 | } else { |
| 4170 | pr_err("%s: ERROR: wrong signal to SLIM TX%u\n" |
| 4171 | , __func__, tx_port); |
| 4172 | pr_err("%s: ERROR: wrong signal = %u\n" |
| 4173 | , __func__, tx_port_reg_val); |
| 4174 | return -EINVAL; |
| 4175 | } |
| 4176 | } |
| 4177 | } |
| 4178 | return 0; |
| 4179 | } |
| 4180 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4181 | static int tabla_hw_params(struct snd_pcm_substream *substream, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4182 | struct snd_pcm_hw_params *params, |
| 4183 | struct snd_soc_dai *dai) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4184 | { |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4185 | struct snd_soc_codec *codec = dai->codec; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4186 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4187 | u8 tx_fs_rate_reg_val, rx_fs_rate_reg_val; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4188 | u32 compander_fs; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4189 | int ret; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4190 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4191 | pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4192 | dai->name, dai->id, params_rate(params), |
| 4193 | params_channels(params)); |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4194 | |
| 4195 | switch (params_rate(params)) { |
| 4196 | case 8000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4197 | tx_fs_rate_reg_val = 0x00; |
| 4198 | rx_fs_rate_reg_val = 0x00; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4199 | compander_fs = COMPANDER_FS_8KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4200 | break; |
| 4201 | case 16000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4202 | tx_fs_rate_reg_val = 0x01; |
| 4203 | rx_fs_rate_reg_val = 0x20; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4204 | compander_fs = COMPANDER_FS_16KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4205 | break; |
| 4206 | case 32000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4207 | tx_fs_rate_reg_val = 0x02; |
| 4208 | rx_fs_rate_reg_val = 0x40; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4209 | compander_fs = COMPANDER_FS_32KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4210 | break; |
| 4211 | case 48000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4212 | tx_fs_rate_reg_val = 0x03; |
| 4213 | rx_fs_rate_reg_val = 0x60; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4214 | compander_fs = COMPANDER_FS_48KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4215 | break; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4216 | case 96000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4217 | tx_fs_rate_reg_val = 0x04; |
| 4218 | rx_fs_rate_reg_val = 0x80; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4219 | compander_fs = COMPANDER_FS_96KHZ; |
| 4220 | break; |
| 4221 | case 192000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4222 | tx_fs_rate_reg_val = 0x05; |
| 4223 | rx_fs_rate_reg_val = 0xA0; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4224 | compander_fs = COMPANDER_FS_192KHZ; |
| 4225 | break; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4226 | default: |
| 4227 | pr_err("%s: Invalid sampling rate %d\n", __func__, |
| 4228 | params_rate(params)); |
| 4229 | return -EINVAL; |
| 4230 | } |
| 4231 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4232 | switch (substream->stream) { |
| 4233 | case SNDRV_PCM_STREAM_CAPTURE: |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4234 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4235 | ret = tabla_set_decimator_rate(dai, tx_fs_rate_reg_val, |
| 4236 | params_rate(params)); |
| 4237 | if (ret < 0) { |
| 4238 | pr_err("%s: set decimator rate failed %d\n", __func__, |
| 4239 | ret); |
| 4240 | return ret; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4241 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4242 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4243 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4244 | switch (params_format(params)) { |
| 4245 | case SNDRV_PCM_FORMAT_S16_LE: |
| 4246 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4247 | TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x20); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4248 | break; |
| 4249 | case SNDRV_PCM_FORMAT_S32_LE: |
| 4250 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4251 | TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x00); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4252 | break; |
| 4253 | default: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4254 | pr_err("%s: invalid TX format %u\n", __func__, |
| 4255 | params_format(params)); |
| 4256 | return -EINVAL; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4257 | } |
| 4258 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_TX_I2S_CTL, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4259 | 0x07, tx_fs_rate_reg_val); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4260 | } else { |
| 4261 | tabla->dai[dai->id - 1].rate = params_rate(params); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4262 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4263 | break; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4264 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4265 | case SNDRV_PCM_STREAM_PLAYBACK: |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4266 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4267 | ret = tabla_set_interpolator_rate(dai, rx_fs_rate_reg_val, |
| 4268 | compander_fs, params_rate(params)); |
| 4269 | if (ret < 0) { |
| 4270 | pr_err("%s: set decimator rate failed %d\n", __func__, |
| 4271 | ret); |
| 4272 | return ret; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4273 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4274 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4275 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4276 | switch (params_format(params)) { |
| 4277 | case SNDRV_PCM_FORMAT_S16_LE: |
| 4278 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4279 | TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x20); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4280 | break; |
| 4281 | case SNDRV_PCM_FORMAT_S32_LE: |
| 4282 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4283 | TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x00); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4284 | break; |
| 4285 | default: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4286 | pr_err("%s: invalid RX format %u\n", __func__, |
| 4287 | params_format(params)); |
| 4288 | return -EINVAL; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4289 | } |
| 4290 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_I2S_CTL, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4291 | 0x03, (rx_fs_rate_reg_val >> 0x05)); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4292 | } else { |
| 4293 | tabla->dai[dai->id - 1].rate = params_rate(params); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4294 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4295 | break; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4296 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4297 | default: |
| 4298 | pr_err("%s: Invalid stream type %d\n", __func__, |
| 4299 | substream->stream); |
| 4300 | return -EINVAL; |
| 4301 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4302 | return 0; |
| 4303 | } |
| 4304 | |
| 4305 | static struct snd_soc_dai_ops tabla_dai_ops = { |
| 4306 | .startup = tabla_startup, |
| 4307 | .shutdown = tabla_shutdown, |
| 4308 | .hw_params = tabla_hw_params, |
| 4309 | .set_sysclk = tabla_set_dai_sysclk, |
| 4310 | .set_fmt = tabla_set_dai_fmt, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4311 | .set_channel_map = tabla_set_channel_map, |
| 4312 | .get_channel_map = tabla_get_channel_map, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4313 | }; |
| 4314 | |
| 4315 | static struct snd_soc_dai_driver tabla_dai[] = { |
| 4316 | { |
| 4317 | .name = "tabla_rx1", |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4318 | .id = AIF1_PB, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4319 | .playback = { |
| 4320 | .stream_name = "AIF1 Playback", |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4321 | .rates = WCD9310_RATES, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4322 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4323 | .rate_max = 192000, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4324 | .rate_min = 8000, |
| 4325 | .channels_min = 1, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4326 | .channels_max = 2, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4327 | }, |
| 4328 | .ops = &tabla_dai_ops, |
| 4329 | }, |
| 4330 | { |
| 4331 | .name = "tabla_tx1", |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4332 | .id = AIF1_CAP, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4333 | .capture = { |
| 4334 | .stream_name = "AIF1 Capture", |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4335 | .rates = WCD9310_RATES, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4336 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4337 | .rate_max = 192000, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4338 | .rate_min = 8000, |
| 4339 | .channels_min = 1, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4340 | .channels_max = 4, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4341 | }, |
| 4342 | .ops = &tabla_dai_ops, |
| 4343 | }, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4344 | { |
| 4345 | .name = "tabla_rx2", |
| 4346 | .id = AIF2_PB, |
| 4347 | .playback = { |
| 4348 | .stream_name = "AIF2 Playback", |
| 4349 | .rates = WCD9310_RATES, |
| 4350 | .formats = TABLA_FORMATS, |
| 4351 | .rate_min = 8000, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4352 | .rate_max = 192000, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4353 | .channels_min = 1, |
| 4354 | .channels_max = 2, |
| 4355 | }, |
| 4356 | .ops = &tabla_dai_ops, |
| 4357 | }, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4358 | { |
| 4359 | .name = "tabla_tx2", |
| 4360 | .id = AIF2_CAP, |
| 4361 | .capture = { |
| 4362 | .stream_name = "AIF2 Capture", |
| 4363 | .rates = WCD9310_RATES, |
| 4364 | .formats = TABLA_FORMATS, |
| 4365 | .rate_max = 192000, |
| 4366 | .rate_min = 8000, |
| 4367 | .channels_min = 1, |
| 4368 | .channels_max = 4, |
| 4369 | }, |
| 4370 | .ops = &tabla_dai_ops, |
| 4371 | }, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 4372 | { |
| 4373 | .name = "tabla_tx3", |
| 4374 | .id = AIF3_CAP, |
| 4375 | .capture = { |
| 4376 | .stream_name = "AIF3 Capture", |
| 4377 | .rates = WCD9310_RATES, |
| 4378 | .formats = TABLA_FORMATS, |
| 4379 | .rate_max = 48000, |
| 4380 | .rate_min = 8000, |
| 4381 | .channels_min = 1, |
| 4382 | .channels_max = 2, |
| 4383 | }, |
| 4384 | .ops = &tabla_dai_ops, |
| 4385 | }, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4386 | { |
| 4387 | .name = "tabla_rx3", |
| 4388 | .id = AIF3_PB, |
| 4389 | .playback = { |
| 4390 | .stream_name = "AIF3 Playback", |
| 4391 | .rates = WCD9310_RATES, |
| 4392 | .formats = TABLA_FORMATS, |
| 4393 | .rate_min = 8000, |
| 4394 | .rate_max = 192000, |
| 4395 | .channels_min = 1, |
| 4396 | .channels_max = 2, |
| 4397 | }, |
| 4398 | .ops = &tabla_dai_ops, |
| 4399 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4400 | }; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4401 | |
| 4402 | static struct snd_soc_dai_driver tabla_i2s_dai[] = { |
| 4403 | { |
| 4404 | .name = "tabla_i2s_rx1", |
| 4405 | .id = 1, |
| 4406 | .playback = { |
| 4407 | .stream_name = "AIF1 Playback", |
| 4408 | .rates = WCD9310_RATES, |
| 4409 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4410 | .rate_max = 192000, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4411 | .rate_min = 8000, |
| 4412 | .channels_min = 1, |
| 4413 | .channels_max = 4, |
| 4414 | }, |
| 4415 | .ops = &tabla_dai_ops, |
| 4416 | }, |
| 4417 | { |
| 4418 | .name = "tabla_i2s_tx1", |
| 4419 | .id = 2, |
| 4420 | .capture = { |
| 4421 | .stream_name = "AIF1 Capture", |
| 4422 | .rates = WCD9310_RATES, |
| 4423 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4424 | .rate_max = 192000, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4425 | .rate_min = 8000, |
| 4426 | .channels_min = 1, |
| 4427 | .channels_max = 4, |
| 4428 | }, |
| 4429 | .ops = &tabla_dai_ops, |
| 4430 | }, |
| 4431 | }; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4432 | |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 4433 | static int tabla_codec_enable_chmask(struct tabla_priv *tabla_p, |
| 4434 | int event, int index) |
| 4435 | { |
| 4436 | int ret = 0; |
| 4437 | u32 k = 0; |
| 4438 | switch (event) { |
| 4439 | case SND_SOC_DAPM_POST_PMU: |
| 4440 | for (k = 0; k < tabla_p->dai[index].ch_tot; k++) { |
| 4441 | ret = wcd9xxx_get_slave_port( |
| 4442 | tabla_p->dai[index].ch_num[k]); |
| 4443 | if (ret < 0) { |
| 4444 | pr_err("%s: Invalid slave port ID: %d\n", |
| 4445 | __func__, ret); |
| 4446 | ret = -EINVAL; |
| 4447 | break; |
| 4448 | } |
| 4449 | tabla_p->dai[index].ch_mask |= 1 << ret; |
| 4450 | } |
| 4451 | ret = 0; |
| 4452 | break; |
| 4453 | case SND_SOC_DAPM_POST_PMD: |
| 4454 | ret = wait_event_timeout(tabla_p->dai[index].dai_wait, |
| 4455 | (tabla_p->dai[index].ch_mask == 0), |
| 4456 | msecs_to_jiffies(SLIM_CLOSE_TIMEOUT)); |
| 4457 | if (!ret) { |
| 4458 | pr_err("%s: Slim close tx/rx wait timeout\n", |
| 4459 | __func__); |
| 4460 | ret = -EINVAL; |
| 4461 | } |
| 4462 | ret = 0; |
| 4463 | break; |
| 4464 | } |
| 4465 | return ret; |
| 4466 | } |
| 4467 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4468 | static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
| 4469 | struct snd_kcontrol *kcontrol, int event) |
| 4470 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4471 | struct wcd9xxx *tabla; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4472 | struct snd_soc_codec *codec = w->codec; |
| 4473 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 4474 | u32 j = 0; |
| 4475 | u32 ret = 0; |
| 4476 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 4477 | tabla = codec->control_data; |
| 4478 | /* Execute the callback only if interface type is slimbus */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4479 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4480 | return 0; |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4481 | |
| 4482 | pr_debug("%s: %s %d\n", __func__, w->name, event); |
| 4483 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4484 | switch (event) { |
| 4485 | case SND_SOC_DAPM_POST_PMU: |
| 4486 | for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) { |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4487 | if ((tabla_dai[j].id == AIF1_CAP) || |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 4488 | (tabla_dai[j].id == AIF2_CAP) || |
| 4489 | (tabla_dai[j].id == AIF3_CAP)) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4490 | continue; |
| 4491 | if (!strncmp(w->sname, |
| 4492 | tabla_dai[j].playback.stream_name, 13)) { |
| 4493 | ++tabla_p->dai[j].ch_act; |
| 4494 | break; |
| 4495 | } |
| 4496 | } |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 4497 | if (tabla_p->dai[j].ch_act == tabla_p->dai[j].ch_tot) { |
| 4498 | ret = tabla_codec_enable_chmask(tabla_p, |
| 4499 | SND_SOC_DAPM_POST_PMU, |
| 4500 | j); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4501 | ret = wcd9xxx_cfg_slim_sch_rx(tabla, |
| 4502 | tabla_p->dai[j].ch_num, |
| 4503 | tabla_p->dai[j].ch_tot, |
| 4504 | tabla_p->dai[j].rate); |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 4505 | } |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4506 | break; |
| 4507 | case SND_SOC_DAPM_POST_PMD: |
| 4508 | for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) { |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4509 | if ((tabla_dai[j].id == AIF1_CAP) || |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 4510 | (tabla_dai[j].id == AIF2_CAP) || |
| 4511 | (tabla_dai[j].id == AIF3_CAP)) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4512 | continue; |
| 4513 | if (!strncmp(w->sname, |
| 4514 | tabla_dai[j].playback.stream_name, 13)) { |
Helen Zeng | 2aaa3c1 | 2012-06-08 20:29:21 -0700 | [diff] [blame] | 4515 | if (tabla_p->dai[j].ch_act) |
| 4516 | --tabla_p->dai[j].ch_act; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4517 | break; |
| 4518 | } |
| 4519 | } |
| 4520 | if (!tabla_p->dai[j].ch_act) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4521 | ret = wcd9xxx_close_slim_sch_rx(tabla, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4522 | tabla_p->dai[j].ch_num, |
| 4523 | tabla_p->dai[j].ch_tot); |
| 4524 | tabla_p->dai[j].rate = 0; |
| 4525 | memset(tabla_p->dai[j].ch_num, 0, (sizeof(u32)* |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4526 | tabla_p->dai[j].ch_tot)); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4527 | tabla_p->dai[j].ch_tot = 0; |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 4528 | ret = tabla_codec_enable_chmask(tabla_p, |
| 4529 | SND_SOC_DAPM_POST_PMD, |
| 4530 | j); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4531 | } |
| 4532 | } |
| 4533 | return ret; |
| 4534 | } |
| 4535 | |
| 4536 | static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
| 4537 | struct snd_kcontrol *kcontrol, int event) |
| 4538 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4539 | struct wcd9xxx *tabla; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4540 | struct snd_soc_codec *codec = w->codec; |
| 4541 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 4542 | /* index to the DAI ID, for now hardcoding */ |
| 4543 | u32 j = 0; |
| 4544 | u32 ret = 0; |
| 4545 | |
| 4546 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 4547 | tabla = codec->control_data; |
| 4548 | |
| 4549 | /* Execute the callback only if interface type is slimbus */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4550 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4551 | return 0; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4552 | |
| 4553 | pr_debug("%s(): %s %d\n", __func__, w->name, event); |
| 4554 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4555 | switch (event) { |
| 4556 | case SND_SOC_DAPM_POST_PMU: |
| 4557 | for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) { |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4558 | if (tabla_dai[j].id == AIF1_PB || |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4559 | tabla_dai[j].id == AIF2_PB || |
| 4560 | tabla_dai[j].id == AIF3_PB) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4561 | continue; |
| 4562 | if (!strncmp(w->sname, |
| 4563 | tabla_dai[j].capture.stream_name, 13)) { |
| 4564 | ++tabla_p->dai[j].ch_act; |
| 4565 | break; |
| 4566 | } |
| 4567 | } |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 4568 | if (tabla_p->dai[j].ch_act == tabla_p->dai[j].ch_tot) { |
| 4569 | ret = tabla_codec_enable_chmask(tabla_p, |
| 4570 | SND_SOC_DAPM_POST_PMU, |
| 4571 | j); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4572 | ret = wcd9xxx_cfg_slim_sch_tx(tabla, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4573 | tabla_p->dai[j].ch_num, |
| 4574 | tabla_p->dai[j].ch_tot, |
| 4575 | tabla_p->dai[j].rate); |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 4576 | } |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4577 | break; |
| 4578 | case SND_SOC_DAPM_POST_PMD: |
| 4579 | for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) { |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4580 | if (tabla_dai[j].id == AIF1_PB || |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4581 | tabla_dai[j].id == AIF2_PB || |
| 4582 | tabla_dai[j].id == AIF3_PB) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4583 | continue; |
| 4584 | if (!strncmp(w->sname, |
| 4585 | tabla_dai[j].capture.stream_name, 13)) { |
| 4586 | --tabla_p->dai[j].ch_act; |
| 4587 | break; |
| 4588 | } |
| 4589 | } |
| 4590 | if (!tabla_p->dai[j].ch_act) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4591 | ret = wcd9xxx_close_slim_sch_tx(tabla, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4592 | tabla_p->dai[j].ch_num, |
| 4593 | tabla_p->dai[j].ch_tot); |
| 4594 | tabla_p->dai[j].rate = 0; |
| 4595 | memset(tabla_p->dai[j].ch_num, 0, (sizeof(u32)* |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4596 | tabla_p->dai[j].ch_tot)); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4597 | tabla_p->dai[j].ch_tot = 0; |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 4598 | ret = tabla_codec_enable_chmask(tabla_p, |
| 4599 | SND_SOC_DAPM_POST_PMD, |
| 4600 | j); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4601 | } |
| 4602 | } |
| 4603 | return ret; |
| 4604 | } |
| 4605 | |
| 4606 | /* Todo: Have seperate dapm widgets for I2S and Slimbus. |
| 4607 | * Might Need to have callbacks registered only for slimbus |
| 4608 | */ |
| 4609 | static const struct snd_soc_dapm_widget tabla_dapm_widgets[] = { |
| 4610 | /*RX stuff */ |
| 4611 | SND_SOC_DAPM_OUTPUT("EAR"), |
| 4612 | |
| 4613 | SND_SOC_DAPM_PGA("EAR PA", TABLA_A_RX_EAR_EN, 4, 0, NULL, 0), |
| 4614 | |
| 4615 | SND_SOC_DAPM_MIXER("DAC1", TABLA_A_RX_EAR_EN, 6, 0, dac1_switch, |
| 4616 | ARRAY_SIZE(dac1_switch)), |
| 4617 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4618 | /* Headphone */ |
| 4619 | SND_SOC_DAPM_OUTPUT("HEADPHONE"), |
| 4620 | SND_SOC_DAPM_PGA_E("HPHL", TABLA_A_RX_HPH_CNP_EN, 5, 0, NULL, 0, |
| 4621 | tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 4622 | SND_SOC_DAPM_POST_PMD), |
| 4623 | SND_SOC_DAPM_MIXER("HPHL DAC", TABLA_A_RX_HPH_L_DAC_CTL, 7, 0, |
| 4624 | hphl_switch, ARRAY_SIZE(hphl_switch)), |
| 4625 | |
| 4626 | SND_SOC_DAPM_PGA_E("HPHR", TABLA_A_RX_HPH_CNP_EN, 4, 0, NULL, 0, |
| 4627 | tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 4628 | SND_SOC_DAPM_POST_PMD), |
| 4629 | |
| 4630 | SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TABLA_A_RX_HPH_R_DAC_CTL, 7, 0, |
| 4631 | tabla_hphr_dac_event, |
| 4632 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4633 | |
| 4634 | /* Speaker */ |
| 4635 | SND_SOC_DAPM_OUTPUT("LINEOUT1"), |
| 4636 | SND_SOC_DAPM_OUTPUT("LINEOUT2"), |
| 4637 | SND_SOC_DAPM_OUTPUT("LINEOUT3"), |
| 4638 | SND_SOC_DAPM_OUTPUT("LINEOUT4"), |
| 4639 | SND_SOC_DAPM_OUTPUT("LINEOUT5"), |
| 4640 | |
| 4641 | SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TABLA_A_RX_LINE_CNP_EN, 0, 0, NULL, |
| 4642 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4643 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4644 | SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TABLA_A_RX_LINE_CNP_EN, 1, 0, NULL, |
| 4645 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4646 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4647 | SND_SOC_DAPM_PGA_E("LINEOUT3 PA", TABLA_A_RX_LINE_CNP_EN, 2, 0, NULL, |
| 4648 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4649 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4650 | SND_SOC_DAPM_PGA_E("LINEOUT4 PA", TABLA_A_RX_LINE_CNP_EN, 3, 0, NULL, |
| 4651 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4652 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4653 | SND_SOC_DAPM_PGA_E("LINEOUT5 PA", TABLA_A_RX_LINE_CNP_EN, 4, 0, NULL, 0, |
| 4654 | tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4655 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4656 | |
| 4657 | SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TABLA_A_RX_LINE_1_DAC_CTL, 7, 0 |
| 4658 | , tabla_lineout_dac_event, |
| 4659 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4660 | SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TABLA_A_RX_LINE_2_DAC_CTL, 7, 0 |
| 4661 | , tabla_lineout_dac_event, |
| 4662 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4663 | SND_SOC_DAPM_DAC_E("LINEOUT3 DAC", NULL, TABLA_A_RX_LINE_3_DAC_CTL, 7, 0 |
| 4664 | , tabla_lineout_dac_event, |
| 4665 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4666 | SND_SOC_DAPM_SWITCH("LINEOUT3 DAC GROUND", SND_SOC_NOPM, 0, 0, |
| 4667 | &lineout3_ground_switch), |
| 4668 | SND_SOC_DAPM_DAC_E("LINEOUT4 DAC", NULL, TABLA_A_RX_LINE_4_DAC_CTL, 7, 0 |
| 4669 | , tabla_lineout_dac_event, |
| 4670 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4671 | SND_SOC_DAPM_SWITCH("LINEOUT4 DAC GROUND", SND_SOC_NOPM, 0, 0, |
| 4672 | &lineout4_ground_switch), |
| 4673 | SND_SOC_DAPM_DAC_E("LINEOUT5 DAC", NULL, TABLA_A_RX_LINE_5_DAC_CTL, 7, 0 |
| 4674 | , tabla_lineout_dac_event, |
| 4675 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4676 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4677 | 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] | 4678 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4679 | SND_SOC_DAPM_POST_PMU), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4680 | 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] | 4681 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4682 | SND_SOC_DAPM_POST_PMU), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4683 | 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] | 4684 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4685 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4686 | 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] | 4687 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4688 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4689 | 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] | 4690 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4691 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4692 | 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] | 4693 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4694 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4695 | 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] | 4696 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4697 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4698 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4699 | SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4700 | SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4701 | SND_SOC_DAPM_MIXER("RX3 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4702 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4703 | SND_SOC_DAPM_MUX_E("RX4 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0, |
| 4704 | &rx4_dsm_mux, tabla_codec_reset_interpolator, |
| 4705 | SND_SOC_DAPM_PRE_PMU), |
| 4706 | |
| 4707 | SND_SOC_DAPM_MUX_E("RX6 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0, |
| 4708 | &rx6_dsm_mux, tabla_codec_reset_interpolator, |
| 4709 | SND_SOC_DAPM_PRE_PMU), |
| 4710 | |
| 4711 | SND_SOC_DAPM_MIXER("RX1 CHAIN", TABLA_A_CDC_RX1_B6_CTL, 5, 0, NULL, 0), |
| 4712 | SND_SOC_DAPM_MIXER("RX2 CHAIN", TABLA_A_CDC_RX2_B6_CTL, 5, 0, NULL, 0), |
| 4713 | |
| 4714 | SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4715 | &rx_mix1_inp1_mux), |
| 4716 | SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4717 | &rx_mix1_inp2_mux), |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4718 | SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0, |
| 4719 | &rx_mix1_inp3_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4720 | SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4721 | &rx2_mix1_inp1_mux), |
| 4722 | SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4723 | &rx2_mix1_inp2_mux), |
| 4724 | SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4725 | &rx3_mix1_inp1_mux), |
| 4726 | SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4727 | &rx3_mix1_inp2_mux), |
| 4728 | SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4729 | &rx4_mix1_inp1_mux), |
| 4730 | SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4731 | &rx4_mix1_inp2_mux), |
| 4732 | SND_SOC_DAPM_MUX("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4733 | &rx5_mix1_inp1_mux), |
| 4734 | SND_SOC_DAPM_MUX("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4735 | &rx5_mix1_inp2_mux), |
| 4736 | SND_SOC_DAPM_MUX("RX6 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4737 | &rx6_mix1_inp1_mux), |
| 4738 | SND_SOC_DAPM_MUX("RX6 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4739 | &rx6_mix1_inp2_mux), |
| 4740 | SND_SOC_DAPM_MUX("RX7 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4741 | &rx7_mix1_inp1_mux), |
| 4742 | SND_SOC_DAPM_MUX("RX7 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4743 | &rx7_mix1_inp2_mux), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4744 | SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 4745 | &rx1_mix2_inp1_mux), |
| 4746 | SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 4747 | &rx1_mix2_inp2_mux), |
| 4748 | SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 4749 | &rx2_mix2_inp1_mux), |
| 4750 | SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 4751 | &rx2_mix2_inp2_mux), |
| 4752 | SND_SOC_DAPM_MUX("RX3 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 4753 | &rx3_mix2_inp1_mux), |
| 4754 | SND_SOC_DAPM_MUX("RX3 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 4755 | &rx3_mix2_inp2_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4756 | |
| 4757 | SND_SOC_DAPM_SUPPLY("CP", TABLA_A_CP_EN, 0, 0, |
| 4758 | tabla_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU | |
| 4759 | SND_SOC_DAPM_PRE_PMD), |
| 4760 | |
| 4761 | SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0, |
| 4762 | tabla_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU | |
| 4763 | SND_SOC_DAPM_POST_PMD), |
| 4764 | |
| 4765 | /* TX */ |
| 4766 | |
| 4767 | SND_SOC_DAPM_SUPPLY("CDC_CONN", TABLA_A_CDC_CLK_OTHR_CTL, 2, 0, NULL, |
| 4768 | 0), |
| 4769 | |
| 4770 | SND_SOC_DAPM_SUPPLY("LDO_H", TABLA_A_LDO_H_MODE_1, 7, 0, |
| 4771 | tabla_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU), |
| 4772 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4773 | SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 0, 0, |
| 4774 | tabla_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 4775 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 4776 | SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 1, 0, |
| 4777 | tabla_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 4778 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 4779 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4780 | SND_SOC_DAPM_INPUT("AMIC1"), |
| 4781 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", TABLA_A_MICB_1_CTL, 7, 0, |
| 4782 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4783 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4784 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", TABLA_A_MICB_1_CTL, 7, 0, |
| 4785 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4786 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4787 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", TABLA_A_MICB_1_CTL, 7, 0, |
| 4788 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4789 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4790 | SND_SOC_DAPM_ADC_E("ADC1", NULL, TABLA_A_TX_1_2_EN, 7, 0, |
| 4791 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 4792 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4793 | |
| 4794 | SND_SOC_DAPM_INPUT("AMIC3"), |
| 4795 | SND_SOC_DAPM_ADC_E("ADC3", NULL, TABLA_A_TX_3_4_EN, 7, 0, |
| 4796 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 4797 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4798 | |
| 4799 | SND_SOC_DAPM_INPUT("AMIC4"), |
| 4800 | SND_SOC_DAPM_ADC_E("ADC4", NULL, TABLA_A_TX_3_4_EN, 3, 0, |
| 4801 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 4802 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4803 | |
| 4804 | SND_SOC_DAPM_INPUT("AMIC5"), |
| 4805 | SND_SOC_DAPM_ADC_E("ADC5", NULL, TABLA_A_TX_5_6_EN, 7, 0, |
| 4806 | tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU), |
| 4807 | |
| 4808 | SND_SOC_DAPM_INPUT("AMIC6"), |
| 4809 | SND_SOC_DAPM_ADC_E("ADC6", NULL, TABLA_A_TX_5_6_EN, 3, 0, |
| 4810 | tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU), |
| 4811 | |
| 4812 | 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] | 4813 | &dec1_mux, tabla_codec_enable_dec, |
| 4814 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4815 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4816 | |
| 4817 | 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] | 4818 | &dec2_mux, tabla_codec_enable_dec, |
| 4819 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4820 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4821 | |
| 4822 | 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] | 4823 | &dec3_mux, tabla_codec_enable_dec, |
| 4824 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4825 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4826 | |
| 4827 | 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] | 4828 | &dec4_mux, tabla_codec_enable_dec, |
| 4829 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4830 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4831 | |
| 4832 | 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] | 4833 | &dec5_mux, tabla_codec_enable_dec, |
| 4834 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4835 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4836 | |
| 4837 | 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] | 4838 | &dec6_mux, tabla_codec_enable_dec, |
| 4839 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4840 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4841 | |
| 4842 | 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] | 4843 | &dec7_mux, tabla_codec_enable_dec, |
| 4844 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4845 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4846 | |
| 4847 | 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] | 4848 | &dec8_mux, tabla_codec_enable_dec, |
| 4849 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4850 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4851 | |
| 4852 | 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] | 4853 | &dec9_mux, tabla_codec_enable_dec, |
| 4854 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4855 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4856 | |
| 4857 | 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] | 4858 | &dec10_mux, tabla_codec_enable_dec, |
| 4859 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4860 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4861 | |
| 4862 | SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux), |
| 4863 | SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux), |
| 4864 | |
| 4865 | SND_SOC_DAPM_MIXER_E("ANC", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 4866 | tabla_codec_enable_anc, SND_SOC_DAPM_PRE_PMU | |
| 4867 | SND_SOC_DAPM_POST_PMD), |
| 4868 | |
| 4869 | SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux), |
| 4870 | |
| 4871 | SND_SOC_DAPM_INPUT("AMIC2"), |
| 4872 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", TABLA_A_MICB_2_CTL, 7, 0, |
| 4873 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4874 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4875 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", TABLA_A_MICB_2_CTL, 7, 0, |
| 4876 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4877 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4878 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", TABLA_A_MICB_2_CTL, 7, 0, |
| 4879 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4880 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4881 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", TABLA_A_MICB_2_CTL, 7, 0, |
| 4882 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4883 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4884 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", TABLA_A_MICB_3_CTL, 7, 0, |
| 4885 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4886 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4887 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", TABLA_A_MICB_3_CTL, 7, 0, |
| 4888 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4889 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4890 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", TABLA_A_MICB_3_CTL, 7, 0, |
| 4891 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4892 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4893 | SND_SOC_DAPM_ADC_E("ADC2", NULL, TABLA_A_TX_1_2_EN, 3, 0, |
| 4894 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 4895 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4896 | |
| 4897 | SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, 0, 0, &sb_tx1_mux), |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4898 | SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, 0, 0, &sb_tx2_mux), |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4899 | SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, 0, 0, &sb_tx3_mux), |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4900 | SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, 0, 0, &sb_tx4_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4901 | SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, 0, 0, &sb_tx5_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4902 | SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, 0, 0, &sb_tx6_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4903 | SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, 0, 0, &sb_tx7_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4904 | SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, 0, 0, &sb_tx8_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4905 | SND_SOC_DAPM_MUX("SLIM TX9 MUX", SND_SOC_NOPM, 0, 0, &sb_tx9_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4906 | SND_SOC_DAPM_MUX("SLIM TX10 MUX", SND_SOC_NOPM, 0, 0, &sb_tx10_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4907 | |
| 4908 | /* Digital Mic Inputs */ |
| 4909 | SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0, |
| 4910 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4911 | SND_SOC_DAPM_POST_PMD), |
| 4912 | |
| 4913 | SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0, |
| 4914 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4915 | SND_SOC_DAPM_POST_PMD), |
| 4916 | |
| 4917 | SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0, |
| 4918 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4919 | SND_SOC_DAPM_POST_PMD), |
| 4920 | |
| 4921 | SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0, |
| 4922 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4923 | SND_SOC_DAPM_POST_PMD), |
| 4924 | |
| 4925 | SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0, |
| 4926 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4927 | SND_SOC_DAPM_POST_PMD), |
| 4928 | SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 0, |
| 4929 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4930 | SND_SOC_DAPM_POST_PMD), |
| 4931 | |
| 4932 | /* Sidetone */ |
| 4933 | SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux), |
| 4934 | 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] | 4935 | |
| 4936 | /* AUX PGA */ |
| 4937 | SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TABLA_A_AUX_L_EN, 7, 0, |
| 4938 | tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 4939 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD | |
| 4940 | SND_SOC_DAPM_POST_PMD), |
| 4941 | |
| 4942 | SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TABLA_A_AUX_R_EN, 7, 0, |
| 4943 | tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 4944 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD | |
| 4945 | SND_SOC_DAPM_POST_PMD), |
| 4946 | |
| 4947 | /* Lineout, ear and HPH PA Mixers */ |
| 4948 | SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4949 | hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)), |
| 4950 | |
| 4951 | SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4952 | hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)), |
| 4953 | |
| 4954 | SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4955 | lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)), |
| 4956 | |
| 4957 | SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4958 | lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)), |
| 4959 | |
| 4960 | SND_SOC_DAPM_MIXER("LINEOUT3_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4961 | lineout3_pa_mix, ARRAY_SIZE(lineout3_pa_mix)), |
| 4962 | |
| 4963 | SND_SOC_DAPM_MIXER("LINEOUT4_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4964 | lineout4_pa_mix, ARRAY_SIZE(lineout4_pa_mix)), |
| 4965 | |
| 4966 | SND_SOC_DAPM_MIXER("LINEOUT5_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4967 | lineout5_pa_mix, ARRAY_SIZE(lineout5_pa_mix)), |
| 4968 | |
| 4969 | SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4970 | ear_pa_mix, ARRAY_SIZE(ear_pa_mix)), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4971 | }; |
| 4972 | |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 4973 | static short tabla_codec_read_sta_result(struct snd_soc_codec *codec) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4974 | { |
| 4975 | u8 bias_msb, bias_lsb; |
| 4976 | short bias_value; |
| 4977 | |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 4978 | bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B3_STATUS); |
| 4979 | bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B2_STATUS); |
| 4980 | bias_value = (bias_msb << 8) | bias_lsb; |
| 4981 | return bias_value; |
| 4982 | } |
| 4983 | |
| 4984 | static short tabla_codec_read_dce_result(struct snd_soc_codec *codec) |
| 4985 | { |
| 4986 | u8 bias_msb, bias_lsb; |
| 4987 | short bias_value; |
| 4988 | |
| 4989 | bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B5_STATUS); |
| 4990 | bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B4_STATUS); |
| 4991 | bias_value = (bias_msb << 8) | bias_lsb; |
| 4992 | return bias_value; |
| 4993 | } |
| 4994 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4995 | 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] | 4996 | { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4997 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, on << 1); |
| 4998 | } |
| 4999 | |
| 5000 | static short __tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce, |
| 5001 | bool override_bypass, bool noreldetection) |
| 5002 | { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5003 | short bias_value; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5004 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 5005 | |
| 5006 | wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL); |
| 5007 | if (noreldetection) |
| 5008 | tabla_turn_onoff_rel_detection(codec, false); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5009 | |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 5010 | /* Turn on the override */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5011 | if (!override_bypass) |
| 5012 | 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] | 5013 | if (dce) { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5014 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5015 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4); |
| 5016 | 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] | 5017 | usleep_range(tabla->mbhc_data.t_sta_dce, |
| 5018 | tabla->mbhc_data.t_sta_dce); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5019 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5020 | usleep_range(tabla->mbhc_data.t_dce, |
| 5021 | tabla->mbhc_data.t_dce); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5022 | bias_value = tabla_codec_read_dce_result(codec); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5023 | } else { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5024 | 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] | 5025 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2); |
| 5026 | 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] | 5027 | usleep_range(tabla->mbhc_data.t_sta_dce, |
| 5028 | tabla->mbhc_data.t_sta_dce); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5029 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2); |
| 5030 | usleep_range(tabla->mbhc_data.t_sta, |
| 5031 | tabla->mbhc_data.t_sta); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5032 | bias_value = tabla_codec_read_sta_result(codec); |
| 5033 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5034 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x0); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5035 | } |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 5036 | /* Turn off the override after measuring mic voltage */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5037 | if (!override_bypass) |
| 5038 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00); |
| 5039 | |
| 5040 | if (noreldetection) |
| 5041 | tabla_turn_onoff_rel_detection(codec, true); |
| 5042 | wcd9xxx_enable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5043 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5044 | return bias_value; |
| 5045 | } |
| 5046 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5047 | static short tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce, |
| 5048 | bool norel) |
| 5049 | { |
| 5050 | return __tabla_codec_sta_dce(codec, dce, false, norel); |
| 5051 | } |
| 5052 | |
| 5053 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 5054 | static short tabla_codec_setup_hs_polling(struct snd_soc_codec *codec) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5055 | { |
| 5056 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 5057 | short bias_value; |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 5058 | u8 cfilt_mode; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5059 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5060 | pr_debug("%s: enter, mclk_enabled %d\n", __func__, tabla->mclk_enabled); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5061 | if (!tabla->mbhc_cfg.calibration) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5062 | pr_err("Error, no tabla calibration\n"); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5063 | return -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5064 | } |
| 5065 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 5066 | if (!tabla->mclk_enabled) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 5067 | tabla_codec_disable_clock_block(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5068 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_MBHC_MODE); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 5069 | tabla_enable_rx_bias(codec, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5070 | tabla_codec_enable_clock_block(codec, 1); |
| 5071 | } |
| 5072 | |
| 5073 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x01); |
| 5074 | |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 5075 | /* Make sure CFILT is in fast mode, save current mode */ |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 5076 | cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl); |
| 5077 | 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] | 5078 | |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 5079 | 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] | 5080 | |
| 5081 | 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] | 5082 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5083 | |
| 5084 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x80); |
| 5085 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x1F, 0x1C); |
| 5086 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x40, 0x40); |
| 5087 | |
| 5088 | 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] | 5089 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5090 | 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] | 5091 | |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 5092 | 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] | 5093 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5094 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5095 | tabla_codec_calibrate_hs_polling(codec); |
| 5096 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5097 | /* don't flip override */ |
| 5098 | bias_value = __tabla_codec_sta_dce(codec, 1, true, true); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5099 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 5100 | cfilt_mode); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5101 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5102 | |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 5103 | return bias_value; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5104 | } |
| 5105 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5106 | static int tabla_cancel_btn_work(struct tabla_priv *tabla) |
| 5107 | { |
| 5108 | int r = 0; |
| 5109 | struct wcd9xxx *core = dev_get_drvdata(tabla->codec->dev->parent); |
| 5110 | |
| 5111 | if (cancel_delayed_work_sync(&tabla->mbhc_btn_dwork)) { |
| 5112 | /* if scheduled mbhc_btn_dwork is canceled from here, |
| 5113 | * we have to unlock from here instead btn_work */ |
| 5114 | wcd9xxx_unlock_sleep(core); |
| 5115 | r = 1; |
| 5116 | } |
| 5117 | return r; |
| 5118 | } |
| 5119 | |
| 5120 | /* called under codec_resource_lock acquisition */ |
| 5121 | void tabla_set_and_turnoff_hph_padac(struct snd_soc_codec *codec) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5122 | { |
| 5123 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5124 | u8 wg_time; |
| 5125 | |
| 5126 | wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ; |
| 5127 | wg_time += 1; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5128 | |
| 5129 | /* If headphone PA is on, check if userspace receives |
| 5130 | * removal event to sync-up PA's state */ |
| 5131 | if (tabla_is_hph_pa_on(codec)) { |
| 5132 | pr_debug("%s PA is on, setting PA_OFF_ACK\n", __func__); |
| 5133 | set_bit(TABLA_HPHL_PA_OFF_ACK, &tabla->hph_pa_dac_state); |
| 5134 | set_bit(TABLA_HPHR_PA_OFF_ACK, &tabla->hph_pa_dac_state); |
| 5135 | } else { |
| 5136 | pr_debug("%s PA is off\n", __func__); |
| 5137 | } |
| 5138 | |
| 5139 | if (tabla_is_hph_dac_on(codec, 1)) |
| 5140 | set_bit(TABLA_HPHL_DAC_OFF_ACK, &tabla->hph_pa_dac_state); |
| 5141 | if (tabla_is_hph_dac_on(codec, 0)) |
| 5142 | set_bit(TABLA_HPHR_DAC_OFF_ACK, &tabla->hph_pa_dac_state); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5143 | |
| 5144 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00); |
| 5145 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_DAC_CTL, |
| 5146 | 0xC0, 0x00); |
| 5147 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_DAC_CTL, |
| 5148 | 0xC0, 0x00); |
| 5149 | usleep_range(wg_time * 1000, wg_time * 1000); |
| 5150 | } |
| 5151 | |
| 5152 | static void tabla_clr_and_turnon_hph_padac(struct tabla_priv *tabla) |
| 5153 | { |
| 5154 | bool pa_turned_on = false; |
| 5155 | struct snd_soc_codec *codec = tabla->codec; |
| 5156 | u8 wg_time; |
| 5157 | |
| 5158 | wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ; |
| 5159 | wg_time += 1; |
| 5160 | |
| 5161 | if (test_and_clear_bit(TABLA_HPHR_DAC_OFF_ACK, |
| 5162 | &tabla->hph_pa_dac_state)) { |
| 5163 | pr_debug("%s: HPHR clear flag and enable DAC\n", __func__); |
| 5164 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_R_DAC_CTL, |
| 5165 | 0xC0, 0xC0); |
| 5166 | } |
| 5167 | if (test_and_clear_bit(TABLA_HPHL_DAC_OFF_ACK, |
| 5168 | &tabla->hph_pa_dac_state)) { |
| 5169 | pr_debug("%s: HPHL clear flag and enable DAC\n", __func__); |
| 5170 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_L_DAC_CTL, |
| 5171 | 0xC0, 0xC0); |
| 5172 | } |
| 5173 | |
| 5174 | if (test_and_clear_bit(TABLA_HPHR_PA_OFF_ACK, |
| 5175 | &tabla->hph_pa_dac_state)) { |
| 5176 | pr_debug("%s: HPHR clear flag and enable PA\n", __func__); |
| 5177 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x10, |
| 5178 | 1 << 4); |
| 5179 | pa_turned_on = true; |
| 5180 | } |
| 5181 | if (test_and_clear_bit(TABLA_HPHL_PA_OFF_ACK, |
| 5182 | &tabla->hph_pa_dac_state)) { |
| 5183 | pr_debug("%s: HPHL clear flag and enable PA\n", __func__); |
| 5184 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x20, |
| 5185 | 1 << 5); |
| 5186 | pa_turned_on = true; |
| 5187 | } |
| 5188 | |
| 5189 | if (pa_turned_on) { |
| 5190 | pr_debug("%s: PA was turned off by MBHC and not by DAPM\n", |
| 5191 | __func__); |
| 5192 | usleep_range(wg_time * 1000, wg_time * 1000); |
| 5193 | } |
| 5194 | } |
| 5195 | |
| 5196 | /* called under codec_resource_lock acquisition */ |
| 5197 | static void tabla_codec_report_plug(struct snd_soc_codec *codec, int insertion, |
| 5198 | enum snd_jack_types jack_type) |
| 5199 | { |
| 5200 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 5201 | |
| 5202 | if (!insertion) { |
| 5203 | /* Report removal */ |
| 5204 | tabla->hph_status &= ~jack_type; |
| 5205 | if (tabla->mbhc_cfg.headset_jack) { |
| 5206 | /* cancel possibly scheduled btn work and |
| 5207 | * report release if we reported button press */ |
| 5208 | if (tabla_cancel_btn_work(tabla)) { |
| 5209 | pr_debug("%s: button press is canceled\n", |
| 5210 | __func__); |
| 5211 | } else if (tabla->buttons_pressed) { |
| 5212 | pr_debug("%s: Reporting release for reported " |
| 5213 | "button press %d\n", __func__, |
| 5214 | jack_type); |
| 5215 | tabla_snd_soc_jack_report(tabla, |
| 5216 | tabla->mbhc_cfg.button_jack, 0, |
| 5217 | tabla->buttons_pressed); |
| 5218 | tabla->buttons_pressed &= |
| 5219 | ~TABLA_JACK_BUTTON_MASK; |
| 5220 | } |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 5221 | pr_debug("%s: Reporting removal %d(%x)\n", __func__, |
| 5222 | jack_type, tabla->hph_status); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5223 | tabla_snd_soc_jack_report(tabla, |
| 5224 | tabla->mbhc_cfg.headset_jack, |
| 5225 | tabla->hph_status, |
| 5226 | TABLA_JACK_MASK); |
| 5227 | } |
| 5228 | tabla_set_and_turnoff_hph_padac(codec); |
| 5229 | hphocp_off_report(tabla, SND_JACK_OC_HPHR, |
| 5230 | TABLA_IRQ_HPH_PA_OCPR_FAULT); |
| 5231 | hphocp_off_report(tabla, SND_JACK_OC_HPHL, |
| 5232 | TABLA_IRQ_HPH_PA_OCPL_FAULT); |
| 5233 | tabla->current_plug = PLUG_TYPE_NONE; |
| 5234 | tabla->mbhc_polling_active = false; |
| 5235 | } else { |
| 5236 | /* Report insertion */ |
| 5237 | tabla->hph_status |= jack_type; |
| 5238 | |
| 5239 | if (jack_type == SND_JACK_HEADPHONE) |
| 5240 | tabla->current_plug = PLUG_TYPE_HEADPHONE; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 5241 | else if (jack_type == SND_JACK_UNSUPPORTED) |
| 5242 | tabla->current_plug = PLUG_TYPE_GND_MIC_SWAP; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5243 | else if (jack_type == SND_JACK_HEADSET) { |
| 5244 | tabla->mbhc_polling_active = true; |
| 5245 | tabla->current_plug = PLUG_TYPE_HEADSET; |
| 5246 | } |
| 5247 | if (tabla->mbhc_cfg.headset_jack) { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 5248 | pr_debug("%s: Reporting insertion %d(%x)\n", __func__, |
| 5249 | jack_type, tabla->hph_status); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5250 | tabla_snd_soc_jack_report(tabla, |
| 5251 | tabla->mbhc_cfg.headset_jack, |
| 5252 | tabla->hph_status, |
| 5253 | TABLA_JACK_MASK); |
| 5254 | } |
| 5255 | tabla_clr_and_turnon_hph_padac(tabla); |
| 5256 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5257 | } |
| 5258 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5259 | static int tabla_codec_enable_hs_detect(struct snd_soc_codec *codec, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5260 | int insertion, int trigger, |
| 5261 | bool padac_off) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5262 | { |
| 5263 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5264 | int central_bias_enabled = 0; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5265 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5266 | TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5267 | const struct tabla_mbhc_plug_detect_cfg *plug_det = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5268 | TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5269 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5270 | if (!tabla->mbhc_cfg.calibration) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5271 | pr_err("Error, no tabla calibration\n"); |
| 5272 | return -EINVAL; |
| 5273 | } |
| 5274 | |
| 5275 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0); |
| 5276 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5277 | /* Make sure mic bias and Mic line schmitt trigger |
| 5278 | * are turned OFF |
| 5279 | */ |
| 5280 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01); |
| 5281 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 5282 | |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5283 | if (insertion) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5284 | tabla_codec_switch_micbias(codec, 0); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5285 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5286 | /* DAPM can manipulate PA/DAC bits concurrently */ |
| 5287 | if (padac_off == true) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5288 | tabla_set_and_turnoff_hph_padac(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5289 | } |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5290 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5291 | if (trigger & MBHC_USE_HPHL_TRIGGER) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5292 | /* Enable HPH Schmitt Trigger */ |
| 5293 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x11, |
| 5294 | 0x11); |
| 5295 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x0C, |
| 5296 | plug_det->hph_current << 2); |
| 5297 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x02, |
| 5298 | 0x02); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5299 | } |
| 5300 | if (trigger & MBHC_USE_MB_TRIGGER) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5301 | /* enable the mic line schmitt trigger */ |
| 5302 | snd_soc_update_bits(codec, |
| 5303 | tabla->mbhc_bias_regs.mbhc_reg, |
| 5304 | 0x60, plug_det->mic_current << 5); |
| 5305 | snd_soc_update_bits(codec, |
| 5306 | tabla->mbhc_bias_regs.mbhc_reg, |
| 5307 | 0x80, 0x80); |
| 5308 | usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid); |
| 5309 | snd_soc_update_bits(codec, |
| 5310 | tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 5311 | 0x00); |
| 5312 | snd_soc_update_bits(codec, |
| 5313 | tabla->mbhc_bias_regs.mbhc_reg, |
| 5314 | 0x10, 0x10); |
| 5315 | } |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5316 | |
| 5317 | /* setup for insetion detection */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5318 | 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] | 5319 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5320 | pr_debug("setup for removal detection\n"); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5321 | /* Make sure the HPH schmitt trigger is OFF */ |
| 5322 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x12, 0x00); |
| 5323 | |
| 5324 | /* enable the mic line schmitt trigger */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5325 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, |
| 5326 | 0x01, 0x00); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5327 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x60, |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5328 | plug_det->mic_current << 5); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5329 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 5330 | 0x80, 0x80); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5331 | usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5332 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 5333 | 0x10, 0x10); |
| 5334 | |
| 5335 | /* Setup for low power removal detection */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5336 | 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] | 5337 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5338 | |
| 5339 | if (snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x4) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5340 | /* called called by interrupt */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5341 | if (!(tabla->clock_active)) { |
| 5342 | tabla_codec_enable_config_mode(codec, 1); |
| 5343 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5344 | 0x06, 0); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5345 | usleep_range(generic->t_shutdown_plug_rem, |
| 5346 | generic->t_shutdown_plug_rem); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5347 | tabla_codec_enable_config_mode(codec, 0); |
| 5348 | } else |
| 5349 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5350 | 0x06, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5351 | } |
| 5352 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 5353 | 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] | 5354 | |
| 5355 | /* If central bandgap disabled */ |
| 5356 | if (!(snd_soc_read(codec, TABLA_A_PIN_CTL_OE1) & 1)) { |
| 5357 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x3, 0x3); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5358 | usleep_range(generic->t_bg_fast_settle, |
| 5359 | generic->t_bg_fast_settle); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5360 | central_bias_enabled = 1; |
| 5361 | } |
| 5362 | |
| 5363 | /* If LDO_H disabled */ |
| 5364 | if (snd_soc_read(codec, TABLA_A_PIN_CTL_OE0) & 0x80) { |
| 5365 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x10, 0); |
| 5366 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0x80); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5367 | usleep_range(generic->t_ldoh, generic->t_ldoh); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5368 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0); |
| 5369 | |
| 5370 | if (central_bias_enabled) |
| 5371 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x1, 0); |
| 5372 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5373 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 5374 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x3, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5375 | tabla->mbhc_cfg.micbias); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5376 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5377 | wcd9xxx_enable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5378 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0x1); |
| 5379 | return 0; |
| 5380 | } |
| 5381 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5382 | static u16 tabla_codec_v_sta_dce(struct snd_soc_codec *codec, bool dce, |
| 5383 | s16 vin_mv) |
| 5384 | { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5385 | struct tabla_priv *tabla; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5386 | s16 diff, zero; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5387 | u32 mb_mv, in; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5388 | u16 value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5389 | |
| 5390 | tabla = snd_soc_codec_get_drvdata(codec); |
| 5391 | mb_mv = tabla->mbhc_data.micb_mv; |
| 5392 | |
| 5393 | if (mb_mv == 0) { |
| 5394 | pr_err("%s: Mic Bias voltage is set to zero\n", __func__); |
| 5395 | return -EINVAL; |
| 5396 | } |
| 5397 | |
| 5398 | if (dce) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5399 | diff = (tabla->mbhc_data.dce_mb) - (tabla->mbhc_data.dce_z); |
| 5400 | zero = (tabla->mbhc_data.dce_z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5401 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5402 | diff = (tabla->mbhc_data.sta_mb) - (tabla->mbhc_data.sta_z); |
| 5403 | zero = (tabla->mbhc_data.sta_z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5404 | } |
| 5405 | in = (u32) diff * vin_mv; |
| 5406 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5407 | value = (u16) (in / mb_mv) + zero; |
| 5408 | return value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5409 | } |
| 5410 | |
| 5411 | static s32 tabla_codec_sta_dce_v(struct snd_soc_codec *codec, s8 dce, |
| 5412 | u16 bias_value) |
| 5413 | { |
| 5414 | struct tabla_priv *tabla; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5415 | s16 value, z, mb; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5416 | s32 mv; |
| 5417 | |
| 5418 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5419 | value = bias_value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5420 | if (dce) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5421 | z = (tabla->mbhc_data.dce_z); |
| 5422 | mb = (tabla->mbhc_data.dce_mb); |
| 5423 | mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5424 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5425 | z = (tabla->mbhc_data.sta_z); |
| 5426 | mb = (tabla->mbhc_data.sta_mb); |
| 5427 | mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5428 | } |
| 5429 | |
| 5430 | return mv; |
| 5431 | } |
| 5432 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5433 | static void btn_lpress_fn(struct work_struct *work) |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5434 | { |
| 5435 | struct delayed_work *delayed_work; |
| 5436 | struct tabla_priv *tabla; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5437 | short bias_value; |
| 5438 | int dce_mv, sta_mv; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5439 | struct wcd9xxx *core; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5440 | |
| 5441 | pr_debug("%s:\n", __func__); |
| 5442 | |
| 5443 | delayed_work = to_delayed_work(work); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5444 | tabla = container_of(delayed_work, struct tabla_priv, mbhc_btn_dwork); |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 5445 | core = dev_get_drvdata(tabla->codec->dev->parent); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5446 | |
| 5447 | if (tabla) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5448 | if (tabla->mbhc_cfg.button_jack) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5449 | bias_value = tabla_codec_read_sta_result(tabla->codec); |
| 5450 | sta_mv = tabla_codec_sta_dce_v(tabla->codec, 0, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5451 | bias_value); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5452 | bias_value = tabla_codec_read_dce_result(tabla->codec); |
| 5453 | dce_mv = tabla_codec_sta_dce_v(tabla->codec, 1, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5454 | bias_value); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5455 | pr_debug("%s: Reporting long button press event" |
| 5456 | " STA: %d, DCE: %d\n", __func__, |
| 5457 | sta_mv, dce_mv); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5458 | tabla_snd_soc_jack_report(tabla, |
| 5459 | tabla->mbhc_cfg.button_jack, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5460 | tabla->buttons_pressed, |
| 5461 | tabla->buttons_pressed); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5462 | } |
| 5463 | } else { |
| 5464 | pr_err("%s: Bad tabla private data\n", __func__); |
| 5465 | } |
| 5466 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5467 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5468 | wcd9xxx_unlock_sleep(core); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5469 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 5470 | |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 5471 | static u16 tabla_get_cfilt_reg(struct snd_soc_codec *codec, u8 cfilt) |
| 5472 | { |
| 5473 | u16 reg; |
| 5474 | |
| 5475 | switch (cfilt) { |
| 5476 | case TABLA_CFILT1_SEL: |
| 5477 | reg = TABLA_A_MICB_CFILT_1_CTL; |
| 5478 | break; |
| 5479 | case TABLA_CFILT2_SEL: |
| 5480 | reg = TABLA_A_MICB_CFILT_2_CTL; |
| 5481 | break; |
| 5482 | case TABLA_CFILT3_SEL: |
| 5483 | reg = TABLA_A_MICB_CFILT_3_CTL; |
| 5484 | break; |
| 5485 | default: |
| 5486 | BUG(); |
| 5487 | } |
| 5488 | return reg; |
| 5489 | } |
| 5490 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5491 | void tabla_mbhc_cal(struct snd_soc_codec *codec) |
| 5492 | { |
| 5493 | struct tabla_priv *tabla; |
| 5494 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 5495 | u8 cfilt_mode, micbias2_cfilt_mode, bg_mode; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5496 | u8 ncic, nmeas, navg; |
| 5497 | u32 mclk_rate; |
| 5498 | u32 dce_wait, sta_wait; |
| 5499 | u8 *n_cic; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5500 | void *calibration; |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 5501 | u16 bias2_ctl; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5502 | |
| 5503 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5504 | calibration = tabla->mbhc_cfg.calibration; |
| 5505 | |
| 5506 | wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL); |
| 5507 | tabla_turn_onoff_rel_detection(codec, false); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5508 | |
| 5509 | /* First compute the DCE / STA wait times |
| 5510 | * depending on tunable parameters. |
| 5511 | * The value is computed in microseconds |
| 5512 | */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5513 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5514 | 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] | 5515 | ncic = n_cic[tabla_codec_mclk_index(tabla)]; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5516 | nmeas = TABLA_MBHC_CAL_BTN_DET_PTR(calibration)->n_meas; |
| 5517 | navg = TABLA_MBHC_CAL_GENERAL_PTR(calibration)->mbhc_navg; |
| 5518 | mclk_rate = tabla->mbhc_cfg.mclk_rate; |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 5519 | dce_wait = (1000 * 512 * ncic * (nmeas + 1)) / (mclk_rate / 1000); |
| 5520 | sta_wait = (1000 * 128 * (navg + 1)) / (mclk_rate / 1000); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5521 | |
| 5522 | tabla->mbhc_data.t_dce = dce_wait; |
| 5523 | tabla->mbhc_data.t_sta = sta_wait; |
| 5524 | |
| 5525 | /* LDOH and CFILT are already configured during pdata handling. |
| 5526 | * Only need to make sure CFILT and bandgap are in Fast mode. |
| 5527 | * Need to restore defaults once calculation is done. |
| 5528 | */ |
| 5529 | cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl); |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 5530 | micbias2_cfilt_mode = |
| 5531 | snd_soc_read(codec, tabla_get_cfilt_reg(codec, |
| 5532 | tabla->pdata->micbias.bias2_cfilt_sel)); |
| 5533 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 5534 | TABLA_CFILT_FAST_MODE); |
| 5535 | snd_soc_update_bits(codec, |
| 5536 | tabla_get_cfilt_reg(codec, |
| 5537 | tabla->pdata->micbias.bias2_cfilt_sel), |
| 5538 | 0x40, TABLA_CFILT_FAST_MODE); |
| 5539 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5540 | bg_mode = snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, |
| 5541 | 0x02); |
| 5542 | |
| 5543 | /* Micbias, CFILT, LDOH, MBHC MUX mode settings |
| 5544 | * to perform ADC calibration |
| 5545 | */ |
| 5546 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x60, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5547 | tabla->mbhc_cfg.micbias << 5); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5548 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
| 5549 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x60, 0x60); |
| 5550 | snd_soc_write(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x78); |
| 5551 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x04); |
| 5552 | |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 5553 | /* MICBIAS2 routing for calibration */ |
| 5554 | bias2_ctl = snd_soc_read(codec, TABLA_A_MICB_2_CTL); |
| 5555 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, TABLA_MICBIAS2); |
| 5556 | snd_soc_write(codec, TABLA_A_MICB_2_CTL, |
| 5557 | snd_soc_read(codec, tabla->mbhc_bias_regs.ctl_reg)); |
| 5558 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5559 | /* DCE measurement for 0 volts */ |
| 5560 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 5561 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 5562 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5563 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81); |
| 5564 | usleep_range(100, 100); |
| 5565 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 5566 | usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce); |
| 5567 | tabla->mbhc_data.dce_z = tabla_codec_read_dce_result(codec); |
| 5568 | |
| 5569 | /* DCE measurment for MB voltage */ |
| 5570 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 5571 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
| 5572 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82); |
| 5573 | usleep_range(100, 100); |
| 5574 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 5575 | usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce); |
| 5576 | tabla->mbhc_data.dce_mb = tabla_codec_read_dce_result(codec); |
| 5577 | |
| 5578 | /* Sta measuremnt for 0 volts */ |
| 5579 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 5580 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 5581 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5582 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81); |
| 5583 | usleep_range(100, 100); |
| 5584 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 5585 | usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta); |
| 5586 | tabla->mbhc_data.sta_z = tabla_codec_read_sta_result(codec); |
| 5587 | |
| 5588 | /* STA Measurement for MB Voltage */ |
| 5589 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82); |
| 5590 | usleep_range(100, 100); |
| 5591 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 5592 | usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta); |
| 5593 | tabla->mbhc_data.sta_mb = tabla_codec_read_sta_result(codec); |
| 5594 | |
| 5595 | /* Restore default settings. */ |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 5596 | snd_soc_write(codec, TABLA_A_MICB_2_CTL, bias2_ctl); |
| 5597 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, |
| 5598 | tabla->mbhc_cfg.micbias); |
| 5599 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5600 | 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] | 5601 | snd_soc_update_bits(codec, |
| 5602 | tabla_get_cfilt_reg(codec, |
| 5603 | tabla->pdata->micbias.bias2_cfilt_sel), 0x40, |
| 5604 | micbias2_cfilt_mode); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5605 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 5606 | cfilt_mode); |
| 5607 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, bg_mode); |
| 5608 | |
| 5609 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
| 5610 | usleep_range(100, 100); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5611 | |
| 5612 | wcd9xxx_enable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL); |
| 5613 | tabla_turn_onoff_rel_detection(codec, true); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5614 | } |
| 5615 | |
| 5616 | void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg* btn_det, |
| 5617 | const enum tabla_mbhc_btn_det_mem mem) |
| 5618 | { |
| 5619 | void *ret = &btn_det->_v_btn_low; |
| 5620 | |
| 5621 | switch (mem) { |
| 5622 | case TABLA_BTN_DET_GAIN: |
| 5623 | ret += sizeof(btn_det->_n_cic); |
| 5624 | case TABLA_BTN_DET_N_CIC: |
| 5625 | ret += sizeof(btn_det->_n_ready); |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 5626 | case TABLA_BTN_DET_N_READY: |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5627 | ret += sizeof(btn_det->_v_btn_high[0]) * btn_det->num_btn; |
| 5628 | case TABLA_BTN_DET_V_BTN_HIGH: |
| 5629 | ret += sizeof(btn_det->_v_btn_low[0]) * btn_det->num_btn; |
| 5630 | case TABLA_BTN_DET_V_BTN_LOW: |
| 5631 | /* do nothing */ |
| 5632 | break; |
| 5633 | default: |
| 5634 | ret = NULL; |
| 5635 | } |
| 5636 | |
| 5637 | return ret; |
| 5638 | } |
| 5639 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5640 | static s16 tabla_scale_v_micb_vddio(struct tabla_priv *tabla, int v, |
| 5641 | bool tovddio) |
| 5642 | { |
| 5643 | int r; |
| 5644 | int vddio_k, mb_k; |
| 5645 | vddio_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v, |
| 5646 | VDDIO_MICBIAS_MV); |
| 5647 | mb_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v, |
| 5648 | tabla->mbhc_data.micb_mv); |
| 5649 | if (tovddio) |
| 5650 | r = v * vddio_k / mb_k; |
| 5651 | else |
| 5652 | r = v * mb_k / vddio_k; |
| 5653 | return r; |
| 5654 | } |
| 5655 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5656 | static void tabla_mbhc_calc_thres(struct snd_soc_codec *codec) |
| 5657 | { |
| 5658 | struct tabla_priv *tabla; |
| 5659 | s16 btn_mv = 0, btn_delta_mv; |
| 5660 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 5661 | struct tabla_mbhc_plug_type_cfg *plug_type; |
| 5662 | u16 *btn_high; |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 5663 | u8 *n_ready; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5664 | int i; |
| 5665 | |
| 5666 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5667 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 5668 | plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5669 | |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 5670 | 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] | 5671 | if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5672 | tabla->mbhc_data.npoll = 4; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5673 | tabla->mbhc_data.nbounce_wait = 30; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5674 | } else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5675 | tabla->mbhc_data.npoll = 7; |
| 5676 | tabla->mbhc_data.nbounce_wait = 23; |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 5677 | } |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5678 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5679 | tabla->mbhc_data.t_sta_dce = ((1000 * 256) / |
| 5680 | (tabla->mbhc_cfg.mclk_rate / 1000) * |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 5681 | n_ready[tabla_codec_mclk_index(tabla)]) + |
| 5682 | 10; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5683 | tabla->mbhc_data.v_ins_hu = |
| 5684 | tabla_codec_v_sta_dce(codec, STA, plug_type->v_hs_max); |
| 5685 | tabla->mbhc_data.v_ins_h = |
| 5686 | tabla_codec_v_sta_dce(codec, DCE, plug_type->v_hs_max); |
| 5687 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5688 | tabla->mbhc_data.v_inval_ins_low = TABLA_MBHC_FAKE_INSERT_LOW; |
| 5689 | if (tabla->mbhc_cfg.gpio) |
| 5690 | tabla->mbhc_data.v_inval_ins_high = |
| 5691 | TABLA_MBHC_FAKE_INSERT_HIGH; |
| 5692 | else |
| 5693 | tabla->mbhc_data.v_inval_ins_high = |
| 5694 | TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO; |
| 5695 | |
| 5696 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
| 5697 | tabla->mbhc_data.adj_v_hs_max = |
| 5698 | tabla_scale_v_micb_vddio(tabla, plug_type->v_hs_max, true); |
| 5699 | tabla->mbhc_data.adj_v_ins_hu = |
| 5700 | tabla_codec_v_sta_dce(codec, STA, |
| 5701 | tabla->mbhc_data.adj_v_hs_max); |
| 5702 | tabla->mbhc_data.adj_v_ins_h = |
| 5703 | tabla_codec_v_sta_dce(codec, DCE, |
| 5704 | tabla->mbhc_data.adj_v_hs_max); |
| 5705 | tabla->mbhc_data.v_inval_ins_low = |
| 5706 | tabla_scale_v_micb_vddio(tabla, |
| 5707 | tabla->mbhc_data.v_inval_ins_low, |
| 5708 | false); |
| 5709 | tabla->mbhc_data.v_inval_ins_high = |
| 5710 | tabla_scale_v_micb_vddio(tabla, |
| 5711 | tabla->mbhc_data.v_inval_ins_high, |
| 5712 | false); |
| 5713 | } |
| 5714 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5715 | btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_HIGH); |
| 5716 | for (i = 0; i < btn_det->num_btn; i++) |
| 5717 | btn_mv = btn_high[i] > btn_mv ? btn_high[i] : btn_mv; |
| 5718 | |
| 5719 | tabla->mbhc_data.v_b1_h = tabla_codec_v_sta_dce(codec, DCE, btn_mv); |
| 5720 | btn_delta_mv = btn_mv + btn_det->v_btn_press_delta_sta; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5721 | tabla->mbhc_data.v_b1_hu = |
| 5722 | tabla_codec_v_sta_dce(codec, STA, btn_delta_mv); |
| 5723 | |
| 5724 | btn_delta_mv = btn_mv + btn_det->v_btn_press_delta_cic; |
| 5725 | |
| 5726 | tabla->mbhc_data.v_b1_huc = |
| 5727 | tabla_codec_v_sta_dce(codec, DCE, btn_delta_mv); |
| 5728 | |
| 5729 | tabla->mbhc_data.v_brh = tabla->mbhc_data.v_b1_h; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5730 | tabla->mbhc_data.v_brl = TABLA_MBHC_BUTTON_MIN; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5731 | |
| 5732 | tabla->mbhc_data.v_no_mic = |
| 5733 | tabla_codec_v_sta_dce(codec, STA, plug_type->v_no_mic); |
| 5734 | } |
| 5735 | |
| 5736 | void tabla_mbhc_init(struct snd_soc_codec *codec) |
| 5737 | { |
| 5738 | struct tabla_priv *tabla; |
| 5739 | struct tabla_mbhc_general_cfg *generic; |
| 5740 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 5741 | int n; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5742 | u8 *n_cic, *gain; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5743 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5744 | |
| 5745 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5746 | generic = TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
| 5747 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5748 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5749 | for (n = 0; n < 8; n++) { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 5750 | if ((!TABLA_IS_1_X(tabla_core->version)) || n != 7) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5751 | snd_soc_update_bits(codec, |
| 5752 | TABLA_A_CDC_MBHC_FEATURE_B1_CFG, |
| 5753 | 0x07, n); |
| 5754 | snd_soc_write(codec, TABLA_A_CDC_MBHC_FEATURE_B2_CFG, |
| 5755 | btn_det->c[n]); |
| 5756 | } |
| 5757 | } |
| 5758 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x07, |
| 5759 | btn_det->nc); |
| 5760 | |
| 5761 | n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC); |
| 5762 | 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] | 5763 | n_cic[tabla_codec_mclk_index(tabla)]); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5764 | |
| 5765 | 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] | 5766 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x78, |
| 5767 | gain[tabla_codec_mclk_index(tabla)] << 3); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5768 | |
| 5769 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x70, |
| 5770 | generic->mbhc_nsa << 4); |
| 5771 | |
| 5772 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x0F, |
| 5773 | btn_det->n_meas); |
| 5774 | |
| 5775 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B5_CTL, generic->mbhc_navg); |
| 5776 | |
| 5777 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x80, 0x80); |
| 5778 | |
| 5779 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x78, |
| 5780 | btn_det->mbhc_nsc << 3); |
| 5781 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 5782 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x03, |
| 5783 | TABLA_MICBIAS2); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5784 | |
| 5785 | 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] | 5786 | |
| 5787 | 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] | 5788 | |
| 5789 | /* override mbhc's micbias */ |
| 5790 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, |
| 5791 | tabla->mbhc_cfg.micbias); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5792 | } |
| 5793 | |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 5794 | static bool tabla_mbhc_fw_validate(const struct firmware *fw) |
| 5795 | { |
| 5796 | u32 cfg_offset; |
| 5797 | struct tabla_mbhc_imped_detect_cfg *imped_cfg; |
| 5798 | struct tabla_mbhc_btn_detect_cfg *btn_cfg; |
| 5799 | |
| 5800 | if (fw->size < TABLA_MBHC_CAL_MIN_SIZE) |
| 5801 | return false; |
| 5802 | |
| 5803 | /* previous check guarantees that there is enough fw data up |
| 5804 | * to num_btn |
| 5805 | */ |
| 5806 | btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(fw->data); |
| 5807 | cfg_offset = (u32) ((void *) btn_cfg - (void *) fw->data); |
| 5808 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_BTN_SZ(btn_cfg))) |
| 5809 | return false; |
| 5810 | |
| 5811 | /* previous check guarantees that there is enough fw data up |
| 5812 | * to start of impedance detection configuration |
| 5813 | */ |
| 5814 | imped_cfg = TABLA_MBHC_CAL_IMPED_DET_PTR(fw->data); |
| 5815 | cfg_offset = (u32) ((void *) imped_cfg - (void *) fw->data); |
| 5816 | |
| 5817 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_MIN_SZ)) |
| 5818 | return false; |
| 5819 | |
| 5820 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_SZ(imped_cfg))) |
| 5821 | return false; |
| 5822 | |
| 5823 | return true; |
| 5824 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5825 | |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 5826 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5827 | static int tabla_determine_button(const struct tabla_priv *priv, |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 5828 | const s32 micmv) |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5829 | { |
| 5830 | s16 *v_btn_low, *v_btn_high; |
| 5831 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 5832 | int i, btn = -1; |
| 5833 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5834 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5835 | v_btn_low = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_LOW); |
| 5836 | v_btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5837 | TABLA_BTN_DET_V_BTN_HIGH); |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 5838 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5839 | for (i = 0; i < btn_det->num_btn; i++) { |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 5840 | if ((v_btn_low[i] <= micmv) && (v_btn_high[i] >= micmv)) { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5841 | btn = i; |
| 5842 | break; |
| 5843 | } |
| 5844 | } |
| 5845 | |
| 5846 | if (btn == -1) |
| 5847 | 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] | 5848 | __func__, micmv); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5849 | |
| 5850 | return btn; |
| 5851 | } |
| 5852 | |
| 5853 | static int tabla_get_button_mask(const int btn) |
| 5854 | { |
| 5855 | int mask = 0; |
| 5856 | switch (btn) { |
| 5857 | case 0: |
| 5858 | mask = SND_JACK_BTN_0; |
| 5859 | break; |
| 5860 | case 1: |
| 5861 | mask = SND_JACK_BTN_1; |
| 5862 | break; |
| 5863 | case 2: |
| 5864 | mask = SND_JACK_BTN_2; |
| 5865 | break; |
| 5866 | case 3: |
| 5867 | mask = SND_JACK_BTN_3; |
| 5868 | break; |
| 5869 | case 4: |
| 5870 | mask = SND_JACK_BTN_4; |
| 5871 | break; |
| 5872 | case 5: |
| 5873 | mask = SND_JACK_BTN_5; |
| 5874 | break; |
| 5875 | case 6: |
| 5876 | mask = SND_JACK_BTN_6; |
| 5877 | break; |
| 5878 | case 7: |
| 5879 | mask = SND_JACK_BTN_7; |
| 5880 | break; |
| 5881 | } |
| 5882 | return mask; |
| 5883 | } |
| 5884 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5885 | static irqreturn_t tabla_dce_handler(int irq, void *data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5886 | { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5887 | int i, mask; |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 5888 | short dce, sta; |
| 5889 | s32 mv, mv_s, stamv_s; |
| 5890 | bool vddio; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5891 | int btn = -1, meas = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5892 | struct tabla_priv *priv = data; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5893 | const struct tabla_mbhc_btn_detect_cfg *d = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5894 | TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5895 | short btnmeas[d->n_btn_meas + 1]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5896 | struct snd_soc_codec *codec = priv->codec; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5897 | struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5898 | int n_btn_meas = d->n_btn_meas; |
| 5899 | 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] | 5900 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5901 | pr_debug("%s: enter\n", __func__); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5902 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5903 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 5904 | if (priv->mbhc_state == MBHC_STATE_POTENTIAL_RECOVERY) { |
| 5905 | pr_debug("%s: mbhc is being recovered, skip button press\n", |
| 5906 | __func__); |
| 5907 | goto done; |
| 5908 | } |
| 5909 | |
| 5910 | priv->mbhc_state = MBHC_STATE_POTENTIAL; |
| 5911 | |
| 5912 | if (!priv->mbhc_polling_active) { |
| 5913 | pr_warn("%s: mbhc polling is not active, skip button press\n", |
| 5914 | __func__); |
| 5915 | goto done; |
| 5916 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5917 | |
| 5918 | dce = tabla_codec_read_dce_result(codec); |
| 5919 | mv = tabla_codec_sta_dce_v(codec, 1, dce); |
| 5920 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5921 | /* If GPIO interrupt already kicked in, ignore button press */ |
| 5922 | if (priv->in_gpio_handler) { |
| 5923 | pr_debug("%s: GPIO State Changed, ignore button press\n", |
| 5924 | __func__); |
| 5925 | btn = -1; |
| 5926 | goto done; |
| 5927 | } |
| 5928 | |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 5929 | vddio = (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
| 5930 | priv->mbhc_micbias_switched); |
| 5931 | mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv; |
| 5932 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5933 | if (mbhc_status != TABLA_MBHC_STATUS_REL_DETECTION) { |
| 5934 | if (priv->mbhc_last_resume && |
| 5935 | !time_after(jiffies, priv->mbhc_last_resume + HZ)) { |
| 5936 | pr_debug("%s: Button is already released shortly after " |
| 5937 | "resume\n", __func__); |
| 5938 | n_btn_meas = 0; |
| 5939 | } else { |
| 5940 | pr_debug("%s: Button is already released without " |
| 5941 | "resume", __func__); |
| 5942 | sta = tabla_codec_read_sta_result(codec); |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 5943 | stamv_s = tabla_codec_sta_dce_v(codec, 0, sta); |
| 5944 | if (vddio) |
| 5945 | stamv_s = tabla_scale_v_micb_vddio(priv, |
| 5946 | stamv_s, |
| 5947 | false); |
| 5948 | btn = tabla_determine_button(priv, mv_s); |
| 5949 | if (btn != tabla_determine_button(priv, stamv_s)) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5950 | btn = -1; |
| 5951 | goto done; |
| 5952 | } |
| 5953 | } |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5954 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5955 | /* determine pressed button */ |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 5956 | btnmeas[meas++] = tabla_determine_button(priv, mv_s); |
| 5957 | pr_debug("%s: meas %d - DCE %d,%d,%d button %d\n", __func__, |
| 5958 | meas - 1, dce, mv, mv_s, btnmeas[meas - 1]); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5959 | if (n_btn_meas == 0) |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5960 | btn = btnmeas[0]; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5961 | for (; ((d->n_btn_meas) && (meas < (d->n_btn_meas + 1))); meas++) { |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 5962 | dce = tabla_codec_sta_dce(codec, 1, false); |
| 5963 | mv = tabla_codec_sta_dce_v(codec, 1, dce); |
| 5964 | mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv; |
| 5965 | |
| 5966 | btnmeas[meas] = tabla_determine_button(priv, mv_s); |
| 5967 | pr_debug("%s: meas %d - DCE %d,%d,%d button %d\n", |
| 5968 | __func__, meas, dce, mv, mv_s, btnmeas[meas]); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5969 | /* if large enough measurements are collected, |
| 5970 | * start to check if last all n_btn_con measurements were |
| 5971 | * in same button low/high range */ |
| 5972 | if (meas + 1 >= d->n_btn_con) { |
| 5973 | for (i = 0; i < d->n_btn_con; i++) |
| 5974 | if ((btnmeas[meas] < 0) || |
| 5975 | (btnmeas[meas] != btnmeas[meas - i])) |
| 5976 | break; |
| 5977 | if (i == d->n_btn_con) { |
| 5978 | /* button pressed */ |
| 5979 | btn = btnmeas[meas]; |
| 5980 | break; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5981 | } else if ((n_btn_meas - meas) < (d->n_btn_con - 1)) { |
| 5982 | /* if left measurements are less than n_btn_con, |
| 5983 | * it's impossible to find button number */ |
| 5984 | break; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5985 | } |
| 5986 | } |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 5987 | } |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5988 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5989 | if (btn >= 0) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5990 | if (priv->in_gpio_handler) { |
| 5991 | pr_debug("%s: GPIO already triggered, ignore button " |
| 5992 | "press\n", __func__); |
| 5993 | goto done; |
| 5994 | } |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5995 | mask = tabla_get_button_mask(btn); |
| 5996 | priv->buttons_pressed |= mask; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5997 | wcd9xxx_lock_sleep(core); |
| 5998 | if (schedule_delayed_work(&priv->mbhc_btn_dwork, |
| 5999 | msecs_to_jiffies(400)) == 0) { |
| 6000 | WARN(1, "Button pressed twice without release" |
| 6001 | "event\n"); |
| 6002 | wcd9xxx_unlock_sleep(core); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6003 | } |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6004 | } else { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6005 | pr_debug("%s: bogus button press, too short press?\n", |
| 6006 | __func__); |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6007 | } |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6008 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6009 | done: |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6010 | pr_debug("%s: leave\n", __func__); |
| 6011 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6012 | return IRQ_HANDLED; |
| 6013 | } |
| 6014 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6015 | static int tabla_is_fake_press(struct tabla_priv *priv) |
| 6016 | { |
| 6017 | int i; |
| 6018 | int r = 0; |
| 6019 | struct snd_soc_codec *codec = priv->codec; |
| 6020 | const int dces = MBHC_NUM_DCE_PLUG_DETECT; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6021 | s16 mb_v, v_ins_hu, v_ins_h; |
| 6022 | |
| 6023 | v_ins_hu = tabla_get_current_v_ins(priv, true); |
| 6024 | v_ins_h = tabla_get_current_v_ins(priv, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6025 | |
| 6026 | for (i = 0; i < dces; i++) { |
| 6027 | usleep_range(10000, 10000); |
| 6028 | if (i == 0) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6029 | mb_v = tabla_codec_sta_dce(codec, 0, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6030 | pr_debug("%s: STA[0]: %d,%d\n", __func__, mb_v, |
| 6031 | tabla_codec_sta_dce_v(codec, 0, mb_v)); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6032 | if (mb_v < (s16)priv->mbhc_data.v_b1_hu || |
| 6033 | mb_v > v_ins_hu) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6034 | r = 1; |
| 6035 | break; |
| 6036 | } |
| 6037 | } else { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6038 | mb_v = tabla_codec_sta_dce(codec, 1, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6039 | pr_debug("%s: DCE[%d]: %d,%d\n", __func__, i, mb_v, |
| 6040 | tabla_codec_sta_dce_v(codec, 1, mb_v)); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6041 | if (mb_v < (s16)priv->mbhc_data.v_b1_h || |
| 6042 | mb_v > v_ins_h) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6043 | r = 1; |
| 6044 | break; |
| 6045 | } |
| 6046 | } |
| 6047 | } |
| 6048 | |
| 6049 | return r; |
| 6050 | } |
| 6051 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6052 | static irqreturn_t tabla_release_handler(int irq, void *data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6053 | { |
Joonwoo Park | e5d3aa9 | 2012-01-11 14:47:15 -0800 | [diff] [blame] | 6054 | int ret; |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6055 | struct tabla_priv *priv = data; |
| 6056 | struct snd_soc_codec *codec = priv->codec; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6057 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6058 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6059 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6060 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 6061 | priv->mbhc_state = MBHC_STATE_RELEASE; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6062 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6063 | tabla_codec_drive_v_to_micbias(codec, 10000); |
| 6064 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6065 | if (priv->buttons_pressed & TABLA_JACK_BUTTON_MASK) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6066 | ret = tabla_cancel_btn_work(priv); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6067 | if (ret == 0) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6068 | pr_debug("%s: Reporting long button release event\n", |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6069 | __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6070 | if (priv->mbhc_cfg.button_jack) |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 6071 | tabla_snd_soc_jack_report(priv, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6072 | priv->mbhc_cfg.button_jack, 0, |
| 6073 | priv->buttons_pressed); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6074 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6075 | if (tabla_is_fake_press(priv)) { |
| 6076 | pr_debug("%s: Fake button press interrupt\n", |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6077 | __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6078 | } else if (priv->mbhc_cfg.button_jack) { |
| 6079 | if (priv->in_gpio_handler) { |
| 6080 | pr_debug("%s: GPIO kicked in, ignore\n", |
| 6081 | __func__); |
| 6082 | } else { |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6083 | pr_debug("%s: Reporting short button " |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6084 | "press and release\n", |
| 6085 | __func__); |
| 6086 | tabla_snd_soc_jack_report(priv, |
| 6087 | priv->mbhc_cfg.button_jack, |
| 6088 | priv->buttons_pressed, |
| 6089 | priv->buttons_pressed); |
| 6090 | tabla_snd_soc_jack_report(priv, |
| 6091 | priv->mbhc_cfg.button_jack, 0, |
| 6092 | priv->buttons_pressed); |
| 6093 | } |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6094 | } |
| 6095 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6096 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6097 | priv->buttons_pressed &= ~TABLA_JACK_BUTTON_MASK; |
| 6098 | } |
| 6099 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6100 | tabla_codec_calibrate_hs_polling(codec); |
| 6101 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6102 | if (priv->mbhc_cfg.gpio) |
| 6103 | msleep(TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6104 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6105 | tabla_codec_start_hs_polling(codec); |
| 6106 | |
| 6107 | pr_debug("%s: leave\n", __func__); |
| 6108 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6109 | return IRQ_HANDLED; |
| 6110 | } |
| 6111 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6112 | static void tabla_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec) |
| 6113 | { |
| 6114 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6115 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6116 | TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6117 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 6118 | if (!tabla->mclk_enabled && !tabla->mbhc_polling_active) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6119 | tabla_codec_enable_config_mode(codec, 1); |
| 6120 | |
| 6121 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 6122 | 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] | 6123 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6124 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00); |
| 6125 | |
| 6126 | usleep_range(generic->t_shutdown_plug_rem, |
| 6127 | generic->t_shutdown_plug_rem); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6128 | |
| 6129 | 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] | 6130 | if (!tabla->mclk_enabled && !tabla->mbhc_polling_active) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6131 | tabla_codec_enable_config_mode(codec, 0); |
| 6132 | |
| 6133 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x00); |
| 6134 | } |
| 6135 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6136 | static void tabla_codec_cleanup_hs_polling(struct snd_soc_codec *codec) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6137 | { |
| 6138 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6139 | |
| 6140 | tabla_codec_shutdown_hs_removal_detect(codec); |
| 6141 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 6142 | if (!tabla->mclk_enabled) { |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 6143 | tabla_codec_disable_clock_block(codec); |
| 6144 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6145 | } |
| 6146 | |
| 6147 | tabla->mbhc_polling_active = false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6148 | tabla->mbhc_state = MBHC_STATE_NONE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6149 | } |
| 6150 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 6151 | static irqreturn_t tabla_hphl_ocp_irq(int irq, void *data) |
| 6152 | { |
| 6153 | struct tabla_priv *tabla = data; |
| 6154 | struct snd_soc_codec *codec; |
| 6155 | |
| 6156 | pr_info("%s: received HPHL OCP irq\n", __func__); |
| 6157 | |
| 6158 | if (tabla) { |
| 6159 | codec = tabla->codec; |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6160 | if (tabla->hphlocp_cnt++ < TABLA_OCP_ATTEMPT) { |
| 6161 | pr_info("%s: retry\n", __func__); |
| 6162 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 6163 | 0x00); |
| 6164 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 6165 | 0x10); |
| 6166 | } else { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6167 | wcd9xxx_disable_irq(codec->control_data, |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6168 | TABLA_IRQ_HPH_PA_OCPL_FAULT); |
| 6169 | tabla->hphlocp_cnt = 0; |
| 6170 | tabla->hph_status |= SND_JACK_OC_HPHL; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6171 | if (tabla->mbhc_cfg.headset_jack) |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6172 | tabla_snd_soc_jack_report(tabla, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6173 | tabla->mbhc_cfg.headset_jack, |
| 6174 | tabla->hph_status, |
| 6175 | TABLA_JACK_MASK); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 6176 | } |
| 6177 | } else { |
| 6178 | pr_err("%s: Bad tabla private data\n", __func__); |
| 6179 | } |
| 6180 | |
| 6181 | return IRQ_HANDLED; |
| 6182 | } |
| 6183 | |
| 6184 | static irqreturn_t tabla_hphr_ocp_irq(int irq, void *data) |
| 6185 | { |
| 6186 | struct tabla_priv *tabla = data; |
| 6187 | struct snd_soc_codec *codec; |
| 6188 | |
| 6189 | pr_info("%s: received HPHR OCP irq\n", __func__); |
| 6190 | |
| 6191 | if (tabla) { |
| 6192 | codec = tabla->codec; |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6193 | if (tabla->hphrocp_cnt++ < TABLA_OCP_ATTEMPT) { |
| 6194 | pr_info("%s: retry\n", __func__); |
| 6195 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 6196 | 0x00); |
| 6197 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 6198 | 0x10); |
| 6199 | } else { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6200 | wcd9xxx_disable_irq(codec->control_data, |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6201 | TABLA_IRQ_HPH_PA_OCPR_FAULT); |
| 6202 | tabla->hphrocp_cnt = 0; |
| 6203 | tabla->hph_status |= SND_JACK_OC_HPHR; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6204 | if (tabla->mbhc_cfg.headset_jack) |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6205 | tabla_snd_soc_jack_report(tabla, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6206 | tabla->mbhc_cfg.headset_jack, |
| 6207 | tabla->hph_status, |
| 6208 | TABLA_JACK_MASK); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 6209 | } |
| 6210 | } else { |
| 6211 | pr_err("%s: Bad tabla private data\n", __func__); |
| 6212 | } |
| 6213 | |
| 6214 | return IRQ_HANDLED; |
| 6215 | } |
| 6216 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6217 | static bool tabla_is_inval_ins_range(struct snd_soc_codec *codec, |
| 6218 | s32 mic_volt, bool highhph, bool *highv) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6219 | { |
| 6220 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6221 | bool invalid = false; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6222 | s16 v_hs_max; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6223 | |
| 6224 | /* Perform this check only when the high voltage headphone |
| 6225 | * needs to be considered as invalid |
| 6226 | */ |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6227 | v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6228 | *highv = mic_volt > v_hs_max; |
| 6229 | if (!highhph && *highv) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6230 | invalid = true; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6231 | else if (mic_volt < tabla->mbhc_data.v_inval_ins_high && |
| 6232 | (mic_volt > tabla->mbhc_data.v_inval_ins_low)) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6233 | invalid = true; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6234 | |
| 6235 | return invalid; |
| 6236 | } |
| 6237 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6238 | static bool tabla_is_inval_ins_delta(struct snd_soc_codec *codec, |
| 6239 | int mic_volt, int mic_volt_prev, |
| 6240 | int threshold) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6241 | { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6242 | return abs(mic_volt - mic_volt_prev) > threshold; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6243 | } |
| 6244 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6245 | /* called under codec_resource_lock acquisition */ |
| 6246 | void tabla_find_plug_and_report(struct snd_soc_codec *codec, |
| 6247 | enum tabla_mbhc_plug_type plug_type) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6248 | { |
| 6249 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6250 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6251 | if (plug_type == PLUG_TYPE_HEADPHONE && |
| 6252 | tabla->current_plug == PLUG_TYPE_NONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6253 | /* Nothing was reported previously |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6254 | * report a headphone or unsupported |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6255 | */ |
| 6256 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 6257 | tabla_codec_cleanup_hs_polling(codec); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6258 | } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
| 6259 | if (tabla->current_plug == PLUG_TYPE_HEADSET) |
| 6260 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET); |
| 6261 | else if (tabla->current_plug == PLUG_TYPE_HEADPHONE) |
| 6262 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE); |
| 6263 | |
| 6264 | tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED); |
| 6265 | tabla_codec_cleanup_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6266 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
| 6267 | /* If Headphone was reported previously, this will |
| 6268 | * only report the mic line |
| 6269 | */ |
| 6270 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
| 6271 | msleep(100); |
| 6272 | tabla_codec_start_hs_polling(codec); |
| 6273 | } else if (plug_type == PLUG_TYPE_HIGH_HPH) { |
| 6274 | if (tabla->current_plug == PLUG_TYPE_NONE) |
| 6275 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 6276 | tabla_codec_cleanup_hs_polling(codec); |
| 6277 | pr_debug("setup mic trigger for further detection\n"); |
| 6278 | tabla->lpi_enabled = true; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6279 | tabla_codec_enable_hs_detect(codec, 1, |
| 6280 | MBHC_USE_MB_TRIGGER | |
| 6281 | MBHC_USE_HPHL_TRIGGER, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6282 | false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6283 | } else { |
| 6284 | WARN(1, "Unexpected current plug_type %d, plug_type %d\n", |
| 6285 | tabla->current_plug, plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6286 | } |
| 6287 | } |
| 6288 | |
| 6289 | /* should be called under interrupt context that hold suspend */ |
| 6290 | static void tabla_schedule_hs_detect_plug(struct tabla_priv *tabla) |
| 6291 | { |
| 6292 | pr_debug("%s: scheduling tabla_hs_correct_gpio_plug\n", __func__); |
| 6293 | tabla->hs_detect_work_stop = false; |
| 6294 | wcd9xxx_lock_sleep(tabla->codec->control_data); |
| 6295 | schedule_work(&tabla->hs_correct_plug_work); |
| 6296 | } |
| 6297 | |
| 6298 | /* called under codec_resource_lock acquisition */ |
| 6299 | static void tabla_cancel_hs_detect_plug(struct tabla_priv *tabla) |
| 6300 | { |
| 6301 | pr_debug("%s: canceling hs_correct_plug_work\n", __func__); |
| 6302 | tabla->hs_detect_work_stop = true; |
| 6303 | wmb(); |
| 6304 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 6305 | if (cancel_work_sync(&tabla->hs_correct_plug_work)) { |
| 6306 | pr_debug("%s: hs_correct_plug_work is canceled\n", __func__); |
| 6307 | wcd9xxx_unlock_sleep(tabla->codec->control_data); |
| 6308 | } |
| 6309 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 6310 | } |
| 6311 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6312 | static bool tabla_hs_gpio_level_remove(struct tabla_priv *tabla) |
| 6313 | { |
| 6314 | return (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) != |
| 6315 | tabla->mbhc_cfg.gpio_level_insert); |
| 6316 | } |
| 6317 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6318 | /* called under codec_resource_lock acquisition */ |
| 6319 | static void tabla_codec_hphr_gnd_switch(struct snd_soc_codec *codec, bool on) |
| 6320 | { |
| 6321 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, on); |
| 6322 | if (on) |
| 6323 | usleep_range(5000, 5000); |
| 6324 | } |
| 6325 | |
| 6326 | /* called under codec_resource_lock acquisition and mbhc override = 1 */ |
| 6327 | static enum tabla_mbhc_plug_type |
| 6328 | tabla_codec_get_plug_type(struct snd_soc_codec *codec, bool highhph) |
| 6329 | { |
| 6330 | int i; |
| 6331 | bool gndswitch, vddioswitch; |
| 6332 | int scaled; |
| 6333 | struct tabla_mbhc_plug_type_cfg *plug_type_ptr; |
| 6334 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 6335 | int num_det = MBHC_NUM_DCE_PLUG_DETECT + 1; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6336 | enum tabla_mbhc_plug_type plug_type[num_det]; |
| 6337 | s16 mb_v[num_det]; |
| 6338 | s32 mic_mv[num_det]; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6339 | bool inval; |
| 6340 | bool highdelta; |
| 6341 | bool ahighv = false, highv; |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 6342 | bool gndmicswapped = false; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6343 | |
| 6344 | /* make sure override is on */ |
| 6345 | WARN_ON(!(snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04)); |
| 6346 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6347 | /* GND and MIC swap detection requires at least 2 rounds of DCE */ |
| 6348 | BUG_ON(num_det < 2); |
| 6349 | |
| 6350 | plug_type_ptr = |
| 6351 | TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 6352 | |
| 6353 | plug_type[0] = PLUG_TYPE_INVALID; |
| 6354 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6355 | /* performs DCEs for N times |
| 6356 | * 1st: check if voltage is in invalid range |
| 6357 | * 2nd - N-2nd: check voltage range and delta |
| 6358 | * N-1st: check voltage range, delta with HPHR GND switch |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 6359 | * Nth: check voltage range with VDDIO switch */ |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6360 | for (i = 0; i < num_det; i++) { |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 6361 | gndswitch = (i == (num_det - 2)); |
| 6362 | vddioswitch = (i == (num_det - 1)) || (i == (num_det - 2)); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6363 | if (i == 0) { |
| 6364 | mb_v[i] = tabla_codec_setup_hs_polling(codec); |
| 6365 | 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] | 6366 | inval = tabla_is_inval_ins_range(codec, mic_mv[i], |
| 6367 | highhph, &highv); |
| 6368 | ahighv |= highv; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6369 | scaled = mic_mv[i]; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6370 | } else { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6371 | if (vddioswitch) |
| 6372 | __tabla_codec_switch_micbias(tabla->codec, 1, |
| 6373 | false, false); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6374 | if (gndswitch) |
| 6375 | tabla_codec_hphr_gnd_switch(codec, true); |
| 6376 | mb_v[i] = __tabla_codec_sta_dce(codec, 1, true, true); |
| 6377 | 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] | 6378 | if (vddioswitch) |
| 6379 | scaled = tabla_scale_v_micb_vddio(tabla, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6380 | mic_mv[i], |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6381 | false); |
| 6382 | else |
| 6383 | scaled = mic_mv[i]; |
| 6384 | /* !gndswitch & vddioswitch means the previous DCE |
| 6385 | * was done with gndswitch, don't compare with DCE |
| 6386 | * with gndswitch */ |
| 6387 | highdelta = tabla_is_inval_ins_delta(codec, scaled, |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 6388 | mic_mv[i - 1], |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6389 | TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV); |
| 6390 | inval = (tabla_is_inval_ins_range(codec, mic_mv[i], |
| 6391 | highhph, &highv) || |
| 6392 | highdelta); |
| 6393 | ahighv |= highv; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6394 | if (gndswitch) |
| 6395 | tabla_codec_hphr_gnd_switch(codec, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6396 | if (vddioswitch) |
| 6397 | __tabla_codec_switch_micbias(tabla->codec, 0, |
| 6398 | false, false); |
| 6399 | /* claim UNSUPPORTED plug insertion when |
| 6400 | * good headset is detected but HPHR GND switch makes |
| 6401 | * delta difference */ |
| 6402 | if (i == (num_det - 2) && highdelta && !ahighv) |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 6403 | gndmicswapped = true; |
| 6404 | else if (i == (num_det - 1) && inval) { |
| 6405 | if (gndmicswapped) |
| 6406 | plug_type[0] = PLUG_TYPE_GND_MIC_SWAP; |
| 6407 | else |
| 6408 | plug_type[0] = PLUG_TYPE_INVALID; |
| 6409 | } |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6410 | } |
| 6411 | 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] | 6412 | "VDDIO %d, inval %d\n", __func__, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6413 | i + 1, mb_v[i] & 0xffff, mic_mv[i], scaled, gndswitch, |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6414 | vddioswitch, inval); |
| 6415 | /* don't need to run further DCEs */ |
| 6416 | if (ahighv && inval) |
| 6417 | break; |
| 6418 | mic_mv[i] = scaled; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6419 | } |
| 6420 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6421 | for (i = 0; (plug_type[0] != PLUG_TYPE_GND_MIC_SWAP && !inval) && |
| 6422 | i < num_det; i++) { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6423 | /* |
| 6424 | * If we are here, means none of the all |
| 6425 | * measurements are fake, continue plug type detection. |
| 6426 | * If all three measurements do not produce same |
| 6427 | * plug type, restart insertion detection |
| 6428 | */ |
| 6429 | if (mic_mv[i] < plug_type_ptr->v_no_mic) { |
| 6430 | plug_type[i] = PLUG_TYPE_HEADPHONE; |
| 6431 | pr_debug("%s: Detect attempt %d, detected Headphone\n", |
| 6432 | __func__, i); |
| 6433 | } else if (highhph && (mic_mv[i] > plug_type_ptr->v_hs_max)) { |
| 6434 | plug_type[i] = PLUG_TYPE_HIGH_HPH; |
| 6435 | pr_debug("%s: Detect attempt %d, detected High " |
| 6436 | "Headphone\n", __func__, i); |
| 6437 | } else { |
| 6438 | plug_type[i] = PLUG_TYPE_HEADSET; |
| 6439 | pr_debug("%s: Detect attempt %d, detected Headset\n", |
| 6440 | __func__, i); |
| 6441 | } |
| 6442 | |
| 6443 | if (i > 0 && (plug_type[i - 1] != plug_type[i])) { |
| 6444 | pr_err("%s: Detect attempt %d and %d are not same", |
| 6445 | __func__, i - 1, i); |
| 6446 | plug_type[0] = PLUG_TYPE_INVALID; |
| 6447 | inval = true; |
| 6448 | break; |
| 6449 | } |
| 6450 | } |
| 6451 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6452 | pr_debug("%s: Detected plug type %d\n", __func__, plug_type[0]); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6453 | return plug_type[0]; |
| 6454 | } |
| 6455 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6456 | static void tabla_hs_correct_gpio_plug(struct work_struct *work) |
| 6457 | { |
| 6458 | struct tabla_priv *tabla; |
| 6459 | struct snd_soc_codec *codec; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6460 | int retry = 0, pt_gnd_mic_swap_cnt = 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6461 | bool correction = false; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6462 | enum tabla_mbhc_plug_type plug_type; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6463 | unsigned long timeout; |
| 6464 | |
| 6465 | tabla = container_of(work, struct tabla_priv, hs_correct_plug_work); |
| 6466 | codec = tabla->codec; |
| 6467 | |
| 6468 | pr_debug("%s: enter\n", __func__); |
| 6469 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 6470 | |
| 6471 | /* Keep override on during entire plug type correction work. |
| 6472 | * |
| 6473 | * This is okay under the assumption that any GPIO irqs which use |
| 6474 | * MBHC block cancel and sync this work so override is off again |
| 6475 | * prior to GPIO interrupt handler's MBHC block usage. |
| 6476 | * Also while this correction work is running, we can guarantee |
| 6477 | * DAPM doesn't use any MBHC block as this work only runs with |
| 6478 | * headphone detection. |
| 6479 | */ |
| 6480 | tabla_turn_onoff_override(codec, true); |
| 6481 | |
| 6482 | timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS); |
| 6483 | while (!time_after(jiffies, timeout)) { |
| 6484 | ++retry; |
| 6485 | rmb(); |
| 6486 | if (tabla->hs_detect_work_stop) { |
| 6487 | pr_debug("%s: stop requested\n", __func__); |
| 6488 | break; |
| 6489 | } |
| 6490 | |
| 6491 | msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS); |
| 6492 | if (tabla_hs_gpio_level_remove(tabla)) { |
| 6493 | pr_debug("%s: GPIO value is low\n", __func__); |
| 6494 | break; |
| 6495 | } |
| 6496 | |
| 6497 | /* can race with removal interrupt */ |
| 6498 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6499 | plug_type = tabla_codec_get_plug_type(codec, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6500 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 6501 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6502 | if (plug_type == PLUG_TYPE_INVALID) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6503 | pr_debug("Invalid plug in attempt # %d\n", retry); |
| 6504 | if (retry == NUM_ATTEMPTS_TO_REPORT && |
| 6505 | tabla->current_plug == PLUG_TYPE_NONE) { |
| 6506 | tabla_codec_report_plug(codec, 1, |
| 6507 | SND_JACK_HEADPHONE); |
| 6508 | } |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6509 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6510 | pr_debug("Good headphone detected, continue polling mic\n"); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6511 | if (tabla->current_plug == PLUG_TYPE_NONE) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6512 | tabla_codec_report_plug(codec, 1, |
| 6513 | SND_JACK_HEADPHONE); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6514 | } else { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6515 | if (plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
| 6516 | pt_gnd_mic_swap_cnt++; |
| 6517 | if (pt_gnd_mic_swap_cnt < |
| 6518 | TABLA_MBHC_GND_MIC_SWAP_THRESHOLD) |
| 6519 | continue; |
| 6520 | else if (pt_gnd_mic_swap_cnt > |
| 6521 | TABLA_MBHC_GND_MIC_SWAP_THRESHOLD) { |
| 6522 | /* This is due to GND/MIC switch didn't |
| 6523 | * work, Report unsupported plug */ |
| 6524 | } else if (tabla->mbhc_cfg.swap_gnd_mic) { |
| 6525 | /* if switch is toggled, check again, |
| 6526 | * otherwise report unsupported plug */ |
| 6527 | if (tabla->mbhc_cfg.swap_gnd_mic(codec)) |
| 6528 | continue; |
| 6529 | } |
| 6530 | } else |
| 6531 | pt_gnd_mic_swap_cnt = 0; |
| 6532 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6533 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 6534 | /* Turn off override */ |
| 6535 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6536 | /* The valid plug also includes PLUG_TYPE_GND_MIC_SWAP |
| 6537 | */ |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6538 | tabla_find_plug_and_report(codec, plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6539 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 6540 | pr_debug("Attempt %d found correct plug %d\n", retry, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6541 | plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6542 | correction = true; |
| 6543 | break; |
| 6544 | } |
| 6545 | } |
| 6546 | |
| 6547 | /* Turn off override */ |
| 6548 | if (!correction) |
| 6549 | tabla_turn_onoff_override(codec, false); |
| 6550 | |
| 6551 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
| 6552 | pr_debug("%s: leave\n", __func__); |
| 6553 | /* unlock sleep */ |
| 6554 | wcd9xxx_unlock_sleep(tabla->codec->control_data); |
| 6555 | } |
| 6556 | |
| 6557 | /* called under codec_resource_lock acquisition */ |
| 6558 | static void tabla_codec_decide_gpio_plug(struct snd_soc_codec *codec) |
| 6559 | { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6560 | enum tabla_mbhc_plug_type plug_type; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6561 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6562 | |
| 6563 | pr_debug("%s: enter\n", __func__); |
| 6564 | |
| 6565 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6566 | plug_type = tabla_codec_get_plug_type(codec, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6567 | tabla_turn_onoff_override(codec, false); |
| 6568 | |
| 6569 | if (tabla_hs_gpio_level_remove(tabla)) { |
| 6570 | pr_debug("%s: GPIO value is low when determining plug\n", |
| 6571 | __func__); |
| 6572 | return; |
| 6573 | } |
| 6574 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6575 | if (plug_type == PLUG_TYPE_INVALID || |
| 6576 | plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6577 | tabla_schedule_hs_detect_plug(tabla); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6578 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6579 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 6580 | |
| 6581 | tabla_schedule_hs_detect_plug(tabla); |
| 6582 | } else { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6583 | pr_debug("%s: Valid plug found, determine plug type %d\n", |
| 6584 | __func__, plug_type); |
| 6585 | tabla_find_plug_and_report(codec, plug_type); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6586 | } |
| 6587 | } |
| 6588 | |
| 6589 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6590 | static void tabla_codec_detect_plug_type(struct snd_soc_codec *codec) |
| 6591 | { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6592 | enum tabla_mbhc_plug_type plug_type; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6593 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 6594 | const struct tabla_mbhc_plug_detect_cfg *plug_det = |
| 6595 | TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6596 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6597 | /* Turn on the override, |
| 6598 | * tabla_codec_setup_hs_polling requires override on */ |
| 6599 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6600 | |
| 6601 | if (plug_det->t_ins_complete > 20) |
| 6602 | msleep(plug_det->t_ins_complete); |
| 6603 | else |
| 6604 | usleep_range(plug_det->t_ins_complete * 1000, |
| 6605 | plug_det->t_ins_complete * 1000); |
| 6606 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6607 | if (tabla->mbhc_cfg.gpio) { |
| 6608 | /* Turn off the override */ |
| 6609 | tabla_turn_onoff_override(codec, false); |
| 6610 | if (tabla_hs_gpio_level_remove(tabla)) |
| 6611 | pr_debug("%s: GPIO value is low when determining " |
| 6612 | "plug\n", __func__); |
| 6613 | else |
| 6614 | tabla_codec_decide_gpio_plug(codec); |
| 6615 | return; |
| 6616 | } |
| 6617 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6618 | plug_type = tabla_codec_get_plug_type(codec, false); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6619 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6620 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6621 | if (plug_type == PLUG_TYPE_INVALID) { |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6622 | pr_debug("%s: Invalid plug type detected\n", __func__); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6623 | 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] | 6624 | tabla_codec_cleanup_hs_polling(codec); |
| 6625 | tabla_codec_enable_hs_detect(codec, 1, |
| 6626 | MBHC_USE_MB_TRIGGER | |
| 6627 | MBHC_USE_HPHL_TRIGGER, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6628 | } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
| 6629 | pr_debug("%s: GND-MIC swapped plug type detected\n", __func__); |
| 6630 | tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED); |
| 6631 | tabla_codec_cleanup_hs_polling(codec); |
| 6632 | tabla_codec_enable_hs_detect(codec, 0, 0, false); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6633 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6634 | pr_debug("%s: Headphone Detected\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6635 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 6636 | tabla_codec_cleanup_hs_polling(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6637 | tabla_codec_enable_hs_detect(codec, 0, 0, false); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6638 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6639 | pr_debug("%s: Headset detected\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6640 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
| 6641 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6642 | /* avoid false button press detect */ |
| 6643 | msleep(50); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6644 | tabla_codec_start_hs_polling(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6645 | } |
| 6646 | } |
| 6647 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6648 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 6649 | 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] | 6650 | { |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6651 | struct snd_soc_codec *codec = priv->codec; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6652 | |
| 6653 | if (!is_removal) { |
| 6654 | pr_debug("%s: MIC trigger insertion interrupt\n", __func__); |
| 6655 | |
| 6656 | rmb(); |
| 6657 | if (priv->lpi_enabled) |
| 6658 | msleep(100); |
| 6659 | |
| 6660 | rmb(); |
| 6661 | if (!priv->lpi_enabled) { |
| 6662 | pr_debug("%s: lpi is disabled\n", __func__); |
| 6663 | } else if (gpio_get_value_cansleep(priv->mbhc_cfg.gpio) == |
| 6664 | priv->mbhc_cfg.gpio_level_insert) { |
| 6665 | pr_debug("%s: Valid insertion, " |
| 6666 | "detect plug type\n", __func__); |
| 6667 | tabla_codec_decide_gpio_plug(codec); |
| 6668 | } else { |
| 6669 | pr_debug("%s: Invalid insertion, " |
| 6670 | "stop plug detection\n", __func__); |
| 6671 | } |
| 6672 | } else { |
| 6673 | pr_err("%s: GPIO used, invalid MBHC Removal\n", __func__); |
| 6674 | } |
| 6675 | } |
| 6676 | |
| 6677 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 6678 | static void tabla_hs_insert_irq_nogpio(struct tabla_priv *priv, bool is_removal, |
| 6679 | bool is_mb_trigger) |
| 6680 | { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6681 | int ret; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6682 | struct snd_soc_codec *codec = priv->codec; |
| 6683 | struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6684 | |
| 6685 | if (is_removal) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6686 | /* cancel possiblely running hs detect work */ |
| 6687 | tabla_cancel_hs_detect_plug(priv); |
| 6688 | |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 6689 | /* |
| 6690 | * If headphone is removed while playback is in progress, |
| 6691 | * it is possible that micbias will be switched to VDDIO. |
| 6692 | */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6693 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6694 | if (priv->current_plug == PLUG_TYPE_HEADPHONE) |
| 6695 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE); |
| 6696 | else if (priv->current_plug == PLUG_TYPE_GND_MIC_SWAP) |
| 6697 | tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED); |
| 6698 | else |
| 6699 | WARN(1, "%s: Unexpected current plug type %d\n", |
| 6700 | __func__, priv->current_plug); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6701 | tabla_codec_shutdown_hs_removal_detect(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6702 | tabla_codec_enable_hs_detect(codec, 1, |
| 6703 | MBHC_USE_MB_TRIGGER | |
| 6704 | MBHC_USE_HPHL_TRIGGER, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6705 | true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6706 | } else if (is_mb_trigger && !is_removal) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6707 | pr_debug("%s: Waiting for Headphone left trigger\n", |
| 6708 | __func__); |
| 6709 | wcd9xxx_lock_sleep(core); |
| 6710 | if (schedule_delayed_work(&priv->mbhc_insert_dwork, |
| 6711 | usecs_to_jiffies(1000000)) == 0) { |
| 6712 | pr_err("%s: mbhc_insert_dwork is already scheduled\n", |
| 6713 | __func__); |
| 6714 | wcd9xxx_unlock_sleep(core); |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 6715 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6716 | tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER, |
| 6717 | false); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6718 | } else { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6719 | ret = cancel_delayed_work(&priv->mbhc_insert_dwork); |
| 6720 | if (ret != 0) { |
| 6721 | pr_debug("%s: Complete plug insertion, Detecting plug " |
| 6722 | "type\n", __func__); |
| 6723 | tabla_codec_detect_plug_type(codec); |
| 6724 | wcd9xxx_unlock_sleep(core); |
| 6725 | } else { |
| 6726 | wcd9xxx_enable_irq(codec->control_data, |
| 6727 | TABLA_IRQ_MBHC_INSERTION); |
| 6728 | pr_err("%s: Error detecting plug insertion\n", |
| 6729 | __func__); |
| 6730 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6731 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6732 | } |
Bhalchandra Gajare | 9494fa26 | 2011-11-10 19:25:59 -0800 | [diff] [blame] | 6733 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6734 | static irqreturn_t tabla_hs_insert_irq(int irq, void *data) |
| 6735 | { |
| 6736 | bool is_mb_trigger, is_removal; |
| 6737 | struct tabla_priv *priv = data; |
| 6738 | struct snd_soc_codec *codec = priv->codec; |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6739 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6740 | pr_debug("%s: enter\n", __func__); |
| 6741 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 6742 | wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION); |
| 6743 | |
| 6744 | is_mb_trigger = !!(snd_soc_read(codec, priv->mbhc_bias_regs.mbhc_reg) & |
| 6745 | 0x10); |
| 6746 | is_removal = !!(snd_soc_read(codec, TABLA_A_CDC_MBHC_INT_CTL) & 0x02); |
| 6747 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x03, 0x00); |
| 6748 | |
| 6749 | /* Turn off both HPH and MIC line schmitt triggers */ |
| 6750 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 6751 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
| 6752 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
| 6753 | |
| 6754 | if (priv->mbhc_cfg.gpio) |
| 6755 | tabla_hs_insert_irq_gpio(priv, is_removal); |
| 6756 | else |
| 6757 | tabla_hs_insert_irq_nogpio(priv, is_removal, is_mb_trigger); |
| 6758 | |
| 6759 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6760 | return IRQ_HANDLED; |
| 6761 | } |
| 6762 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6763 | static bool is_valid_mic_voltage(struct snd_soc_codec *codec, s32 mic_mv) |
| 6764 | { |
| 6765 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6766 | const struct tabla_mbhc_plug_type_cfg *plug_type = |
| 6767 | TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 6768 | const s16 v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6769 | |
| 6770 | 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] | 6771 | && (mic_mv < v_hs_max)) ? true : false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6772 | } |
| 6773 | |
| 6774 | /* called under codec_resource_lock acquisition |
| 6775 | * returns true if mic voltage range is back to normal insertion |
| 6776 | * returns false either if timedout or removed */ |
| 6777 | static bool tabla_hs_remove_settle(struct snd_soc_codec *codec) |
| 6778 | { |
| 6779 | int i; |
| 6780 | bool timedout, settled = false; |
| 6781 | s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT]; |
| 6782 | short mb_v[MBHC_NUM_DCE_PLUG_DETECT]; |
| 6783 | unsigned long retry = 0, timeout; |
| 6784 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6785 | const s16 v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6786 | |
| 6787 | timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS); |
| 6788 | while (!(timedout = time_after(jiffies, timeout))) { |
| 6789 | retry++; |
| 6790 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 6791 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 6792 | break; |
| 6793 | } |
| 6794 | |
| 6795 | if (tabla->mbhc_cfg.gpio) { |
| 6796 | if (retry > 1) |
| 6797 | msleep(250); |
| 6798 | else |
| 6799 | msleep(50); |
| 6800 | } |
| 6801 | |
| 6802 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 6803 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 6804 | break; |
| 6805 | } |
| 6806 | |
| 6807 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) { |
| 6808 | mb_v[i] = tabla_codec_sta_dce(codec, 1, true); |
| 6809 | mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]); |
| 6810 | pr_debug("%s : DCE run %lu, mic_mv = %d(%x)\n", |
| 6811 | __func__, retry, mic_mv[i], mb_v[i]); |
| 6812 | } |
| 6813 | |
| 6814 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 6815 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 6816 | break; |
| 6817 | } |
| 6818 | |
| 6819 | if (tabla->current_plug == PLUG_TYPE_NONE) { |
| 6820 | pr_debug("%s : headset/headphone is removed\n", |
| 6821 | __func__); |
| 6822 | break; |
| 6823 | } |
| 6824 | |
| 6825 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) |
| 6826 | if (!is_valid_mic_voltage(codec, mic_mv[i])) |
| 6827 | break; |
| 6828 | |
| 6829 | if (i == MBHC_NUM_DCE_PLUG_DETECT) { |
| 6830 | pr_debug("%s: MIC voltage settled\n", __func__); |
| 6831 | settled = true; |
| 6832 | msleep(200); |
| 6833 | break; |
| 6834 | } |
| 6835 | |
| 6836 | /* only for non-GPIO remove irq */ |
| 6837 | if (!tabla->mbhc_cfg.gpio) { |
| 6838 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6839 | if (mic_mv[i] < v_hs_max) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6840 | break; |
| 6841 | if (i == MBHC_NUM_DCE_PLUG_DETECT) { |
| 6842 | pr_debug("%s: Headset is removed\n", __func__); |
| 6843 | break; |
| 6844 | } |
| 6845 | } |
| 6846 | } |
| 6847 | |
| 6848 | if (timedout) |
| 6849 | pr_debug("%s: Microphone did not settle in %d seconds\n", |
| 6850 | __func__, TABLA_HS_DETECT_PLUG_TIME_MS); |
| 6851 | return settled; |
| 6852 | } |
| 6853 | |
| 6854 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 6855 | static void tabla_hs_remove_irq_gpio(struct tabla_priv *priv) |
| 6856 | { |
| 6857 | struct snd_soc_codec *codec = priv->codec; |
| 6858 | |
| 6859 | if (tabla_hs_remove_settle(codec)) |
| 6860 | tabla_codec_start_hs_polling(codec); |
| 6861 | pr_debug("%s: remove settle done\n", __func__); |
| 6862 | } |
| 6863 | |
| 6864 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 6865 | static void tabla_hs_remove_irq_nogpio(struct tabla_priv *priv) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6866 | { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6867 | short bias_value; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6868 | bool removed = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6869 | struct snd_soc_codec *codec = priv->codec; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6870 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6871 | TABLA_MBHC_CAL_GENERAL_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6872 | int min_us = TABLA_FAKE_REMOVAL_MIN_PERIOD_MS * 1000; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6873 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6874 | if (priv->current_plug != PLUG_TYPE_HEADSET) { |
| 6875 | pr_debug("%s(): Headset is not inserted, ignore removal\n", |
| 6876 | __func__); |
| 6877 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 6878 | 0x08, 0x08); |
| 6879 | return; |
| 6880 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6881 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6882 | usleep_range(generic->t_shutdown_plug_rem, |
| 6883 | generic->t_shutdown_plug_rem); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6884 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6885 | do { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6886 | bias_value = tabla_codec_sta_dce(codec, 1, true); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6887 | pr_debug("%s: DCE %d,%d, %d us left\n", __func__, bias_value, |
| 6888 | tabla_codec_sta_dce_v(codec, 1, bias_value), min_us); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6889 | if (bias_value < tabla_get_current_v_ins(priv, false)) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6890 | pr_debug("%s: checking false removal\n", __func__); |
| 6891 | msleep(500); |
| 6892 | removed = !tabla_hs_remove_settle(codec); |
| 6893 | pr_debug("%s: headset %sactually removed\n", __func__, |
| 6894 | removed ? "" : "not "); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6895 | break; |
| 6896 | } |
| 6897 | min_us -= priv->mbhc_data.t_dce; |
| 6898 | } while (min_us > 0); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 6899 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6900 | if (removed) { |
| 6901 | /* cancel possiblely running hs detect work */ |
| 6902 | tabla_cancel_hs_detect_plug(priv); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 6903 | /* |
| 6904 | * If this removal is not false, first check the micbias |
| 6905 | * switch status and switch it to LDOH if it is already |
| 6906 | * switched to VDDIO. |
| 6907 | */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6908 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6909 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6910 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET); |
| 6911 | tabla_codec_cleanup_hs_polling(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6912 | tabla_codec_enable_hs_detect(codec, 1, |
| 6913 | MBHC_USE_MB_TRIGGER | |
| 6914 | MBHC_USE_HPHL_TRIGGER, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6915 | true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6916 | } else { |
| 6917 | tabla_codec_start_hs_polling(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6918 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6919 | } |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 6920 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6921 | static irqreturn_t tabla_hs_remove_irq(int irq, void *data) |
| 6922 | { |
| 6923 | struct tabla_priv *priv = data; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6924 | bool vddio; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6925 | pr_debug("%s: enter, removal interrupt\n", __func__); |
| 6926 | |
| 6927 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6928 | vddio = (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
| 6929 | priv->mbhc_micbias_switched); |
| 6930 | if (vddio) |
| 6931 | __tabla_codec_switch_micbias(priv->codec, 0, false, true); |
| 6932 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6933 | if (priv->mbhc_cfg.gpio) |
| 6934 | tabla_hs_remove_irq_gpio(priv); |
| 6935 | else |
| 6936 | tabla_hs_remove_irq_nogpio(priv); |
| 6937 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6938 | /* if driver turned off vddio switch and headset is not removed, |
| 6939 | * turn on the vddio switch back, if headset is removed then vddio |
| 6940 | * switch is off by time now and shouldn't be turn on again from here */ |
| 6941 | if (vddio && priv->current_plug == PLUG_TYPE_HEADSET) |
| 6942 | __tabla_codec_switch_micbias(priv->codec, 1, true, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6943 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6944 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6945 | return IRQ_HANDLED; |
| 6946 | } |
| 6947 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6948 | void mbhc_insert_work(struct work_struct *work) |
| 6949 | { |
| 6950 | struct delayed_work *dwork; |
| 6951 | struct tabla_priv *tabla; |
| 6952 | struct snd_soc_codec *codec; |
| 6953 | struct wcd9xxx *tabla_core; |
| 6954 | |
| 6955 | dwork = to_delayed_work(work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6956 | tabla = container_of(dwork, struct tabla_priv, mbhc_insert_dwork); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6957 | codec = tabla->codec; |
| 6958 | tabla_core = dev_get_drvdata(codec->dev->parent); |
| 6959 | |
| 6960 | pr_debug("%s:\n", __func__); |
| 6961 | |
| 6962 | /* Turn off both HPH and MIC line schmitt triggers */ |
| 6963 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 6964 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
| 6965 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
| 6966 | wcd9xxx_disable_irq_sync(codec->control_data, TABLA_IRQ_MBHC_INSERTION); |
| 6967 | tabla_codec_detect_plug_type(codec); |
| 6968 | wcd9xxx_unlock_sleep(tabla_core); |
| 6969 | } |
| 6970 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6971 | static void tabla_hs_gpio_handler(struct snd_soc_codec *codec) |
| 6972 | { |
| 6973 | bool insert; |
| 6974 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 6975 | bool is_removed = false; |
| 6976 | |
| 6977 | pr_debug("%s: enter\n", __func__); |
| 6978 | |
| 6979 | tabla->in_gpio_handler = true; |
| 6980 | /* Wait here for debounce time */ |
| 6981 | usleep_range(TABLA_GPIO_IRQ_DEBOUNCE_TIME_US, |
| 6982 | TABLA_GPIO_IRQ_DEBOUNCE_TIME_US); |
| 6983 | |
| 6984 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 6985 | |
| 6986 | /* cancel pending button press */ |
| 6987 | if (tabla_cancel_btn_work(tabla)) |
| 6988 | pr_debug("%s: button press is canceled\n", __func__); |
| 6989 | |
| 6990 | insert = (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) == |
| 6991 | tabla->mbhc_cfg.gpio_level_insert); |
| 6992 | if ((tabla->current_plug == PLUG_TYPE_NONE) && insert) { |
| 6993 | tabla->lpi_enabled = false; |
| 6994 | wmb(); |
| 6995 | |
| 6996 | /* cancel detect plug */ |
| 6997 | tabla_cancel_hs_detect_plug(tabla); |
| 6998 | |
| 6999 | /* Disable Mic Bias pull down and HPH Switch to GND */ |
| 7000 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 7001 | 0x00); |
| 7002 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x00); |
| 7003 | tabla_codec_detect_plug_type(codec); |
| 7004 | } else if ((tabla->current_plug != PLUG_TYPE_NONE) && !insert) { |
| 7005 | tabla->lpi_enabled = false; |
| 7006 | wmb(); |
| 7007 | |
| 7008 | /* cancel detect plug */ |
| 7009 | tabla_cancel_hs_detect_plug(tabla); |
| 7010 | |
| 7011 | if (tabla->current_plug == PLUG_TYPE_HEADPHONE) { |
| 7012 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE); |
| 7013 | is_removed = true; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7014 | } else if (tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP) { |
| 7015 | tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED); |
| 7016 | is_removed = true; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7017 | } else if (tabla->current_plug == PLUG_TYPE_HEADSET) { |
| 7018 | tabla_codec_pause_hs_polling(codec); |
| 7019 | tabla_codec_cleanup_hs_polling(codec); |
| 7020 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET); |
| 7021 | is_removed = true; |
| 7022 | } |
| 7023 | |
| 7024 | if (is_removed) { |
| 7025 | /* Enable Mic Bias pull down and HPH Switch to GND */ |
| 7026 | snd_soc_update_bits(codec, |
| 7027 | tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 7028 | 0x01); |
| 7029 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, |
| 7030 | 0x01); |
| 7031 | /* Make sure mic trigger is turned off */ |
| 7032 | snd_soc_update_bits(codec, |
| 7033 | tabla->mbhc_bias_regs.ctl_reg, |
| 7034 | 0x01, 0x01); |
| 7035 | snd_soc_update_bits(codec, |
| 7036 | tabla->mbhc_bias_regs.mbhc_reg, |
| 7037 | 0x90, 0x00); |
| 7038 | /* Reset MBHC State Machine */ |
| 7039 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 7040 | 0x08, 0x08); |
| 7041 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 7042 | 0x08, 0x00); |
| 7043 | /* Turn off override */ |
| 7044 | tabla_turn_onoff_override(codec, false); |
| 7045 | } |
| 7046 | } |
| 7047 | |
| 7048 | tabla->in_gpio_handler = false; |
| 7049 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 7050 | pr_debug("%s: leave\n", __func__); |
| 7051 | } |
| 7052 | |
| 7053 | static irqreturn_t tabla_mechanical_plug_detect_irq(int irq, void *data) |
| 7054 | { |
| 7055 | int r = IRQ_HANDLED; |
| 7056 | struct snd_soc_codec *codec = data; |
| 7057 | |
| 7058 | if (unlikely(wcd9xxx_lock_sleep(codec->control_data) == false)) { |
| 7059 | pr_warn("%s: failed to hold suspend\n", __func__); |
| 7060 | r = IRQ_NONE; |
| 7061 | } else { |
| 7062 | tabla_hs_gpio_handler(codec); |
| 7063 | wcd9xxx_unlock_sleep(codec->control_data); |
| 7064 | } |
| 7065 | |
| 7066 | return r; |
| 7067 | } |
| 7068 | |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7069 | static int tabla_mbhc_init_and_calibrate(struct tabla_priv *tabla) |
| 7070 | { |
| 7071 | int ret = 0; |
| 7072 | struct snd_soc_codec *codec = tabla->codec; |
| 7073 | |
| 7074 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 7075 | tabla_mbhc_init(codec); |
| 7076 | tabla_mbhc_cal(codec); |
| 7077 | tabla_mbhc_calc_thres(codec); |
| 7078 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
| 7079 | tabla_codec_calibrate_hs_polling(codec); |
| 7080 | if (!tabla->mbhc_cfg.gpio) { |
| 7081 | ret = tabla_codec_enable_hs_detect(codec, 1, |
| 7082 | MBHC_USE_MB_TRIGGER | |
| 7083 | MBHC_USE_HPHL_TRIGGER, |
| 7084 | false); |
| 7085 | |
| 7086 | if (IS_ERR_VALUE(ret)) |
| 7087 | pr_err("%s: Failed to setup MBHC detection\n", |
| 7088 | __func__); |
| 7089 | } else { |
| 7090 | /* Enable Mic Bias pull down and HPH Switch to GND */ |
| 7091 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, |
| 7092 | 0x01, 0x01); |
| 7093 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x01); |
| 7094 | INIT_WORK(&tabla->hs_correct_plug_work, |
| 7095 | tabla_hs_correct_gpio_plug); |
| 7096 | } |
| 7097 | |
| 7098 | if (!IS_ERR_VALUE(ret)) { |
| 7099 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10); |
| 7100 | wcd9xxx_enable_irq(codec->control_data, |
| 7101 | TABLA_IRQ_HPH_PA_OCPL_FAULT); |
| 7102 | wcd9xxx_enable_irq(codec->control_data, |
| 7103 | TABLA_IRQ_HPH_PA_OCPR_FAULT); |
| 7104 | |
| 7105 | if (tabla->mbhc_cfg.gpio) { |
| 7106 | ret = request_threaded_irq(tabla->mbhc_cfg.gpio_irq, |
| 7107 | NULL, |
| 7108 | tabla_mechanical_plug_detect_irq, |
| 7109 | (IRQF_TRIGGER_RISING | |
| 7110 | IRQF_TRIGGER_FALLING), |
| 7111 | "tabla-gpio", codec); |
| 7112 | if (!IS_ERR_VALUE(ret)) { |
| 7113 | ret = enable_irq_wake(tabla->mbhc_cfg.gpio_irq); |
| 7114 | /* Bootup time detection */ |
| 7115 | tabla_hs_gpio_handler(codec); |
| 7116 | } |
| 7117 | } |
| 7118 | } |
| 7119 | |
| 7120 | return ret; |
| 7121 | } |
| 7122 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7123 | static void mbhc_fw_read(struct work_struct *work) |
| 7124 | { |
| 7125 | struct delayed_work *dwork; |
| 7126 | struct tabla_priv *tabla; |
| 7127 | struct snd_soc_codec *codec; |
| 7128 | const struct firmware *fw; |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7129 | int ret = -1, retry = 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7130 | |
| 7131 | dwork = to_delayed_work(work); |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7132 | tabla = container_of(dwork, struct tabla_priv, mbhc_firmware_dwork); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7133 | codec = tabla->codec; |
| 7134 | |
| 7135 | while (retry < MBHC_FW_READ_ATTEMPTS) { |
| 7136 | retry++; |
| 7137 | pr_info("%s:Attempt %d to request MBHC firmware\n", |
| 7138 | __func__, retry); |
| 7139 | ret = request_firmware(&fw, "wcd9310/wcd9310_mbhc.bin", |
| 7140 | codec->dev); |
| 7141 | |
| 7142 | if (ret != 0) { |
| 7143 | usleep_range(MBHC_FW_READ_TIMEOUT, |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7144 | MBHC_FW_READ_TIMEOUT); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7145 | } else { |
| 7146 | pr_info("%s: MBHC Firmware read succesful\n", __func__); |
| 7147 | break; |
| 7148 | } |
| 7149 | } |
| 7150 | |
| 7151 | if (ret != 0) { |
| 7152 | pr_err("%s: Cannot load MBHC firmware use default cal\n", |
| 7153 | __func__); |
| 7154 | } else if (tabla_mbhc_fw_validate(fw) == false) { |
| 7155 | pr_err("%s: Invalid MBHC cal data size use default cal\n", |
| 7156 | __func__); |
| 7157 | release_firmware(fw); |
| 7158 | } else { |
| 7159 | tabla->mbhc_cfg.calibration = (void *)fw->data; |
| 7160 | tabla->mbhc_fw = fw; |
| 7161 | } |
| 7162 | |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7163 | (void) tabla_mbhc_init_and_calibrate(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7164 | } |
| 7165 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7166 | int tabla_hs_detect(struct snd_soc_codec *codec, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7167 | const struct tabla_mbhc_config *cfg) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7168 | { |
| 7169 | struct tabla_priv *tabla; |
| 7170 | int rc = 0; |
| 7171 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7172 | if (!codec || !cfg->calibration) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7173 | pr_err("Error: no codec or calibration\n"); |
| 7174 | return -EINVAL; |
| 7175 | } |
| 7176 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7177 | if (cfg->mclk_rate != TABLA_MCLK_RATE_12288KHZ) { |
| 7178 | if (cfg->mclk_rate == TABLA_MCLK_RATE_9600KHZ) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7179 | pr_err("Error: clock rate %dHz is not yet supported\n", |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7180 | cfg->mclk_rate); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7181 | else |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7182 | pr_err("Error: unsupported clock rate %d\n", |
| 7183 | cfg->mclk_rate); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7184 | return -EINVAL; |
| 7185 | } |
| 7186 | |
| 7187 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7188 | tabla->mbhc_cfg = *cfg; |
| 7189 | tabla->in_gpio_handler = false; |
| 7190 | tabla->current_plug = PLUG_TYPE_NONE; |
| 7191 | tabla->lpi_enabled = false; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7192 | tabla_get_mbhc_micbias_regs(codec, &tabla->mbhc_bias_regs); |
| 7193 | |
| 7194 | /* Put CFILT in fast mode by default */ |
| 7195 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, |
| 7196 | 0x40, TABLA_CFILT_FAST_MODE); |
| 7197 | INIT_DELAYED_WORK(&tabla->mbhc_firmware_dwork, mbhc_fw_read); |
| 7198 | INIT_DELAYED_WORK(&tabla->mbhc_btn_dwork, btn_lpress_fn); |
| 7199 | INIT_WORK(&tabla->hphlocp_work, hphlocp_off_report); |
| 7200 | INIT_WORK(&tabla->hphrocp_work, hphrocp_off_report); |
| 7201 | INIT_DELAYED_WORK(&tabla->mbhc_insert_dwork, mbhc_insert_work); |
| 7202 | |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7203 | if (!tabla->mbhc_cfg.read_fw_bin) |
| 7204 | rc = tabla_mbhc_init_and_calibrate(tabla); |
| 7205 | else |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7206 | schedule_delayed_work(&tabla->mbhc_firmware_dwork, |
| 7207 | usecs_to_jiffies(MBHC_FW_READ_TIMEOUT)); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7208 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7209 | return rc; |
| 7210 | } |
| 7211 | EXPORT_SYMBOL_GPL(tabla_hs_detect); |
| 7212 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7213 | static unsigned long slimbus_value; |
| 7214 | |
| 7215 | static irqreturn_t tabla_slimbus_irq(int irq, void *data) |
| 7216 | { |
| 7217 | struct tabla_priv *priv = data; |
| 7218 | struct snd_soc_codec *codec = priv->codec; |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 7219 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 7220 | int i, j, port_id, k, ch_mask_temp; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7221 | u8 val; |
| 7222 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7223 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) { |
| 7224 | slimbus_value = wcd9xxx_interface_reg_read(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7225 | TABLA_SLIM_PGD_PORT_INT_STATUS0 + i); |
| 7226 | for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7227 | val = wcd9xxx_interface_reg_read(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7228 | TABLA_SLIM_PGD_PORT_INT_SOURCE0 + i*8 + j); |
| 7229 | if (val & 0x1) |
| 7230 | pr_err_ratelimited("overflow error on port %x," |
| 7231 | " value %x\n", i*8 + j, val); |
| 7232 | if (val & 0x2) |
| 7233 | pr_err_ratelimited("underflow error on port %x," |
| 7234 | " value %x\n", i*8 + j, val); |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 7235 | if (val & 0x4) { |
| 7236 | pr_debug("%s: port %x disconnect value %x\n", |
| 7237 | __func__, i*8 + j, val); |
| 7238 | port_id = i*8 + j; |
| 7239 | for (k = 0; k < ARRAY_SIZE(tabla_dai); k++) { |
| 7240 | ch_mask_temp = 1 << port_id; |
| 7241 | if (ch_mask_temp & |
| 7242 | tabla_p->dai[k].ch_mask) { |
| 7243 | tabla_p->dai[k].ch_mask &= |
| 7244 | ~ch_mask_temp; |
| 7245 | if (!tabla_p->dai[k].ch_mask) |
| 7246 | wake_up( |
| 7247 | &tabla_p->dai[k].dai_wait); |
| 7248 | } |
| 7249 | } |
| 7250 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7251 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7252 | wcd9xxx_interface_reg_write(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7253 | TABLA_SLIM_PGD_PORT_INT_CLR0 + i, 0xFF); |
| 7254 | } |
| 7255 | |
| 7256 | return IRQ_HANDLED; |
| 7257 | } |
| 7258 | |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7259 | static int tabla_handle_pdata(struct tabla_priv *tabla) |
| 7260 | { |
| 7261 | struct snd_soc_codec *codec = tabla->codec; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7262 | struct wcd9xxx_pdata *pdata = tabla->pdata; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7263 | int k1, k2, k3, rc = 0; |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 7264 | u8 leg_mode = pdata->amic_settings.legacy_mode; |
| 7265 | u8 txfe_bypass = pdata->amic_settings.txfe_enable; |
| 7266 | u8 txfe_buff = pdata->amic_settings.txfe_buff; |
| 7267 | u8 flag = pdata->amic_settings.use_pdata; |
| 7268 | u8 i = 0, j = 0; |
| 7269 | u8 val_txfe = 0, value = 0; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7270 | |
| 7271 | if (!pdata) { |
| 7272 | rc = -ENODEV; |
| 7273 | goto done; |
| 7274 | } |
| 7275 | |
| 7276 | /* Make sure settings are correct */ |
| 7277 | if ((pdata->micbias.ldoh_v > TABLA_LDOH_2P85_V) || |
| 7278 | (pdata->micbias.bias1_cfilt_sel > TABLA_CFILT3_SEL) || |
| 7279 | (pdata->micbias.bias2_cfilt_sel > TABLA_CFILT3_SEL) || |
| 7280 | (pdata->micbias.bias3_cfilt_sel > TABLA_CFILT3_SEL) || |
| 7281 | (pdata->micbias.bias4_cfilt_sel > TABLA_CFILT3_SEL)) { |
| 7282 | rc = -EINVAL; |
| 7283 | goto done; |
| 7284 | } |
| 7285 | |
| 7286 | /* figure out k value */ |
| 7287 | k1 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 7288 | pdata->micbias.cfilt1_mv); |
| 7289 | k2 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 7290 | pdata->micbias.cfilt2_mv); |
| 7291 | k3 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 7292 | pdata->micbias.cfilt3_mv); |
| 7293 | |
| 7294 | if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) { |
| 7295 | rc = -EINVAL; |
| 7296 | goto done; |
| 7297 | } |
| 7298 | |
| 7299 | /* Set voltage level and always use LDO */ |
| 7300 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x0C, |
| 7301 | (pdata->micbias.ldoh_v << 2)); |
| 7302 | |
| 7303 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_1_VAL, 0xFC, |
| 7304 | (k1 << 2)); |
| 7305 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_2_VAL, 0xFC, |
| 7306 | (k2 << 2)); |
| 7307 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_3_VAL, 0xFC, |
| 7308 | (k3 << 2)); |
| 7309 | |
| 7310 | snd_soc_update_bits(codec, TABLA_A_MICB_1_CTL, 0x60, |
| 7311 | (pdata->micbias.bias1_cfilt_sel << 5)); |
| 7312 | snd_soc_update_bits(codec, TABLA_A_MICB_2_CTL, 0x60, |
| 7313 | (pdata->micbias.bias2_cfilt_sel << 5)); |
| 7314 | snd_soc_update_bits(codec, TABLA_A_MICB_3_CTL, 0x60, |
| 7315 | (pdata->micbias.bias3_cfilt_sel << 5)); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7316 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_ctl, 0x60, |
| 7317 | (pdata->micbias.bias4_cfilt_sel << 5)); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7318 | |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 7319 | for (i = 0; i < 6; j++, i += 2) { |
| 7320 | if (flag & (0x01 << i)) { |
| 7321 | value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00; |
| 7322 | val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00; |
| 7323 | val_txfe = val_txfe | |
| 7324 | ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00); |
| 7325 | snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10, |
| 7326 | 0x10, value); |
| 7327 | snd_soc_update_bits(codec, |
| 7328 | TABLA_A_TX_1_2_TEST_EN + j * 10, |
| 7329 | 0x30, val_txfe); |
| 7330 | } |
| 7331 | if (flag & (0x01 << (i + 1))) { |
| 7332 | value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 7333 | val_txfe = (txfe_bypass & |
| 7334 | (0x01 << (i + 1))) ? 0x02 : 0x00; |
| 7335 | val_txfe |= (txfe_buff & |
| 7336 | (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 7337 | snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10, |
| 7338 | 0x01, value); |
| 7339 | snd_soc_update_bits(codec, |
| 7340 | TABLA_A_TX_1_2_TEST_EN + j * 10, |
| 7341 | 0x03, val_txfe); |
| 7342 | } |
| 7343 | } |
| 7344 | if (flag & 0x40) { |
| 7345 | value = (leg_mode & 0x40) ? 0x10 : 0x00; |
| 7346 | value = value | ((txfe_bypass & 0x40) ? 0x02 : 0x00); |
| 7347 | value = value | ((txfe_buff & 0x40) ? 0x01 : 0x00); |
| 7348 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, |
| 7349 | 0x13, value); |
| 7350 | } |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7351 | |
| 7352 | if (pdata->ocp.use_pdata) { |
| 7353 | /* not defined in CODEC specification */ |
| 7354 | if (pdata->ocp.hph_ocp_limit == 1 || |
| 7355 | pdata->ocp.hph_ocp_limit == 5) { |
| 7356 | rc = -EINVAL; |
| 7357 | goto done; |
| 7358 | } |
| 7359 | snd_soc_update_bits(codec, TABLA_A_RX_COM_OCP_CTL, |
| 7360 | 0x0F, pdata->ocp.num_attempts); |
| 7361 | snd_soc_write(codec, TABLA_A_RX_COM_OCP_COUNT, |
| 7362 | ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time)); |
| 7363 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, |
| 7364 | 0xE0, (pdata->ocp.hph_ocp_limit << 5)); |
| 7365 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7366 | |
| 7367 | for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) { |
| 7368 | if (!strncmp(pdata->regulator[i].name, "CDC_VDDA_RX", 11)) { |
| 7369 | if (pdata->regulator[i].min_uV == 1800000 && |
| 7370 | pdata->regulator[i].max_uV == 1800000) { |
| 7371 | snd_soc_write(codec, TABLA_A_BIAS_REF_CTL, |
| 7372 | 0x1C); |
| 7373 | } else if (pdata->regulator[i].min_uV == 2200000 && |
| 7374 | pdata->regulator[i].max_uV == 2200000) { |
| 7375 | snd_soc_write(codec, TABLA_A_BIAS_REF_CTL, |
| 7376 | 0x1E); |
| 7377 | } else { |
| 7378 | pr_err("%s: unsupported CDC_VDDA_RX voltage " |
| 7379 | "min %d, max %d\n", __func__, |
| 7380 | pdata->regulator[i].min_uV, |
| 7381 | pdata->regulator[i].max_uV); |
| 7382 | rc = -EINVAL; |
| 7383 | } |
| 7384 | break; |
| 7385 | } |
| 7386 | } |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7387 | done: |
| 7388 | return rc; |
| 7389 | } |
| 7390 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7391 | static const struct tabla_reg_mask_val tabla_1_1_reg_defaults[] = { |
| 7392 | |
| 7393 | /* Tabla 1.1 MICBIAS changes */ |
| 7394 | TABLA_REG_VAL(TABLA_A_MICB_1_INT_RBIAS, 0x24), |
| 7395 | TABLA_REG_VAL(TABLA_A_MICB_2_INT_RBIAS, 0x24), |
| 7396 | TABLA_REG_VAL(TABLA_A_MICB_3_INT_RBIAS, 0x24), |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7397 | |
| 7398 | /* Tabla 1.1 HPH changes */ |
| 7399 | TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_PA, 0x57), |
| 7400 | TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_LDO, 0x56), |
| 7401 | |
| 7402 | /* Tabla 1.1 EAR PA changes */ |
| 7403 | TABLA_REG_VAL(TABLA_A_RX_EAR_BIAS_PA, 0xA6), |
| 7404 | TABLA_REG_VAL(TABLA_A_RX_EAR_GAIN, 0x02), |
| 7405 | TABLA_REG_VAL(TABLA_A_RX_EAR_VCM, 0x03), |
| 7406 | |
| 7407 | /* Tabla 1.1 Lineout_5 Changes */ |
| 7408 | TABLA_REG_VAL(TABLA_A_RX_LINE_5_GAIN, 0x10), |
| 7409 | |
| 7410 | /* Tabla 1.1 RX Changes */ |
| 7411 | TABLA_REG_VAL(TABLA_A_CDC_RX1_B5_CTL, 0x78), |
| 7412 | TABLA_REG_VAL(TABLA_A_CDC_RX2_B5_CTL, 0x78), |
| 7413 | TABLA_REG_VAL(TABLA_A_CDC_RX3_B5_CTL, 0x78), |
| 7414 | TABLA_REG_VAL(TABLA_A_CDC_RX4_B5_CTL, 0x78), |
| 7415 | TABLA_REG_VAL(TABLA_A_CDC_RX5_B5_CTL, 0x78), |
| 7416 | TABLA_REG_VAL(TABLA_A_CDC_RX6_B5_CTL, 0x78), |
| 7417 | TABLA_REG_VAL(TABLA_A_CDC_RX7_B5_CTL, 0x78), |
| 7418 | |
| 7419 | /* Tabla 1.1 RX1 and RX2 Changes */ |
| 7420 | TABLA_REG_VAL(TABLA_A_CDC_RX1_B6_CTL, 0xA0), |
| 7421 | TABLA_REG_VAL(TABLA_A_CDC_RX2_B6_CTL, 0xA0), |
| 7422 | |
| 7423 | /* Tabla 1.1 RX3 to RX7 Changes */ |
| 7424 | TABLA_REG_VAL(TABLA_A_CDC_RX3_B6_CTL, 0x80), |
| 7425 | TABLA_REG_VAL(TABLA_A_CDC_RX4_B6_CTL, 0x80), |
| 7426 | TABLA_REG_VAL(TABLA_A_CDC_RX5_B6_CTL, 0x80), |
| 7427 | TABLA_REG_VAL(TABLA_A_CDC_RX6_B6_CTL, 0x80), |
| 7428 | TABLA_REG_VAL(TABLA_A_CDC_RX7_B6_CTL, 0x80), |
| 7429 | |
| 7430 | /* Tabla 1.1 CLASSG Changes */ |
| 7431 | TABLA_REG_VAL(TABLA_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B), |
| 7432 | }; |
| 7433 | |
| 7434 | static const struct tabla_reg_mask_val tabla_2_0_reg_defaults[] = { |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7435 | /* Tabla 2.0 MICBIAS changes */ |
| 7436 | TABLA_REG_VAL(TABLA_A_MICB_2_MBHC, 0x02), |
| 7437 | }; |
| 7438 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7439 | static const struct tabla_reg_mask_val tabla_1_x_only_reg_2_0_defaults[] = { |
| 7440 | TABLA_REG_VAL(TABLA_1_A_MICB_4_INT_RBIAS, 0x24), |
| 7441 | }; |
| 7442 | |
| 7443 | static const struct tabla_reg_mask_val tabla_2_only_reg_2_0_defaults[] = { |
| 7444 | TABLA_REG_VAL(TABLA_2_A_MICB_4_INT_RBIAS, 0x24), |
| 7445 | }; |
| 7446 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7447 | static void tabla_update_reg_defaults(struct snd_soc_codec *codec) |
| 7448 | { |
| 7449 | u32 i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7450 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7451 | |
| 7452 | for (i = 0; i < ARRAY_SIZE(tabla_1_1_reg_defaults); i++) |
| 7453 | snd_soc_write(codec, tabla_1_1_reg_defaults[i].reg, |
| 7454 | tabla_1_1_reg_defaults[i].val); |
| 7455 | |
| 7456 | for (i = 0; i < ARRAY_SIZE(tabla_2_0_reg_defaults); i++) |
| 7457 | snd_soc_write(codec, tabla_2_0_reg_defaults[i].reg, |
| 7458 | tabla_2_0_reg_defaults[i].val); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7459 | |
| 7460 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 7461 | for (i = 0; i < ARRAY_SIZE(tabla_1_x_only_reg_2_0_defaults); |
| 7462 | i++) |
| 7463 | snd_soc_write(codec, |
| 7464 | tabla_1_x_only_reg_2_0_defaults[i].reg, |
| 7465 | tabla_1_x_only_reg_2_0_defaults[i].val); |
| 7466 | } else { |
| 7467 | for (i = 0; i < ARRAY_SIZE(tabla_2_only_reg_2_0_defaults); i++) |
| 7468 | snd_soc_write(codec, |
| 7469 | tabla_2_only_reg_2_0_defaults[i].reg, |
| 7470 | tabla_2_only_reg_2_0_defaults[i].val); |
| 7471 | } |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7472 | } |
| 7473 | |
| 7474 | static const struct tabla_reg_mask_val tabla_codec_reg_init_val[] = { |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7475 | /* Initialize current threshold to 350MA |
| 7476 | * number of wait and run cycles to 4096 |
| 7477 | */ |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7478 | {TABLA_A_RX_HPH_OCP_CTL, 0xE0, 0x60}, |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7479 | {TABLA_A_RX_COM_OCP_COUNT, 0xFF, 0xFF}, |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7480 | |
Santosh Mardi | 3217101 | 2011-10-28 23:32:06 +0530 | [diff] [blame] | 7481 | {TABLA_A_QFUSE_CTL, 0xFF, 0x03}, |
| 7482 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7483 | /* Initialize gain registers to use register gain */ |
| 7484 | {TABLA_A_RX_HPH_L_GAIN, 0x10, 0x10}, |
| 7485 | {TABLA_A_RX_HPH_R_GAIN, 0x10, 0x10}, |
| 7486 | {TABLA_A_RX_LINE_1_GAIN, 0x10, 0x10}, |
| 7487 | {TABLA_A_RX_LINE_2_GAIN, 0x10, 0x10}, |
| 7488 | {TABLA_A_RX_LINE_3_GAIN, 0x10, 0x10}, |
| 7489 | {TABLA_A_RX_LINE_4_GAIN, 0x10, 0x10}, |
| 7490 | |
| 7491 | /* Initialize mic biases to differential mode */ |
| 7492 | {TABLA_A_MICB_1_INT_RBIAS, 0x24, 0x24}, |
| 7493 | {TABLA_A_MICB_2_INT_RBIAS, 0x24, 0x24}, |
| 7494 | {TABLA_A_MICB_3_INT_RBIAS, 0x24, 0x24}, |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7495 | |
| 7496 | {TABLA_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14}, |
| 7497 | |
| 7498 | /* Use 16 bit sample size for TX1 to TX6 */ |
| 7499 | {TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20}, |
| 7500 | {TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20}, |
| 7501 | {TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20}, |
| 7502 | {TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20}, |
| 7503 | {TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20}, |
| 7504 | {TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0x30, 0x20}, |
| 7505 | |
| 7506 | /* Use 16 bit sample size for TX7 to TX10 */ |
| 7507 | {TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0x60, 0x40}, |
| 7508 | {TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0x60, 0x40}, |
| 7509 | {TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0x60, 0x40}, |
| 7510 | {TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0x60, 0x40}, |
| 7511 | |
| 7512 | /* Use 16 bit sample size for RX */ |
| 7513 | {TABLA_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA}, |
| 7514 | {TABLA_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0xAA}, |
| 7515 | |
| 7516 | /*enable HPF filter for TX paths */ |
| 7517 | {TABLA_A_CDC_TX1_MUX_CTL, 0x8, 0x0}, |
| 7518 | {TABLA_A_CDC_TX2_MUX_CTL, 0x8, 0x0}, |
| 7519 | {TABLA_A_CDC_TX3_MUX_CTL, 0x8, 0x0}, |
| 7520 | {TABLA_A_CDC_TX4_MUX_CTL, 0x8, 0x0}, |
| 7521 | {TABLA_A_CDC_TX5_MUX_CTL, 0x8, 0x0}, |
| 7522 | {TABLA_A_CDC_TX6_MUX_CTL, 0x8, 0x0}, |
| 7523 | {TABLA_A_CDC_TX7_MUX_CTL, 0x8, 0x0}, |
| 7524 | {TABLA_A_CDC_TX8_MUX_CTL, 0x8, 0x0}, |
| 7525 | {TABLA_A_CDC_TX9_MUX_CTL, 0x8, 0x0}, |
| 7526 | {TABLA_A_CDC_TX10_MUX_CTL, 0x8, 0x0}, |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 7527 | |
| 7528 | /* config Decimator for DMIC CLK_MODE_1(3.072Mhz@12.88Mhz mclk) */ |
| 7529 | {TABLA_A_CDC_TX1_DMIC_CTL, 0x1, 0x1}, |
| 7530 | {TABLA_A_CDC_TX2_DMIC_CTL, 0x1, 0x1}, |
| 7531 | {TABLA_A_CDC_TX3_DMIC_CTL, 0x1, 0x1}, |
| 7532 | {TABLA_A_CDC_TX4_DMIC_CTL, 0x1, 0x1}, |
| 7533 | {TABLA_A_CDC_TX5_DMIC_CTL, 0x1, 0x1}, |
| 7534 | {TABLA_A_CDC_TX6_DMIC_CTL, 0x1, 0x1}, |
| 7535 | {TABLA_A_CDC_TX7_DMIC_CTL, 0x1, 0x1}, |
| 7536 | {TABLA_A_CDC_TX8_DMIC_CTL, 0x1, 0x1}, |
| 7537 | {TABLA_A_CDC_TX9_DMIC_CTL, 0x1, 0x1}, |
| 7538 | {TABLA_A_CDC_TX10_DMIC_CTL, 0x1, 0x1}, |
| 7539 | |
| 7540 | /* config DMIC clk to CLK_MODE_1 (3.072Mhz@12.88Mhz mclk) */ |
| 7541 | {TABLA_A_CDC_CLK_DMIC_CTL, 0x2A, 0x2A}, |
| 7542 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7543 | }; |
| 7544 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7545 | static const struct tabla_reg_mask_val tabla_1_x_codec_reg_init_val[] = { |
| 7546 | /* Initialize mic biases to differential mode */ |
| 7547 | {TABLA_1_A_MICB_4_INT_RBIAS, 0x24, 0x24}, |
| 7548 | }; |
| 7549 | |
| 7550 | static const struct tabla_reg_mask_val tabla_2_higher_codec_reg_init_val[] = { |
| 7551 | /* Initialize mic biases to differential mode */ |
| 7552 | {TABLA_2_A_MICB_4_INT_RBIAS, 0x24, 0x24}, |
| 7553 | }; |
| 7554 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7555 | static void tabla_codec_init_reg(struct snd_soc_codec *codec) |
| 7556 | { |
| 7557 | u32 i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7558 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7559 | |
| 7560 | for (i = 0; i < ARRAY_SIZE(tabla_codec_reg_init_val); i++) |
| 7561 | snd_soc_update_bits(codec, tabla_codec_reg_init_val[i].reg, |
| 7562 | tabla_codec_reg_init_val[i].mask, |
| 7563 | tabla_codec_reg_init_val[i].val); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7564 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 7565 | for (i = 0; i < ARRAY_SIZE(tabla_1_x_codec_reg_init_val); i++) |
| 7566 | snd_soc_update_bits(codec, |
| 7567 | tabla_1_x_codec_reg_init_val[i].reg, |
| 7568 | tabla_1_x_codec_reg_init_val[i].mask, |
| 7569 | tabla_1_x_codec_reg_init_val[i].val); |
| 7570 | } else { |
| 7571 | for (i = 0; i < ARRAY_SIZE(tabla_2_higher_codec_reg_init_val); |
| 7572 | i++) |
| 7573 | snd_soc_update_bits(codec, |
| 7574 | tabla_2_higher_codec_reg_init_val[i].reg, |
| 7575 | tabla_2_higher_codec_reg_init_val[i].mask, |
| 7576 | tabla_2_higher_codec_reg_init_val[i].val); |
| 7577 | } |
| 7578 | } |
| 7579 | |
| 7580 | static void tabla_update_reg_address(struct tabla_priv *priv) |
| 7581 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7582 | struct wcd9xxx *tabla_core = dev_get_drvdata(priv->codec->dev->parent); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7583 | struct tabla_reg_address *reg_addr = &priv->reg_addr; |
| 7584 | |
| 7585 | if (TABLA_IS_1_X(tabla_core->version)) { |
Joonwoo Park | cb7c892 | 2012-02-16 23:12:59 -0800 | [diff] [blame] | 7586 | reg_addr->micb_4_mbhc = TABLA_1_A_MICB_4_MBHC; |
| 7587 | 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] | 7588 | reg_addr->micb_4_ctl = TABLA_1_A_MICB_4_CTL; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7589 | } else if (TABLA_IS_2_0(tabla_core->version)) { |
Joonwoo Park | cb7c892 | 2012-02-16 23:12:59 -0800 | [diff] [blame] | 7590 | reg_addr->micb_4_mbhc = TABLA_2_A_MICB_4_MBHC; |
| 7591 | 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] | 7592 | reg_addr->micb_4_ctl = TABLA_2_A_MICB_4_CTL; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7593 | } |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7594 | } |
| 7595 | |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 7596 | #ifdef CONFIG_DEBUG_FS |
| 7597 | static int codec_debug_open(struct inode *inode, struct file *file) |
| 7598 | { |
| 7599 | file->private_data = inode->i_private; |
| 7600 | return 0; |
| 7601 | } |
| 7602 | |
| 7603 | static ssize_t codec_debug_write(struct file *filp, |
| 7604 | const char __user *ubuf, size_t cnt, loff_t *ppos) |
| 7605 | { |
| 7606 | char lbuf[32]; |
| 7607 | char *buf; |
| 7608 | int rc; |
| 7609 | struct tabla_priv *tabla = filp->private_data; |
| 7610 | |
| 7611 | if (cnt > sizeof(lbuf) - 1) |
| 7612 | return -EINVAL; |
| 7613 | |
| 7614 | rc = copy_from_user(lbuf, ubuf, cnt); |
| 7615 | if (rc) |
| 7616 | return -EFAULT; |
| 7617 | |
| 7618 | lbuf[cnt] = '\0'; |
| 7619 | buf = (char *)lbuf; |
| 7620 | tabla->no_mic_headset_override = (*strsep(&buf, " ") == '0') ? |
| 7621 | false : true; |
| 7622 | return rc; |
| 7623 | } |
| 7624 | |
| 7625 | static ssize_t codec_mbhc_debug_read(struct file *file, char __user *buf, |
| 7626 | size_t count, loff_t *pos) |
| 7627 | { |
| 7628 | const int size = 768; |
| 7629 | char buffer[size]; |
| 7630 | int n = 0; |
| 7631 | struct tabla_priv *tabla = file->private_data; |
| 7632 | struct snd_soc_codec *codec = tabla->codec; |
| 7633 | const struct mbhc_internal_cal_data *p = &tabla->mbhc_data; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7634 | const s16 v_ins_hu_cur = tabla_get_current_v_ins(tabla, true); |
| 7635 | 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] | 7636 | |
| 7637 | n = scnprintf(buffer, size - n, "dce_z = %x(%dmv)\n", p->dce_z, |
| 7638 | tabla_codec_sta_dce_v(codec, 1, p->dce_z)); |
| 7639 | n += scnprintf(buffer + n, size - n, "dce_mb = %x(%dmv)\n", |
| 7640 | p->dce_mb, tabla_codec_sta_dce_v(codec, 1, p->dce_mb)); |
| 7641 | n += scnprintf(buffer + n, size - n, "sta_z = %x(%dmv)\n", |
| 7642 | p->sta_z, tabla_codec_sta_dce_v(codec, 0, p->sta_z)); |
| 7643 | n += scnprintf(buffer + n, size - n, "sta_mb = %x(%dmv)\n", |
| 7644 | p->sta_mb, tabla_codec_sta_dce_v(codec, 0, p->sta_mb)); |
| 7645 | n += scnprintf(buffer + n, size - n, "t_dce = %x\n", p->t_dce); |
| 7646 | n += scnprintf(buffer + n, size - n, "t_sta = %x\n", p->t_sta); |
| 7647 | n += scnprintf(buffer + n, size - n, "micb_mv = %dmv\n", |
| 7648 | p->micb_mv); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7649 | 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] | 7650 | p->v_ins_hu, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7651 | tabla_codec_sta_dce_v(codec, 0, p->v_ins_hu), |
| 7652 | p->v_ins_hu == v_ins_hu_cur ? "*" : ""); |
| 7653 | n += scnprintf(buffer + n, size - n, "v_ins_h = %x(%dmv)%s\n", |
| 7654 | p->v_ins_h, tabla_codec_sta_dce_v(codec, 1, p->v_ins_h), |
| 7655 | p->v_ins_h == v_ins_h_cur ? "*" : ""); |
| 7656 | n += scnprintf(buffer + n, size - n, "adj_v_ins_hu = %x(%dmv)%s\n", |
| 7657 | p->adj_v_ins_hu, |
| 7658 | tabla_codec_sta_dce_v(codec, 0, p->adj_v_ins_hu), |
| 7659 | p->adj_v_ins_hu == v_ins_hu_cur ? "*" : ""); |
| 7660 | n += scnprintf(buffer + n, size - n, "adj_v_ins_h = %x(%dmv)%s\n", |
| 7661 | p->adj_v_ins_h, |
| 7662 | tabla_codec_sta_dce_v(codec, 1, p->adj_v_ins_h), |
| 7663 | p->adj_v_ins_h == v_ins_h_cur ? "*" : ""); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 7664 | n += scnprintf(buffer + n, size - n, "v_b1_hu = %x(%dmv)\n", |
| 7665 | p->v_b1_hu, tabla_codec_sta_dce_v(codec, 0, p->v_b1_hu)); |
| 7666 | n += scnprintf(buffer + n, size - n, "v_b1_h = %x(%dmv)\n", |
| 7667 | p->v_b1_h, tabla_codec_sta_dce_v(codec, 1, p->v_b1_h)); |
| 7668 | n += scnprintf(buffer + n, size - n, "v_b1_huc = %x(%dmv)\n", |
| 7669 | p->v_b1_huc, |
| 7670 | tabla_codec_sta_dce_v(codec, 1, p->v_b1_huc)); |
| 7671 | n += scnprintf(buffer + n, size - n, "v_brh = %x(%dmv)\n", |
| 7672 | p->v_brh, tabla_codec_sta_dce_v(codec, 1, p->v_brh)); |
| 7673 | n += scnprintf(buffer + n, size - n, "v_brl = %x(%dmv)\n", p->v_brl, |
| 7674 | tabla_codec_sta_dce_v(codec, 0, p->v_brl)); |
| 7675 | n += scnprintf(buffer + n, size - n, "v_no_mic = %x(%dmv)\n", |
| 7676 | p->v_no_mic, |
| 7677 | tabla_codec_sta_dce_v(codec, 0, p->v_no_mic)); |
| 7678 | n += scnprintf(buffer + n, size - n, "npoll = %d\n", p->npoll); |
| 7679 | n += scnprintf(buffer + n, size - n, "nbounce_wait = %d\n", |
| 7680 | p->nbounce_wait); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7681 | n += scnprintf(buffer + n, size - n, "v_inval_ins_low = %d\n", |
| 7682 | p->v_inval_ins_low); |
| 7683 | n += scnprintf(buffer + n, size - n, "v_inval_ins_high = %d\n", |
| 7684 | p->v_inval_ins_high); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7685 | if (tabla->mbhc_cfg.gpio) |
| 7686 | n += scnprintf(buffer + n, size - n, "GPIO insert = %d\n", |
| 7687 | tabla_hs_gpio_level_remove(tabla)); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 7688 | buffer[n] = 0; |
| 7689 | |
| 7690 | return simple_read_from_buffer(buf, count, pos, buffer, n); |
| 7691 | } |
| 7692 | |
| 7693 | static const struct file_operations codec_debug_ops = { |
| 7694 | .open = codec_debug_open, |
| 7695 | .write = codec_debug_write, |
| 7696 | }; |
| 7697 | |
| 7698 | static const struct file_operations codec_mbhc_debug_ops = { |
| 7699 | .open = codec_debug_open, |
| 7700 | .read = codec_mbhc_debug_read, |
| 7701 | }; |
| 7702 | #endif |
| 7703 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7704 | static int tabla_codec_probe(struct snd_soc_codec *codec) |
| 7705 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7706 | struct wcd9xxx *control; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7707 | struct tabla_priv *tabla; |
| 7708 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 7709 | int ret = 0; |
| 7710 | int i; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 7711 | int ch_cnt; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7712 | |
| 7713 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 7714 | control = codec->control_data; |
| 7715 | |
| 7716 | tabla = kzalloc(sizeof(struct tabla_priv), GFP_KERNEL); |
| 7717 | if (!tabla) { |
| 7718 | dev_err(codec->dev, "Failed to allocate private data\n"); |
| 7719 | return -ENOMEM; |
| 7720 | } |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 7721 | for (i = 0 ; i < NUM_DECIMATORS; i++) { |
| 7722 | tx_hpf_work[i].tabla = tabla; |
| 7723 | tx_hpf_work[i].decimator = i + 1; |
| 7724 | INIT_DELAYED_WORK(&tx_hpf_work[i].dwork, |
| 7725 | tx_hpf_corner_freq_callback); |
| 7726 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7727 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 7728 | /* Make sure mbhc micbias register addresses are zeroed out */ |
| 7729 | memset(&tabla->mbhc_bias_regs, 0, |
| 7730 | sizeof(struct mbhc_micbias_regs)); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 7731 | tabla->mbhc_micbias_switched = false; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 7732 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 7733 | /* Make sure mbhc intenal calibration data is zeroed out */ |
| 7734 | memset(&tabla->mbhc_data, 0, |
| 7735 | sizeof(struct mbhc_internal_cal_data)); |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 7736 | tabla->mbhc_data.t_sta_dce = DEFAULT_DCE_STA_WAIT; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 7737 | tabla->mbhc_data.t_dce = DEFAULT_DCE_WAIT; |
| 7738 | tabla->mbhc_data.t_sta = DEFAULT_STA_WAIT; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7739 | snd_soc_codec_set_drvdata(codec, tabla); |
| 7740 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 7741 | tabla->mclk_enabled = false; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7742 | tabla->bandgap_type = TABLA_BANDGAP_OFF; |
| 7743 | tabla->clock_active = false; |
| 7744 | tabla->config_mode_active = false; |
| 7745 | tabla->mbhc_polling_active = false; |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 7746 | tabla->mbhc_fake_ins_start = 0; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 7747 | tabla->no_mic_headset_override = false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7748 | tabla->hs_polling_irq_prepared = false; |
| 7749 | mutex_init(&tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7750 | tabla->codec = codec; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7751 | tabla->mbhc_state = MBHC_STATE_NONE; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7752 | tabla->mbhc_last_resume = 0; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 7753 | for (i = 0; i < COMPANDER_MAX; i++) { |
| 7754 | tabla->comp_enabled[i] = 0; |
| 7755 | tabla->comp_fs[i] = COMPANDER_FS_48KHZ; |
| 7756 | } |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7757 | tabla->pdata = dev_get_platdata(codec->dev->parent); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7758 | tabla->intf_type = wcd9xxx_get_intf_type(); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 7759 | tabla->aux_pga_cnt = 0; |
| 7760 | tabla->aux_l_gain = 0x1F; |
| 7761 | tabla->aux_r_gain = 0x1F; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7762 | tabla_update_reg_address(tabla); |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 7763 | tabla_update_reg_defaults(codec); |
| 7764 | tabla_codec_init_reg(codec); |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 7765 | ret = tabla_handle_pdata(tabla); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7766 | if (IS_ERR_VALUE(ret)) { |
| 7767 | pr_err("%s: bad pdata\n", __func__); |
| 7768 | goto err_pdata; |
| 7769 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7770 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 7771 | // snd_soc_add_codec_controls(codec, tabla_snd_controls, |
| 7772 | // ARRAY_SIZE(tabla_snd_controls)); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7773 | if (TABLA_IS_1_X(control->version)) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 7774 | snd_soc_add_codec_controls(codec, tabla_1_x_snd_controls, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7775 | ARRAY_SIZE(tabla_1_x_snd_controls)); |
| 7776 | else |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 7777 | snd_soc_add_codec_controls(codec, tabla_2_higher_snd_controls, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7778 | ARRAY_SIZE(tabla_2_higher_snd_controls)); |
| 7779 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 7780 | // snd_soc_dapm_new_controls(dapm, tabla_dapm_widgets, |
| 7781 | // ARRAY_SIZE(tabla_dapm_widgets)); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 7782 | |
| 7783 | snd_soc_dapm_new_controls(dapm, tabla_dapm_aif_in_widgets, |
| 7784 | ARRAY_SIZE(tabla_dapm_aif_in_widgets)); |
| 7785 | |
| 7786 | snd_soc_dapm_new_controls(dapm, tabla_dapm_aif_out_widgets, |
| 7787 | ARRAY_SIZE(tabla_dapm_aif_out_widgets)); |
| 7788 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7789 | if (TABLA_IS_1_X(control->version)) |
| 7790 | snd_soc_dapm_new_controls(dapm, tabla_1_x_dapm_widgets, |
| 7791 | ARRAY_SIZE(tabla_1_x_dapm_widgets)); |
| 7792 | else |
| 7793 | snd_soc_dapm_new_controls(dapm, tabla_2_higher_dapm_widgets, |
| 7794 | ARRAY_SIZE(tabla_2_higher_dapm_widgets)); |
| 7795 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7796 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 7797 | snd_soc_dapm_new_controls(dapm, tabla_dapm_i2s_widgets, |
| 7798 | ARRAY_SIZE(tabla_dapm_i2s_widgets)); |
| 7799 | snd_soc_dapm_add_routes(dapm, audio_i2s_map, |
| 7800 | ARRAY_SIZE(audio_i2s_map)); |
| 7801 | } |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 7802 | // snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 7803 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7804 | if (TABLA_IS_1_X(control->version)) { |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 7805 | 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] | 7806 | ARRAY_SIZE(tabla_1_x_lineout_2_to_4_map)); |
| 7807 | } else if (TABLA_IS_2_0(control->version)) { |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 7808 | 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] | 7809 | ARRAY_SIZE(tabla_2_x_lineout_2_to_4_map)); |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 7810 | } else { |
| 7811 | pr_err("%s : ERROR. Unsupported Tabla version 0x%2x\n", |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7812 | __func__, control->version); |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 7813 | goto err_pdata; |
| 7814 | } |
| 7815 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7816 | snd_soc_dapm_sync(dapm); |
| 7817 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7818 | ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7819 | tabla_hs_insert_irq, "Headset insert detect", tabla); |
| 7820 | if (ret) { |
| 7821 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7822 | TABLA_IRQ_MBHC_INSERTION); |
| 7823 | goto err_insert_irq; |
| 7824 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7825 | wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7826 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7827 | ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7828 | tabla_hs_remove_irq, "Headset remove detect", tabla); |
| 7829 | if (ret) { |
| 7830 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7831 | TABLA_IRQ_MBHC_REMOVAL); |
| 7832 | goto err_remove_irq; |
| 7833 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7834 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7835 | ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7836 | tabla_dce_handler, "DC Estimation detect", tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7837 | if (ret) { |
| 7838 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7839 | TABLA_IRQ_MBHC_POTENTIAL); |
| 7840 | goto err_potential_irq; |
| 7841 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7842 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7843 | ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7844 | tabla_release_handler, "Button Release detect", tabla); |
| 7845 | if (ret) { |
| 7846 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7847 | TABLA_IRQ_MBHC_RELEASE); |
| 7848 | goto err_release_irq; |
| 7849 | } |
| 7850 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7851 | ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_SLIMBUS, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7852 | tabla_slimbus_irq, "SLIMBUS Slave", tabla); |
| 7853 | if (ret) { |
| 7854 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7855 | TABLA_IRQ_SLIMBUS); |
| 7856 | goto err_slimbus_irq; |
| 7857 | } |
| 7858 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7859 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) |
| 7860 | wcd9xxx_interface_reg_write(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7861 | TABLA_SLIM_PGD_PORT_INT_EN0 + i, 0xFF); |
| 7862 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7863 | ret = wcd9xxx_request_irq(codec->control_data, |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7864 | TABLA_IRQ_HPH_PA_OCPL_FAULT, tabla_hphl_ocp_irq, |
| 7865 | "HPH_L OCP detect", tabla); |
| 7866 | if (ret) { |
| 7867 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7868 | TABLA_IRQ_HPH_PA_OCPL_FAULT); |
| 7869 | goto err_hphl_ocp_irq; |
| 7870 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7871 | wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7872 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7873 | ret = wcd9xxx_request_irq(codec->control_data, |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7874 | TABLA_IRQ_HPH_PA_OCPR_FAULT, tabla_hphr_ocp_irq, |
| 7875 | "HPH_R OCP detect", tabla); |
| 7876 | if (ret) { |
| 7877 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7878 | TABLA_IRQ_HPH_PA_OCPR_FAULT); |
| 7879 | goto err_hphr_ocp_irq; |
| 7880 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7881 | wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_HPH_PA_OCPR_FAULT); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 7882 | for (i = 0; i < ARRAY_SIZE(tabla_dai); i++) { |
| 7883 | switch (tabla_dai[i].id) { |
| 7884 | case AIF1_PB: |
| 7885 | ch_cnt = tabla_dai[i].playback.channels_max; |
| 7886 | break; |
| 7887 | case AIF1_CAP: |
| 7888 | ch_cnt = tabla_dai[i].capture.channels_max; |
| 7889 | break; |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 7890 | case AIF2_PB: |
| 7891 | ch_cnt = tabla_dai[i].playback.channels_max; |
| 7892 | break; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 7893 | case AIF2_CAP: |
| 7894 | ch_cnt = tabla_dai[i].capture.channels_max; |
| 7895 | break; |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 7896 | case AIF3_PB: |
| 7897 | ch_cnt = tabla_dai[i].playback.channels_max; |
| 7898 | break; |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 7899 | case AIF3_CAP: |
| 7900 | ch_cnt = tabla_dai[i].capture.channels_max; |
| 7901 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 7902 | default: |
| 7903 | continue; |
| 7904 | } |
| 7905 | tabla->dai[i].ch_num = kzalloc((sizeof(unsigned int)* |
| 7906 | ch_cnt), GFP_KERNEL); |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 7907 | init_waitqueue_head(&tabla->dai[i].dai_wait); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 7908 | } |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7909 | |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 7910 | #ifdef CONFIG_DEBUG_FS |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 7911 | if (ret == 0) { |
| 7912 | tabla->debugfs_poke = |
| 7913 | debugfs_create_file("TRRS", S_IFREG | S_IRUGO, NULL, tabla, |
| 7914 | &codec_debug_ops); |
| 7915 | tabla->debugfs_mbhc = |
| 7916 | debugfs_create_file("tabla_mbhc", S_IFREG | S_IRUGO, |
| 7917 | NULL, tabla, &codec_mbhc_debug_ops); |
| 7918 | } |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 7919 | #endif |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 7920 | codec->ignore_pmdown_time = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7921 | return ret; |
| 7922 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7923 | err_hphr_ocp_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7924 | wcd9xxx_free_irq(codec->control_data, |
| 7925 | TABLA_IRQ_HPH_PA_OCPL_FAULT, tabla); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7926 | err_hphl_ocp_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7927 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_SLIMBUS, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7928 | err_slimbus_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7929 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, tabla); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7930 | err_release_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7931 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7932 | err_potential_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7933 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7934 | err_remove_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7935 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7936 | err_insert_irq: |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7937 | err_pdata: |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7938 | mutex_destroy(&tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7939 | kfree(tabla); |
| 7940 | return ret; |
| 7941 | } |
| 7942 | static int tabla_codec_remove(struct snd_soc_codec *codec) |
| 7943 | { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 7944 | int i; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7945 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7946 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_SLIMBUS, tabla); |
| 7947 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, tabla); |
| 7948 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, tabla); |
| 7949 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, tabla); |
| 7950 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7951 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7952 | tabla_codec_disable_clock_block(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7953 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7954 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF); |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 7955 | if (tabla->mbhc_fw) |
| 7956 | release_firmware(tabla->mbhc_fw); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 7957 | for (i = 0; i < ARRAY_SIZE(tabla_dai); i++) |
| 7958 | kfree(tabla->dai[i].ch_num); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7959 | mutex_destroy(&tabla->codec_resource_lock); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 7960 | #ifdef CONFIG_DEBUG_FS |
| 7961 | debugfs_remove(tabla->debugfs_poke); |
| 7962 | debugfs_remove(tabla->debugfs_mbhc); |
| 7963 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7964 | kfree(tabla); |
| 7965 | return 0; |
| 7966 | } |
| 7967 | static struct snd_soc_codec_driver soc_codec_dev_tabla = { |
| 7968 | .probe = tabla_codec_probe, |
| 7969 | .remove = tabla_codec_remove, |
| 7970 | .read = tabla_read, |
| 7971 | .write = tabla_write, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7972 | .readable_register = tabla_readable, |
| 7973 | .volatile_register = tabla_volatile, |
| 7974 | |
| 7975 | .reg_cache_size = TABLA_CACHE_SIZE, |
| 7976 | .reg_cache_default = tabla_reg_defaults, |
| 7977 | .reg_word_size = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 7978 | .controls = tabla_snd_controls, |
| 7979 | .num_controls = ARRAY_SIZE(tabla_snd_controls), |
| 7980 | .dapm_widgets = tabla_dapm_widgets, |
| 7981 | .num_dapm_widgets = ARRAY_SIZE(tabla_dapm_widgets), |
| 7982 | .dapm_routes = audio_map, |
| 7983 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7984 | }; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 7985 | |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 7986 | #ifdef CONFIG_PM |
| 7987 | static int tabla_suspend(struct device *dev) |
| 7988 | { |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 7989 | dev_dbg(dev, "%s: system suspend\n", __func__); |
| 7990 | return 0; |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 7991 | } |
| 7992 | |
| 7993 | static int tabla_resume(struct device *dev) |
| 7994 | { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7995 | struct platform_device *pdev = to_platform_device(dev); |
| 7996 | struct tabla_priv *tabla = platform_get_drvdata(pdev); |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 7997 | dev_dbg(dev, "%s: system resume\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7998 | tabla->mbhc_last_resume = jiffies; |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 7999 | return 0; |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 8000 | } |
| 8001 | |
| 8002 | static const struct dev_pm_ops tabla_pm_ops = { |
| 8003 | .suspend = tabla_suspend, |
| 8004 | .resume = tabla_resume, |
| 8005 | }; |
| 8006 | #endif |
| 8007 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8008 | static int __devinit tabla_probe(struct platform_device *pdev) |
| 8009 | { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 8010 | int ret = 0; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 8011 | pr_err("tabla_probe\n"); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8012 | if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 8013 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla, |
| 8014 | tabla_dai, ARRAY_SIZE(tabla_dai)); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8015 | else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 8016 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla, |
| 8017 | tabla_i2s_dai, ARRAY_SIZE(tabla_i2s_dai)); |
| 8018 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8019 | } |
| 8020 | static int __devexit tabla_remove(struct platform_device *pdev) |
| 8021 | { |
| 8022 | snd_soc_unregister_codec(&pdev->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8023 | return 0; |
| 8024 | } |
| 8025 | static struct platform_driver tabla_codec_driver = { |
| 8026 | .probe = tabla_probe, |
| 8027 | .remove = tabla_remove, |
| 8028 | .driver = { |
| 8029 | .name = "tabla_codec", |
| 8030 | .owner = THIS_MODULE, |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 8031 | #ifdef CONFIG_PM |
| 8032 | .pm = &tabla_pm_ops, |
| 8033 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8034 | }, |
| 8035 | }; |
| 8036 | |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 8037 | static struct platform_driver tabla1x_codec_driver = { |
| 8038 | .probe = tabla_probe, |
| 8039 | .remove = tabla_remove, |
| 8040 | .driver = { |
| 8041 | .name = "tabla1x_codec", |
| 8042 | .owner = THIS_MODULE, |
| 8043 | #ifdef CONFIG_PM |
| 8044 | .pm = &tabla_pm_ops, |
| 8045 | #endif |
| 8046 | }, |
| 8047 | }; |
| 8048 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8049 | static int __init tabla_codec_init(void) |
| 8050 | { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 8051 | int rtn = platform_driver_register(&tabla_codec_driver); |
| 8052 | if (rtn == 0) { |
| 8053 | rtn = platform_driver_register(&tabla1x_codec_driver); |
| 8054 | if (rtn != 0) |
| 8055 | platform_driver_unregister(&tabla_codec_driver); |
| 8056 | } |
| 8057 | return rtn; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8058 | } |
| 8059 | |
| 8060 | static void __exit tabla_codec_exit(void) |
| 8061 | { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 8062 | platform_driver_unregister(&tabla1x_codec_driver); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8063 | platform_driver_unregister(&tabla_codec_driver); |
| 8064 | } |
| 8065 | |
| 8066 | module_init(tabla_codec_init); |
| 8067 | module_exit(tabla_codec_exit); |
| 8068 | |
| 8069 | MODULE_DESCRIPTION("Tabla codec driver"); |
| 8070 | MODULE_VERSION("1.0"); |
| 8071 | MODULE_LICENSE("GPL v2"); |