Mohammad Johny Shaik | abb80c6 | 2013-12-27 11:02:02 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [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> |
| 14 | #include <linux/firmware.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/printk.h> |
| 19 | #include <linux/ratelimit.h> |
| 20 | #include <linux/debugfs.h> |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 21 | #include <linux/wait.h> |
| 22 | #include <linux/bitops.h> |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 23 | #include <linux/mfd/wcd9xxx/core.h> |
| 24 | #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h> |
| 25 | #include <linux/mfd/wcd9xxx/wcd9306_registers.h> |
| 26 | #include <linux/mfd/wcd9xxx/pdata.h> |
Bhalchandra Gajare | 5b4199c | 2013-07-03 14:35:43 -0700 | [diff] [blame] | 27 | #include <linux/regulator/consumer.h> |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 28 | #include <sound/pcm.h> |
| 29 | #include <sound/pcm_params.h> |
| 30 | #include <sound/soc.h> |
| 31 | #include <sound/soc-dapm.h> |
| 32 | #include <sound/tlv.h> |
| 33 | #include <linux/bitops.h> |
| 34 | #include <linux/delay.h> |
| 35 | #include <linux/pm_runtime.h> |
| 36 | #include <linux/kernel.h> |
| 37 | #include <linux/gpio.h> |
| 38 | #include "wcd9306.h" |
| 39 | #include "wcd9xxx-resmgr.h" |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 40 | #include "wcd9xxx-common.h" |
| 41 | |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 42 | #define TAPAN_HPH_PA_SETTLE_COMP_ON 3000 |
| 43 | #define TAPAN_HPH_PA_SETTLE_COMP_OFF 13000 |
| 44 | |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 45 | #define DAPM_MICBIAS2_EXTERNAL_STANDALONE "MIC BIAS2 External Standalone" |
Venkat Sudhir | bb44447 | 2014-01-14 10:03:23 -0800 | [diff] [blame] | 46 | #define TAPAN_VALIDATE_RX_SBPORT_RANGE(port) ((port >= 16) && (port <= 20)) |
| 47 | #define TAPAN_CONVERT_RX_SBPORT_ID(port) (port - 16) /* RX1 port ID = 0 */ |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 48 | |
Bhalchandra Gajare | 4e3dd85 | 2013-08-19 17:21:23 -0700 | [diff] [blame] | 49 | #define TAPAN_VDD_CX_OPTIMAL_UA 10000 |
| 50 | #define TAPAN_VDD_CX_SLEEP_UA 2000 |
| 51 | |
Phani Kumar Uppalapati | 01a77e1 | 2013-08-08 15:31:35 -0700 | [diff] [blame] | 52 | /* RX_HPH_CNP_WG_TIME increases by 0.24ms */ |
| 53 | #define TAPAN_WG_TIME_FACTOR_US 240 |
| 54 | |
Damir Didjusto | d6aea99 | 2013-09-03 21:18:59 -0700 | [diff] [blame] | 55 | #define TAPAN_SB_PGD_PORT_RX_BASE 0x40 |
| 56 | #define TAPAN_SB_PGD_PORT_TX_BASE 0x50 |
| 57 | #define TAPAN_REGISTER_START_OFFSET 0x800 |
| 58 | |
| 59 | #define CODEC_REG_CFG_MINOR_VER 1 |
| 60 | |
Bhalchandra Gajare | 4e3dd85 | 2013-08-19 17:21:23 -0700 | [diff] [blame] | 61 | static struct regulator *tapan_codec_find_regulator( |
| 62 | struct snd_soc_codec *codec, |
| 63 | const char *name); |
| 64 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 65 | static atomic_t kp_tapan_priv; |
| 66 | static int spkr_drv_wrnd_param_set(const char *val, |
| 67 | const struct kernel_param *kp); |
| 68 | static int spkr_drv_wrnd = 1; |
| 69 | |
| 70 | static struct kernel_param_ops spkr_drv_wrnd_param_ops = { |
| 71 | .set = spkr_drv_wrnd_param_set, |
| 72 | .get = param_get_int, |
| 73 | }; |
| 74 | module_param_cb(spkr_drv_wrnd, &spkr_drv_wrnd_param_ops, &spkr_drv_wrnd, 0644); |
| 75 | MODULE_PARM_DESC(spkr_drv_wrnd, |
| 76 | "Run software workaround to avoid leakage on the speaker drive"); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 77 | |
| 78 | #define WCD9306_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ |
| 79 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\ |
| 80 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000) |
| 81 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 82 | #define WCD9302_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ |
| 83 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000) |
| 84 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 85 | #define NUM_DECIMATORS 4 |
| 86 | #define NUM_INTERPOLATORS 4 |
| 87 | #define BITS_PER_REG 8 |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 88 | /* This actual number of TX ports supported in slimbus slave */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 89 | #define TAPAN_TX_PORT_NUMBER 16 |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 90 | #define TAPAN_RX_PORT_START_NUMBER 16 |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 91 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 92 | /* Nummer of TX ports actually connected from Slimbus slave to codec Digital */ |
| 93 | #define TAPAN_SLIM_CODEC_TX_PORTS 5 |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 94 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 95 | #define TAPAN_I2S_MASTER_MODE_MASK 0x08 |
| 96 | #define TAPAN_MCLK_CLK_12P288MHZ 12288000 |
Phani Kumar Uppalapati | 43bc415 | 2013-05-24 00:44:20 -0700 | [diff] [blame] | 97 | #define TAPAN_MCLK_CLK_9P6MHZ 9600000 |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 98 | |
| 99 | #define TAPAN_SLIM_CLOSE_TIMEOUT 1000 |
| 100 | #define TAPAN_SLIM_IRQ_OVERFLOW (1 << 0) |
| 101 | #define TAPAN_SLIM_IRQ_UNDERFLOW (1 << 1) |
| 102 | #define TAPAN_SLIM_IRQ_PORT_CLOSED (1 << 2) |
Simmi Pateriya | 95466b1 | 2013-05-09 20:08:46 +0530 | [diff] [blame] | 103 | |
Phani Kumar Uppalapati | cc3ec0c | 2013-09-06 18:04:03 -0700 | [diff] [blame] | 104 | enum tapan_codec_type { |
| 105 | WCD9306, |
| 106 | WCD9302, |
| 107 | }; |
| 108 | |
| 109 | static enum tapan_codec_type codec_ver; |
| 110 | |
Phani Kumar Uppalapati | 01a77e1 | 2013-08-08 15:31:35 -0700 | [diff] [blame] | 111 | /* |
| 112 | * Multiplication factor to compute impedance on Tapan |
| 113 | * This is computed from (Vx / (m*Ical)) = (10mV/(180*30uA)) |
| 114 | */ |
| 115 | #define TAPAN_ZDET_MUL_FACTOR 1852 |
| 116 | |
Damir Didjusto | d6aea99 | 2013-09-03 21:18:59 -0700 | [diff] [blame] | 117 | static struct afe_param_cdc_reg_cfg audio_reg_cfg[] = { |
| 118 | { |
| 119 | CODEC_REG_CFG_MINOR_VER, |
| 120 | (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_TX_BASE), |
| 121 | SB_PGD_PORT_TX_WATERMARK_N, 0x1E, 8, 0x1 |
| 122 | }, |
| 123 | { |
| 124 | CODEC_REG_CFG_MINOR_VER, |
| 125 | (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_TX_BASE), |
| 126 | SB_PGD_PORT_TX_ENABLE_N, 0x1, 8, 0x1 |
| 127 | }, |
| 128 | { |
| 129 | CODEC_REG_CFG_MINOR_VER, |
| 130 | (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_RX_BASE), |
| 131 | SB_PGD_PORT_RX_WATERMARK_N, 0x1E, 8, 0x1 |
| 132 | }, |
| 133 | { |
| 134 | CODEC_REG_CFG_MINOR_VER, |
| 135 | (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_RX_BASE), |
| 136 | SB_PGD_PORT_RX_ENABLE_N, 0x1, 8, 0x1 |
| 137 | }, |
| 138 | { |
| 139 | CODEC_REG_CFG_MINOR_VER, |
| 140 | (TAPAN_REGISTER_START_OFFSET + TAPAN_A_CDC_ANC1_IIR_B1_CTL), |
| 141 | AANC_FF_GAIN_ADAPTIVE, 0x4, 8, 0 |
| 142 | }, |
| 143 | { |
| 144 | CODEC_REG_CFG_MINOR_VER, |
| 145 | (TAPAN_REGISTER_START_OFFSET + TAPAN_A_CDC_ANC1_IIR_B1_CTL), |
| 146 | AANC_FFGAIN_ADAPTIVE_EN, 0x8, 8, 0 |
| 147 | }, |
| 148 | { |
| 149 | CODEC_REG_CFG_MINOR_VER, |
| 150 | (TAPAN_REGISTER_START_OFFSET + TAPAN_A_CDC_ANC1_GAIN_CTL), |
| 151 | AANC_GAIN_CONTROL, 0xFF, 8, 0 |
| 152 | }, |
| 153 | }; |
| 154 | |
| 155 | static struct afe_param_cdc_reg_cfg_data tapan_audio_reg_cfg = { |
| 156 | .num_registers = ARRAY_SIZE(audio_reg_cfg), |
| 157 | .reg_data = audio_reg_cfg, |
| 158 | }; |
| 159 | |
| 160 | static struct afe_param_id_cdc_aanc_version tapan_cdc_aanc_version = { |
| 161 | .cdc_aanc_minor_version = AFE_API_VERSION_CDC_AANC_VERSION, |
| 162 | .aanc_hw_version = AANC_HW_BLOCK_VERSION_2, |
| 163 | }; |
| 164 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 165 | enum { |
| 166 | AIF1_PB = 0, |
| 167 | AIF1_CAP, |
| 168 | AIF2_PB, |
| 169 | AIF2_CAP, |
| 170 | AIF3_PB, |
| 171 | AIF3_CAP, |
| 172 | NUM_CODEC_DAIS, |
| 173 | }; |
| 174 | |
| 175 | enum { |
| 176 | RX_MIX1_INP_SEL_ZERO = 0, |
| 177 | RX_MIX1_INP_SEL_SRC1, |
| 178 | RX_MIX1_INP_SEL_SRC2, |
| 179 | RX_MIX1_INP_SEL_IIR1, |
| 180 | RX_MIX1_INP_SEL_IIR2, |
| 181 | RX_MIX1_INP_SEL_RX1, |
| 182 | RX_MIX1_INP_SEL_RX2, |
| 183 | RX_MIX1_INP_SEL_RX3, |
| 184 | RX_MIX1_INP_SEL_RX4, |
| 185 | RX_MIX1_INP_SEL_RX5, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 186 | RX_MIX1_INP_SEL_AUXRX, |
| 187 | }; |
| 188 | |
| 189 | #define TAPAN_COMP_DIGITAL_GAIN_OFFSET 3 |
| 190 | |
| 191 | static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0); |
| 192 | static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1); |
| 193 | static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1); |
| 194 | static struct snd_soc_dai_driver tapan_dai[]; |
| 195 | static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0); |
| 196 | |
| 197 | /* Codec supports 2 IIR filters */ |
| 198 | enum { |
| 199 | IIR1 = 0, |
| 200 | IIR2, |
| 201 | IIR_MAX, |
| 202 | }; |
| 203 | /* Codec supports 5 bands */ |
| 204 | enum { |
| 205 | BAND1 = 0, |
| 206 | BAND2, |
| 207 | BAND3, |
| 208 | BAND4, |
| 209 | BAND5, |
| 210 | BAND_MAX, |
| 211 | }; |
| 212 | |
| 213 | enum { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 214 | COMPANDER_0, |
| 215 | COMPANDER_1, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 216 | COMPANDER_2, |
| 217 | COMPANDER_MAX, |
| 218 | }; |
| 219 | |
| 220 | enum { |
| 221 | COMPANDER_FS_8KHZ = 0, |
| 222 | COMPANDER_FS_16KHZ, |
| 223 | COMPANDER_FS_32KHZ, |
| 224 | COMPANDER_FS_48KHZ, |
| 225 | COMPANDER_FS_96KHZ, |
| 226 | COMPANDER_FS_192KHZ, |
| 227 | COMPANDER_FS_MAX, |
| 228 | }; |
| 229 | |
| 230 | struct comp_sample_dependent_params { |
| 231 | u32 peak_det_timeout; |
| 232 | u32 rms_meter_div_fact; |
| 233 | u32 rms_meter_resamp_fact; |
| 234 | }; |
| 235 | |
| 236 | struct hpf_work { |
| 237 | struct tapan_priv *tapan; |
| 238 | u32 decimator; |
| 239 | u8 tx_hpf_cut_of_freq; |
| 240 | struct delayed_work dwork; |
| 241 | }; |
| 242 | |
| 243 | static struct hpf_work tx_hpf_work[NUM_DECIMATORS]; |
| 244 | |
| 245 | static const struct wcd9xxx_ch tapan_rx_chs[TAPAN_RX_MAX] = { |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 246 | WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER, 0), |
| 247 | WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 1, 1), |
| 248 | WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 2, 2), |
| 249 | WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 3, 3), |
| 250 | WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 4, 4), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 251 | }; |
| 252 | |
| 253 | static const struct wcd9xxx_ch tapan_tx_chs[TAPAN_TX_MAX] = { |
| 254 | WCD9XXX_CH(0, 0), |
| 255 | WCD9XXX_CH(1, 1), |
| 256 | WCD9XXX_CH(2, 2), |
| 257 | WCD9XXX_CH(3, 3), |
| 258 | WCD9XXX_CH(4, 4), |
| 259 | }; |
| 260 | |
| 261 | static const u32 vport_check_table[NUM_CODEC_DAIS] = { |
| 262 | 0, /* AIF1_PB */ |
| 263 | (1 << AIF2_CAP) | (1 << AIF3_CAP), /* AIF1_CAP */ |
| 264 | 0, /* AIF2_PB */ |
| 265 | (1 << AIF1_CAP) | (1 << AIF3_CAP), /* AIF2_CAP */ |
| 266 | 0, /* AIF2_PB */ |
| 267 | (1 << AIF1_CAP) | (1 << AIF2_CAP), /* AIF2_CAP */ |
| 268 | }; |
| 269 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 270 | static const u32 vport_i2s_check_table[NUM_CODEC_DAIS] = { |
| 271 | 0, /* AIF1_PB */ |
| 272 | 0, /* AIF1_CAP */ |
| 273 | }; |
| 274 | |
Bhalchandra Gajare | 5b4199c | 2013-07-03 14:35:43 -0700 | [diff] [blame] | 275 | enum { |
| 276 | CP_REG_BUCK = 0, |
| 277 | CP_REG_BHELPER, |
| 278 | CP_REG_MAX, |
| 279 | }; |
| 280 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 281 | struct tapan_priv { |
| 282 | struct snd_soc_codec *codec; |
| 283 | u32 adc_count; |
| 284 | u32 rx_bias_count; |
| 285 | s32 dmic_1_2_clk_cnt; |
| 286 | s32 dmic_3_4_clk_cnt; |
| 287 | s32 dmic_5_6_clk_cnt; |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 288 | s32 ldo_h_users; |
| 289 | s32 micb_2_users; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 290 | |
| 291 | u32 anc_slot; |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 292 | bool anc_func; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 293 | |
| 294 | /*track tapan interface type*/ |
| 295 | u8 intf_type; |
| 296 | |
| 297 | /* num of slim ports required */ |
| 298 | struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS]; |
| 299 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 300 | /*compander*/ |
| 301 | int comp_enabled[COMPANDER_MAX]; |
| 302 | u32 comp_fs[COMPANDER_MAX]; |
| 303 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 304 | /* Maintain the status of AUX PGA */ |
| 305 | int aux_pga_cnt; |
| 306 | u8 aux_l_gain; |
| 307 | u8 aux_r_gain; |
| 308 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 309 | bool spkr_pa_widget_on; |
| 310 | |
Damir Didjusto | d6aea99 | 2013-09-03 21:18:59 -0700 | [diff] [blame] | 311 | struct afe_param_cdc_slimbus_slave_cfg slimbus_slave_cfg; |
| 312 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 313 | /* resmgr module */ |
| 314 | struct wcd9xxx_resmgr resmgr; |
| 315 | /* mbhc module */ |
| 316 | struct wcd9xxx_mbhc mbhc; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 317 | |
| 318 | /* class h specific data */ |
| 319 | struct wcd9xxx_clsh_cdc_data clsh_d; |
Bhalchandra Gajare | 5b4199c | 2013-07-03 14:35:43 -0700 | [diff] [blame] | 320 | |
| 321 | /* pointers to regulators required for chargepump */ |
| 322 | struct regulator *cp_regulators[CP_REG_MAX]; |
Phani Kumar Uppalapati | 01a77e1 | 2013-08-08 15:31:35 -0700 | [diff] [blame] | 323 | |
| 324 | /* |
| 325 | * list used to save/restore registers at start and |
| 326 | * end of impedance measurement |
| 327 | */ |
| 328 | struct list_head reg_save_restore; |
Damir Didjusto | d6aea99 | 2013-09-03 21:18:59 -0700 | [diff] [blame] | 329 | |
| 330 | int (*machine_codec_event_cb)(struct snd_soc_codec *codec, |
| 331 | enum wcd9xxx_codec_event); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 332 | }; |
| 333 | |
| 334 | static const u32 comp_shift[] = { |
| 335 | 0, |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 336 | 1, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 337 | 2, |
| 338 | }; |
| 339 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 340 | static const int comp_rx_path[] = { |
| 341 | COMPANDER_1, |
| 342 | COMPANDER_1, |
| 343 | COMPANDER_2, |
| 344 | COMPANDER_2, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 345 | COMPANDER_MAX, |
| 346 | }; |
| 347 | |
| 348 | static const struct comp_sample_dependent_params comp_samp_params[] = { |
| 349 | { |
| 350 | /* 8 Khz */ |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 351 | .peak_det_timeout = 0x06, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 352 | .rms_meter_div_fact = 0x09, |
| 353 | .rms_meter_resamp_fact = 0x06, |
| 354 | }, |
| 355 | { |
| 356 | /* 16 Khz */ |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 357 | .peak_det_timeout = 0x07, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 358 | .rms_meter_div_fact = 0x0A, |
| 359 | .rms_meter_resamp_fact = 0x0C, |
| 360 | }, |
| 361 | { |
| 362 | /* 32 Khz */ |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 363 | .peak_det_timeout = 0x08, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 364 | .rms_meter_div_fact = 0x0B, |
| 365 | .rms_meter_resamp_fact = 0x1E, |
| 366 | }, |
| 367 | { |
| 368 | /* 48 Khz */ |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 369 | .peak_det_timeout = 0x09, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 370 | .rms_meter_div_fact = 0x0B, |
| 371 | .rms_meter_resamp_fact = 0x28, |
| 372 | }, |
| 373 | { |
| 374 | /* 96 Khz */ |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 375 | .peak_det_timeout = 0x0A, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 376 | .rms_meter_div_fact = 0x0C, |
| 377 | .rms_meter_resamp_fact = 0x50, |
| 378 | }, |
| 379 | { |
| 380 | /* 192 Khz */ |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 381 | .peak_det_timeout = 0x0B, |
| 382 | .rms_meter_div_fact = 0xC, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 383 | .rms_meter_resamp_fact = 0xA0, |
| 384 | }, |
| 385 | }; |
| 386 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 387 | static unsigned short rx_digital_gain_reg[] = { |
| 388 | TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 389 | TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 390 | TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 391 | TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 392 | }; |
| 393 | |
| 394 | static unsigned short tx_digital_gain_reg[] = { |
| 395 | TAPAN_A_CDC_TX1_VOL_CTL_GAIN, |
| 396 | TAPAN_A_CDC_TX2_VOL_CTL_GAIN, |
| 397 | TAPAN_A_CDC_TX3_VOL_CTL_GAIN, |
| 398 | TAPAN_A_CDC_TX4_VOL_CTL_GAIN, |
| 399 | }; |
| 400 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 401 | static int spkr_drv_wrnd_param_set(const char *val, |
| 402 | const struct kernel_param *kp) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 403 | { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 404 | struct snd_soc_codec *codec; |
| 405 | int ret, old; |
| 406 | struct tapan_priv *priv; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 407 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 408 | priv = (struct tapan_priv *)atomic_read(&kp_tapan_priv); |
| 409 | if (!priv) { |
| 410 | pr_debug("%s: codec isn't yet registered\n", __func__); |
| 411 | return 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 412 | } |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 413 | |
Joonwoo Park | 973fd35 | 2013-06-19 11:38:53 -0700 | [diff] [blame] | 414 | codec = priv->codec; |
| 415 | mutex_lock(&codec->mutex); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 416 | old = spkr_drv_wrnd; |
| 417 | ret = param_set_int(val, kp); |
| 418 | if (ret) { |
Joonwoo Park | 973fd35 | 2013-06-19 11:38:53 -0700 | [diff] [blame] | 419 | mutex_unlock(&codec->mutex); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 420 | return ret; |
| 421 | } |
| 422 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 423 | dev_dbg(codec->dev, "%s: spkr_drv_wrnd %d -> %d\n", |
| 424 | __func__, old, spkr_drv_wrnd); |
Joonwoo Park | 973fd35 | 2013-06-19 11:38:53 -0700 | [diff] [blame] | 425 | if ((old == -1 || old == 0) && spkr_drv_wrnd == 1) { |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 426 | WCD9XXX_BG_CLK_LOCK(&priv->resmgr); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 427 | wcd9xxx_resmgr_get_bandgap(&priv->resmgr, |
| 428 | WCD9XXX_BANDGAP_AUDIO_MODE); |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 429 | WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 430 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80); |
| 431 | } else if (old == 1 && spkr_drv_wrnd == 0) { |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 432 | WCD9XXX_BG_CLK_LOCK(&priv->resmgr); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 433 | wcd9xxx_resmgr_put_bandgap(&priv->resmgr, |
| 434 | WCD9XXX_BANDGAP_AUDIO_MODE); |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 435 | WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 436 | if (!priv->spkr_pa_widget_on) |
| 437 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, |
| 438 | 0x00); |
| 439 | } |
Joonwoo Park | 973fd35 | 2013-06-19 11:38:53 -0700 | [diff] [blame] | 440 | mutex_unlock(&codec->mutex); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 441 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 442 | return 0; |
| 443 | } |
| 444 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 445 | static int tapan_get_anc_slot(struct snd_kcontrol *kcontrol, |
| 446 | struct snd_ctl_elem_value *ucontrol) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 447 | { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 448 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 449 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 450 | ucontrol->value.integer.value[0] = tapan->anc_slot; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 451 | return 0; |
| 452 | } |
| 453 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 454 | static int tapan_put_anc_slot(struct snd_kcontrol *kcontrol, |
| 455 | struct snd_ctl_elem_value *ucontrol) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 456 | { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 457 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 458 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 459 | tapan->anc_slot = ucontrol->value.integer.value[0]; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 460 | return 0; |
| 461 | } |
| 462 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 463 | static int tapan_get_anc_func(struct snd_kcontrol *kcontrol, |
| 464 | struct snd_ctl_elem_value *ucontrol) |
| 465 | { |
| 466 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 467 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 468 | |
| 469 | ucontrol->value.integer.value[0] = (tapan->anc_func == true ? 1 : 0); |
| 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | static int tapan_put_anc_func(struct snd_kcontrol *kcontrol, |
| 474 | struct snd_ctl_elem_value *ucontrol) |
| 475 | { |
| 476 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 477 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 478 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 479 | |
| 480 | mutex_lock(&dapm->codec->mutex); |
| 481 | tapan->anc_func = (!ucontrol->value.integer.value[0] ? false : true); |
| 482 | |
| 483 | dev_err(codec->dev, "%s: anc_func %x", __func__, tapan->anc_func); |
| 484 | |
| 485 | if (tapan->anc_func == true) { |
| 486 | pr_info("enable anc virtual widgets"); |
| 487 | snd_soc_dapm_enable_pin(dapm, "ANC HPHR"); |
| 488 | snd_soc_dapm_enable_pin(dapm, "ANC HPHL"); |
| 489 | snd_soc_dapm_enable_pin(dapm, "ANC HEADPHONE"); |
| 490 | snd_soc_dapm_enable_pin(dapm, "ANC EAR PA"); |
| 491 | snd_soc_dapm_enable_pin(dapm, "ANC EAR"); |
| 492 | snd_soc_dapm_disable_pin(dapm, "HPHR"); |
| 493 | snd_soc_dapm_disable_pin(dapm, "HPHL"); |
| 494 | snd_soc_dapm_disable_pin(dapm, "HEADPHONE"); |
| 495 | snd_soc_dapm_disable_pin(dapm, "EAR PA"); |
| 496 | snd_soc_dapm_disable_pin(dapm, "EAR"); |
| 497 | } else { |
| 498 | pr_info("disable anc virtual widgets"); |
| 499 | snd_soc_dapm_disable_pin(dapm, "ANC HPHR"); |
| 500 | snd_soc_dapm_disable_pin(dapm, "ANC HPHL"); |
| 501 | snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE"); |
| 502 | snd_soc_dapm_disable_pin(dapm, "ANC EAR PA"); |
| 503 | snd_soc_dapm_disable_pin(dapm, "ANC EAR"); |
| 504 | snd_soc_dapm_enable_pin(dapm, "HPHR"); |
| 505 | snd_soc_dapm_enable_pin(dapm, "HPHL"); |
| 506 | snd_soc_dapm_enable_pin(dapm, "HEADPHONE"); |
| 507 | snd_soc_dapm_enable_pin(dapm, "EAR PA"); |
| 508 | snd_soc_dapm_enable_pin(dapm, "EAR"); |
| 509 | } |
| 510 | snd_soc_dapm_sync(dapm); |
| 511 | mutex_unlock(&dapm->codec->mutex); |
| 512 | return 0; |
| 513 | } |
| 514 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 515 | static int tapan_pa_gain_get(struct snd_kcontrol *kcontrol, |
| 516 | struct snd_ctl_elem_value *ucontrol) |
| 517 | { |
| 518 | u8 ear_pa_gain; |
Venkat Sudhir | 43efc0c | 2013-10-01 16:07:41 -0700 | [diff] [blame] | 519 | int rc = 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 520 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 521 | |
| 522 | ear_pa_gain = snd_soc_read(codec, TAPAN_A_RX_EAR_GAIN); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 523 | ear_pa_gain = ear_pa_gain >> 5; |
| 524 | |
Venkat Sudhir | 43efc0c | 2013-10-01 16:07:41 -0700 | [diff] [blame] | 525 | switch (ear_pa_gain) { |
| 526 | case 0: |
| 527 | case 1: |
| 528 | case 2: |
| 529 | case 3: |
| 530 | case 4: |
| 531 | case 5: |
| 532 | ucontrol->value.integer.value[0] = ear_pa_gain; |
| 533 | break; |
| 534 | case 7: |
| 535 | ucontrol->value.integer.value[0] = (ear_pa_gain - 1); |
| 536 | break; |
| 537 | default: |
| 538 | rc = -EINVAL; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 539 | pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n", |
Venkat Sudhir | 43efc0c | 2013-10-01 16:07:41 -0700 | [diff] [blame] | 540 | __func__, ear_pa_gain); |
| 541 | break; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | dev_dbg(codec->dev, "%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain); |
| 545 | |
Venkat Sudhir | 43efc0c | 2013-10-01 16:07:41 -0700 | [diff] [blame] | 546 | return rc; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | static int tapan_pa_gain_put(struct snd_kcontrol *kcontrol, |
| 550 | struct snd_ctl_elem_value *ucontrol) |
| 551 | { |
| 552 | u8 ear_pa_gain; |
Venkat Sudhir | 43efc0c | 2013-10-01 16:07:41 -0700 | [diff] [blame] | 553 | int rc = 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 554 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 555 | |
| 556 | dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n", |
| 557 | __func__, ucontrol->value.integer.value[0]); |
| 558 | |
| 559 | switch (ucontrol->value.integer.value[0]) { |
| 560 | case 0: |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 561 | case 1: |
Venkat Sudhir | 43efc0c | 2013-10-01 16:07:41 -0700 | [diff] [blame] | 562 | case 2: |
| 563 | case 3: |
| 564 | case 4: |
| 565 | case 5: |
| 566 | ear_pa_gain = ucontrol->value.integer.value[0]; |
| 567 | break; |
| 568 | case 6: |
| 569 | ear_pa_gain = 0x07; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 570 | break; |
| 571 | default: |
Venkat Sudhir | 43efc0c | 2013-10-01 16:07:41 -0700 | [diff] [blame] | 572 | rc = -EINVAL; |
| 573 | break; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 574 | } |
Venkat Sudhir | 43efc0c | 2013-10-01 16:07:41 -0700 | [diff] [blame] | 575 | if (!rc) |
| 576 | snd_soc_update_bits(codec, TAPAN_A_RX_EAR_GAIN, |
| 577 | 0xE0, ear_pa_gain << 5); |
| 578 | return rc; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | static int tapan_get_iir_enable_audio_mixer( |
| 582 | struct snd_kcontrol *kcontrol, |
| 583 | struct snd_ctl_elem_value *ucontrol) |
| 584 | { |
| 585 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 586 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 587 | kcontrol->private_value)->reg; |
| 588 | int band_idx = ((struct soc_multi_mixer_control *) |
| 589 | kcontrol->private_value)->shift; |
| 590 | |
| 591 | ucontrol->value.integer.value[0] = |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 592 | (snd_soc_read(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx)) & |
| 593 | (1 << band_idx)) != 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 594 | |
| 595 | dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__, |
| 596 | iir_idx, band_idx, |
| 597 | (uint32_t)ucontrol->value.integer.value[0]); |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | static int tapan_put_iir_enable_audio_mixer( |
| 602 | struct snd_kcontrol *kcontrol, |
| 603 | struct snd_ctl_elem_value *ucontrol) |
| 604 | { |
| 605 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 606 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 607 | kcontrol->private_value)->reg; |
| 608 | int band_idx = ((struct soc_multi_mixer_control *) |
| 609 | kcontrol->private_value)->shift; |
| 610 | int value = ucontrol->value.integer.value[0]; |
| 611 | |
| 612 | /* Mask first 5 bits, 6-8 are reserved */ |
| 613 | snd_soc_update_bits(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx), |
| 614 | (1 << band_idx), (value << band_idx)); |
| 615 | |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 616 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
| 617 | iir_idx, band_idx, |
| 618 | ((snd_soc_read(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx)) & |
| 619 | (1 << band_idx)) != 0)); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 620 | return 0; |
| 621 | } |
| 622 | static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec, |
| 623 | int iir_idx, int band_idx, |
| 624 | int coeff_idx) |
| 625 | { |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 626 | uint32_t value = 0; |
| 627 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 628 | /* Address does not automatically update if reading */ |
| 629 | snd_soc_write(codec, |
| 630 | (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 631 | ((band_idx * BAND_MAX + coeff_idx) |
| 632 | * sizeof(uint32_t)) & 0x7F); |
| 633 | |
| 634 | value |= snd_soc_read(codec, |
| 635 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)); |
| 636 | |
| 637 | snd_soc_write(codec, |
| 638 | (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
| 639 | ((band_idx * BAND_MAX + coeff_idx) |
| 640 | * sizeof(uint32_t) + 1) & 0x7F); |
| 641 | |
| 642 | value |= (snd_soc_read(codec, |
| 643 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 8); |
| 644 | |
| 645 | snd_soc_write(codec, |
| 646 | (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
| 647 | ((band_idx * BAND_MAX + coeff_idx) |
| 648 | * sizeof(uint32_t) + 2) & 0x7F); |
| 649 | |
| 650 | value |= (snd_soc_read(codec, |
| 651 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 16); |
| 652 | |
| 653 | snd_soc_write(codec, |
| 654 | (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
| 655 | ((band_idx * BAND_MAX + coeff_idx) |
| 656 | * sizeof(uint32_t) + 3) & 0x7F); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 657 | |
| 658 | /* Mask bits top 2 bits since they are reserved */ |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 659 | value |= ((snd_soc_read(codec, |
| 660 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) & 0x3F) << 24); |
| 661 | |
| 662 | return value; |
| 663 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | static int tapan_get_iir_band_audio_mixer( |
| 667 | struct snd_kcontrol *kcontrol, |
| 668 | struct snd_ctl_elem_value *ucontrol) |
| 669 | { |
| 670 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 671 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 672 | kcontrol->private_value)->reg; |
| 673 | int band_idx = ((struct soc_multi_mixer_control *) |
| 674 | kcontrol->private_value)->shift; |
| 675 | |
| 676 | ucontrol->value.integer.value[0] = |
| 677 | get_iir_band_coeff(codec, iir_idx, band_idx, 0); |
| 678 | ucontrol->value.integer.value[1] = |
| 679 | get_iir_band_coeff(codec, iir_idx, band_idx, 1); |
| 680 | ucontrol->value.integer.value[2] = |
| 681 | get_iir_band_coeff(codec, iir_idx, band_idx, 2); |
| 682 | ucontrol->value.integer.value[3] = |
| 683 | get_iir_band_coeff(codec, iir_idx, band_idx, 3); |
| 684 | ucontrol->value.integer.value[4] = |
| 685 | get_iir_band_coeff(codec, iir_idx, band_idx, 4); |
| 686 | |
| 687 | dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n" |
| 688 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 689 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 690 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 691 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 692 | __func__, iir_idx, band_idx, |
| 693 | (uint32_t)ucontrol->value.integer.value[0], |
| 694 | __func__, iir_idx, band_idx, |
| 695 | (uint32_t)ucontrol->value.integer.value[1], |
| 696 | __func__, iir_idx, band_idx, |
| 697 | (uint32_t)ucontrol->value.integer.value[2], |
| 698 | __func__, iir_idx, band_idx, |
| 699 | (uint32_t)ucontrol->value.integer.value[3], |
| 700 | __func__, iir_idx, band_idx, |
| 701 | (uint32_t)ucontrol->value.integer.value[4]); |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | static void set_iir_band_coeff(struct snd_soc_codec *codec, |
| 706 | int iir_idx, int band_idx, |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 707 | uint32_t value) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 708 | { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 709 | snd_soc_write(codec, |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 710 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
| 711 | (value & 0xFF)); |
| 712 | |
| 713 | snd_soc_write(codec, |
| 714 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
| 715 | (value >> 8) & 0xFF); |
| 716 | |
| 717 | snd_soc_write(codec, |
| 718 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
| 719 | (value >> 16) & 0xFF); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 720 | |
| 721 | /* Mask top 2 bits, 7-8 are reserved */ |
| 722 | snd_soc_write(codec, |
| 723 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
| 724 | (value >> 24) & 0x3F); |
| 725 | |
| 726 | } |
| 727 | |
| 728 | static int tapan_put_iir_band_audio_mixer( |
| 729 | struct snd_kcontrol *kcontrol, |
| 730 | struct snd_ctl_elem_value *ucontrol) |
| 731 | { |
| 732 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 733 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 734 | kcontrol->private_value)->reg; |
| 735 | int band_idx = ((struct soc_multi_mixer_control *) |
| 736 | kcontrol->private_value)->shift; |
| 737 | |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 738 | /* Mask top bit it is reserved */ |
| 739 | /* Updates addr automatically for each B2 write */ |
| 740 | snd_soc_write(codec, |
| 741 | (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
| 742 | (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F); |
| 743 | |
| 744 | set_iir_band_coeff(codec, iir_idx, band_idx, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 745 | ucontrol->value.integer.value[0]); |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 746 | set_iir_band_coeff(codec, iir_idx, band_idx, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 747 | ucontrol->value.integer.value[1]); |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 748 | set_iir_band_coeff(codec, iir_idx, band_idx, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 749 | ucontrol->value.integer.value[2]); |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 750 | set_iir_band_coeff(codec, iir_idx, band_idx, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 751 | ucontrol->value.integer.value[3]); |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 752 | set_iir_band_coeff(codec, iir_idx, band_idx, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 753 | ucontrol->value.integer.value[4]); |
| 754 | |
| 755 | dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n" |
| 756 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 757 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 758 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 759 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 760 | __func__, iir_idx, band_idx, |
| 761 | get_iir_band_coeff(codec, iir_idx, band_idx, 0), |
| 762 | __func__, iir_idx, band_idx, |
| 763 | get_iir_band_coeff(codec, iir_idx, band_idx, 1), |
| 764 | __func__, iir_idx, band_idx, |
| 765 | get_iir_band_coeff(codec, iir_idx, band_idx, 2), |
| 766 | __func__, iir_idx, band_idx, |
| 767 | get_iir_band_coeff(codec, iir_idx, band_idx, 3), |
| 768 | __func__, iir_idx, band_idx, |
| 769 | get_iir_band_coeff(codec, iir_idx, band_idx, 4)); |
| 770 | return 0; |
| 771 | } |
| 772 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 773 | static int tapan_get_compander(struct snd_kcontrol *kcontrol, |
| 774 | struct snd_ctl_elem_value *ucontrol) |
| 775 | { |
| 776 | |
| 777 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 778 | int comp = ((struct soc_multi_mixer_control *) |
| 779 | kcontrol->private_value)->shift; |
| 780 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 781 | |
| 782 | ucontrol->value.integer.value[0] = tapan->comp_enabled[comp]; |
| 783 | return 0; |
| 784 | } |
| 785 | |
| 786 | static int tapan_set_compander(struct snd_kcontrol *kcontrol, |
| 787 | struct snd_ctl_elem_value *ucontrol) |
| 788 | { |
| 789 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 790 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 791 | int comp = ((struct soc_multi_mixer_control *) |
| 792 | kcontrol->private_value)->shift; |
| 793 | int value = ucontrol->value.integer.value[0]; |
| 794 | |
| 795 | dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n", |
| 796 | __func__, comp, tapan->comp_enabled[comp], value); |
| 797 | tapan->comp_enabled[comp] = value; |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 798 | |
| 799 | if (comp == COMPANDER_1 && |
| 800 | tapan->comp_enabled[comp] == 1) { |
| 801 | /* Wavegen to 5 msec */ |
| 802 | snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_CTL, 0xDA); |
| 803 | snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_TIME, 0x15); |
| 804 | snd_soc_write(codec, TAPAN_A_RX_HPH_BIAS_WG_OCP, 0x2A); |
| 805 | |
| 806 | /* Enable Chopper */ |
| 807 | snd_soc_update_bits(codec, |
| 808 | TAPAN_A_RX_HPH_CHOP_CTL, 0x80, 0x80); |
| 809 | |
| 810 | snd_soc_write(codec, TAPAN_A_NCP_DTEST, 0x20); |
| 811 | pr_debug("%s: Enabled Chopper and set wavegen to 5 msec\n", |
| 812 | __func__); |
| 813 | } else if (comp == COMPANDER_1 && |
| 814 | tapan->comp_enabled[comp] == 0) { |
| 815 | /* Wavegen to 20 msec */ |
| 816 | snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_CTL, 0xDB); |
| 817 | snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_TIME, 0x58); |
| 818 | snd_soc_write(codec, TAPAN_A_RX_HPH_BIAS_WG_OCP, 0x1A); |
| 819 | |
| 820 | /* Disable CHOPPER block */ |
| 821 | snd_soc_update_bits(codec, |
| 822 | TAPAN_A_RX_HPH_CHOP_CTL, 0x80, 0x00); |
| 823 | |
| 824 | snd_soc_write(codec, TAPAN_A_NCP_DTEST, 0x10); |
| 825 | pr_debug("%s: Disabled Chopper and set wavegen to 20 msec\n", |
| 826 | __func__); |
| 827 | } |
| 828 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 829 | return 0; |
| 830 | } |
| 831 | |
| 832 | static int tapan_config_gain_compander(struct snd_soc_codec *codec, |
| 833 | int comp, bool enable) |
| 834 | { |
| 835 | int ret = 0; |
| 836 | |
| 837 | switch (comp) { |
| 838 | case COMPANDER_0: |
| 839 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_GAIN, |
| 840 | 1 << 2, !enable << 2); |
| 841 | break; |
| 842 | case COMPANDER_1: |
| 843 | snd_soc_update_bits(codec, TAPAN_A_RX_HPH_L_GAIN, |
| 844 | 1 << 5, !enable << 5); |
| 845 | snd_soc_update_bits(codec, TAPAN_A_RX_HPH_R_GAIN, |
| 846 | 1 << 5, !enable << 5); |
| 847 | break; |
| 848 | case COMPANDER_2: |
| 849 | snd_soc_update_bits(codec, TAPAN_A_RX_LINE_1_GAIN, |
| 850 | 1 << 5, !enable << 5); |
| 851 | snd_soc_update_bits(codec, TAPAN_A_RX_LINE_2_GAIN, |
| 852 | 1 << 5, !enable << 5); |
| 853 | break; |
| 854 | default: |
| 855 | WARN_ON(1); |
| 856 | ret = -EINVAL; |
| 857 | } |
| 858 | |
| 859 | return ret; |
| 860 | } |
| 861 | |
| 862 | static void tapan_discharge_comp(struct snd_soc_codec *codec, int comp) |
| 863 | { |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 864 | /* Level meter DIV Factor to 5*/ |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 865 | snd_soc_update_bits(codec, TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8), 0xF0, |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 866 | 0x05 << 4); |
| 867 | /* RMS meter Sampling to 0x01 */ |
| 868 | snd_soc_write(codec, TAPAN_A_CDC_COMP0_B3_CTL + (comp * 8), 0x01); |
| 869 | |
| 870 | /* Worst case timeout for compander CnP sleep timeout */ |
| 871 | usleep_range(3000, 3000); |
| 872 | } |
| 873 | |
| 874 | static enum wcd9xxx_buck_volt tapan_codec_get_buck_mv( |
| 875 | struct snd_soc_codec *codec) |
| 876 | { |
| 877 | int buck_volt = WCD9XXX_CDC_BUCK_UNSUPPORTED; |
| 878 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 879 | struct wcd9xxx_pdata *pdata = tapan->resmgr.pdata; |
| 880 | int i; |
Bhalchandra Gajare | f49df62 | 2013-08-30 12:42:38 -0700 | [diff] [blame] | 881 | bool found_regulator = false; |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 882 | |
| 883 | for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) { |
Bhalchandra Gajare | 5b4199c | 2013-07-03 14:35:43 -0700 | [diff] [blame] | 884 | if (pdata->regulator[i].name == NULL) |
| 885 | continue; |
| 886 | |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 887 | if (!strncmp(pdata->regulator[i].name, |
Bhalchandra Gajare | f49df62 | 2013-08-30 12:42:38 -0700 | [diff] [blame] | 888 | WCD9XXX_SUPPLY_BUCK_NAME, |
| 889 | sizeof(WCD9XXX_SUPPLY_BUCK_NAME))) { |
| 890 | found_regulator = true; |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 891 | if ((pdata->regulator[i].min_uV == |
Bhalchandra Gajare | f49df62 | 2013-08-30 12:42:38 -0700 | [diff] [blame] | 892 | WCD9XXX_CDC_BUCK_MV_1P8) || |
| 893 | (pdata->regulator[i].min_uV == |
| 894 | WCD9XXX_CDC_BUCK_MV_2P15)) |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 895 | buck_volt = pdata->regulator[i].min_uV; |
| 896 | break; |
| 897 | } |
| 898 | } |
Bhalchandra Gajare | f49df62 | 2013-08-30 12:42:38 -0700 | [diff] [blame] | 899 | |
| 900 | if (!found_regulator) |
| 901 | dev_err(codec->dev, |
| 902 | "%s: Failed to find regulator for %s\n", |
| 903 | __func__, WCD9XXX_SUPPLY_BUCK_NAME); |
| 904 | else |
| 905 | dev_dbg(codec->dev, |
Bhalchandra Gajare | 5b4199c | 2013-07-03 14:35:43 -0700 | [diff] [blame] | 906 | "%s: S4 voltage requested is %d\n", |
| 907 | __func__, buck_volt); |
Bhalchandra Gajare | f49df62 | 2013-08-30 12:42:38 -0700 | [diff] [blame] | 908 | |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 909 | return buck_volt; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | static int tapan_config_compander(struct snd_soc_dapm_widget *w, |
| 913 | struct snd_kcontrol *kcontrol, int event) |
| 914 | { |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 915 | int mask, enable_mask; |
| 916 | u8 rdac5_mux; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 917 | struct snd_soc_codec *codec = w->codec; |
| 918 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 919 | const int comp = w->shift; |
| 920 | const u32 rate = tapan->comp_fs[comp]; |
| 921 | const struct comp_sample_dependent_params *comp_params = |
| 922 | &comp_samp_params[rate]; |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 923 | enum wcd9xxx_buck_volt buck_mv; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 924 | |
| 925 | dev_dbg(codec->dev, "%s: %s event %d compander %d, enabled %d", |
| 926 | __func__, w->name, event, comp, tapan->comp_enabled[comp]); |
| 927 | |
| 928 | if (!tapan->comp_enabled[comp]) |
| 929 | return 0; |
| 930 | |
| 931 | /* Compander 0 has single channel */ |
| 932 | mask = (comp == COMPANDER_0 ? 0x01 : 0x03); |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 933 | buck_mv = tapan_codec_get_buck_mv(codec); |
| 934 | |
| 935 | rdac5_mux = snd_soc_read(codec, TAPAN_A_CDC_CONN_MISC); |
| 936 | rdac5_mux = (rdac5_mux & 0x04) >> 2; |
| 937 | |
| 938 | if (comp == COMPANDER_0) { /* SPK compander */ |
| 939 | enable_mask = 0x02; |
| 940 | } else if (comp == COMPANDER_1) { /* HPH compander */ |
| 941 | enable_mask = 0x03; |
| 942 | } else if (comp == COMPANDER_2) { /* LO compander */ |
| 943 | |
| 944 | if (rdac5_mux == 0) { /* DEM4 */ |
| 945 | |
| 946 | /* for LO Stereo SE, enable Compander 2 left |
| 947 | * channel on RX3 interpolator Path and Compander 2 |
| 948 | * rigt channel on RX4 interpolator Path. |
| 949 | */ |
| 950 | enable_mask = 0x03; |
| 951 | } else if (rdac5_mux == 1) { /* DEM3_INV */ |
| 952 | |
| 953 | /* for LO mono differential only enable Compander 2 |
| 954 | * left channel on RX3 interpolator Path. |
| 955 | */ |
| 956 | enable_mask = 0x02; |
| 957 | } else { |
| 958 | dev_err(codec->dev, "%s: invalid rdac5_mux val %d", |
| 959 | __func__, rdac5_mux); |
| 960 | return -EINVAL; |
| 961 | } |
| 962 | } else { |
| 963 | dev_err(codec->dev, "%s: invalid compander %d", __func__, comp); |
| 964 | return -EINVAL; |
| 965 | } |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 966 | |
| 967 | switch (event) { |
| 968 | case SND_SOC_DAPM_PRE_PMU: |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 969 | /* Set compander Sample rate */ |
| 970 | snd_soc_update_bits(codec, |
| 971 | TAPAN_A_CDC_COMP0_FS_CFG + (comp * 8), |
| 972 | 0x07, rate); |
| 973 | /* Set the static gain offset for HPH Path */ |
| 974 | if (comp == COMPANDER_1) { |
| 975 | if (buck_mv == WCD9XXX_CDC_BUCK_MV_2P15) |
| 976 | snd_soc_update_bits(codec, |
| 977 | TAPAN_A_CDC_COMP0_B4_CTL + (comp * 8), |
| 978 | 0x80, 0x00); |
| 979 | else |
| 980 | snd_soc_update_bits(codec, |
| 981 | TAPAN_A_CDC_COMP0_B4_CTL + (comp * 8), |
| 982 | 0x80, 0x80); |
| 983 | } |
| 984 | /* Enable RX interpolation path compander clocks */ |
| 985 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_B2_CTL, |
| 986 | 0x01 << comp_shift[comp], |
| 987 | 0x01 << comp_shift[comp]); |
| 988 | |
| 989 | /* Toggle compander reset bits */ |
| 990 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL, |
| 991 | 0x01 << comp_shift[comp], |
| 992 | 0x01 << comp_shift[comp]); |
| 993 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL, |
| 994 | 0x01 << comp_shift[comp], 0); |
| 995 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 996 | /* Set gain source to compander */ |
| 997 | tapan_config_gain_compander(codec, comp, true); |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 998 | |
| 999 | /* Compander enable */ |
| 1000 | snd_soc_update_bits(codec, TAPAN_A_CDC_COMP0_B1_CTL + |
| 1001 | (comp * 8), enable_mask, enable_mask); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1002 | |
| 1003 | tapan_discharge_comp(codec, comp); |
| 1004 | |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 1005 | /* Set sample rate dependent paramater */ |
| 1006 | snd_soc_write(codec, TAPAN_A_CDC_COMP0_B3_CTL + (comp * 8), |
| 1007 | comp_params->rms_meter_resamp_fact); |
| 1008 | snd_soc_update_bits(codec, |
| 1009 | TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8), |
| 1010 | 0xF0, comp_params->rms_meter_div_fact << 4); |
| 1011 | snd_soc_update_bits(codec, |
| 1012 | TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8), |
| 1013 | 0x0F, comp_params->peak_det_timeout); |
| 1014 | break; |
| 1015 | case SND_SOC_DAPM_PRE_PMD: |
| 1016 | /* Disable compander */ |
| 1017 | snd_soc_update_bits(codec, |
| 1018 | TAPAN_A_CDC_COMP0_B1_CTL + (comp * 8), |
| 1019 | enable_mask, 0x00); |
| 1020 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1021 | /* Toggle compander reset bits */ |
| 1022 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL, |
| 1023 | mask << comp_shift[comp], |
| 1024 | mask << comp_shift[comp]); |
| 1025 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL, |
| 1026 | mask << comp_shift[comp], 0); |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 1027 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1028 | /* Turn off the clock for compander in pair */ |
| 1029 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_B2_CTL, |
| 1030 | mask << comp_shift[comp], 0); |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 1031 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1032 | /* Set gain source to register */ |
| 1033 | tapan_config_gain_compander(codec, comp, false); |
| 1034 | break; |
| 1035 | } |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
Venkat Sudhir | 43efc0c | 2013-10-01 16:07:41 -0700 | [diff] [blame] | 1039 | static const char * const tapan_ear_pa_gain_text[] = {"POS_6_DB", "POS_4P5_DB", |
| 1040 | "POS_3_DB", "POS_1P5_DB", |
| 1041 | "POS_0_DB", "NEG_2P5_DB", |
| 1042 | "NEG_12_DB"}; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1043 | static const struct soc_enum tapan_ear_pa_gain_enum[] = { |
Venkat Sudhir | 43efc0c | 2013-10-01 16:07:41 -0700 | [diff] [blame] | 1044 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tapan_ear_pa_gain_text), |
| 1045 | tapan_ear_pa_gain_text), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1046 | }; |
| 1047 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1048 | static const char *const tapan_anc_func_text[] = {"OFF", "ON"}; |
| 1049 | static const struct soc_enum tapan_anc_func_enum = |
| 1050 | SOC_ENUM_SINGLE_EXT(2, tapan_anc_func_text); |
| 1051 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1052 | /*cut of frequency for high pass filter*/ |
| 1053 | static const char * const cf_text[] = { |
| 1054 | "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz" |
| 1055 | }; |
| 1056 | |
| 1057 | static const struct soc_enum cf_dec1_enum = |
| 1058 | SOC_ENUM_SINGLE(TAPAN_A_CDC_TX1_MUX_CTL, 4, 3, cf_text); |
| 1059 | |
| 1060 | static const struct soc_enum cf_dec2_enum = |
| 1061 | SOC_ENUM_SINGLE(TAPAN_A_CDC_TX2_MUX_CTL, 4, 3, cf_text); |
| 1062 | |
| 1063 | static const struct soc_enum cf_dec3_enum = |
| 1064 | SOC_ENUM_SINGLE(TAPAN_A_CDC_TX3_MUX_CTL, 4, 3, cf_text); |
| 1065 | |
| 1066 | static const struct soc_enum cf_dec4_enum = |
| 1067 | SOC_ENUM_SINGLE(TAPAN_A_CDC_TX4_MUX_CTL, 4, 3, cf_text); |
| 1068 | |
| 1069 | static const struct soc_enum cf_rxmix1_enum = |
Joonwoo Park | 2000a98 | 2013-03-01 14:50:31 -0800 | [diff] [blame] | 1070 | SOC_ENUM_SINGLE(TAPAN_A_CDC_RX1_B4_CTL, 0, 3, cf_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1071 | |
| 1072 | static const struct soc_enum cf_rxmix2_enum = |
Joonwoo Park | 2000a98 | 2013-03-01 14:50:31 -0800 | [diff] [blame] | 1073 | SOC_ENUM_SINGLE(TAPAN_A_CDC_RX2_B4_CTL, 0, 3, cf_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1074 | |
| 1075 | static const struct soc_enum cf_rxmix3_enum = |
Joonwoo Park | 2000a98 | 2013-03-01 14:50:31 -0800 | [diff] [blame] | 1076 | SOC_ENUM_SINGLE(TAPAN_A_CDC_RX3_B4_CTL, 0, 3, cf_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1077 | |
| 1078 | static const struct soc_enum cf_rxmix4_enum = |
Joonwoo Park | 2000a98 | 2013-03-01 14:50:31 -0800 | [diff] [blame] | 1079 | SOC_ENUM_SINGLE(TAPAN_A_CDC_RX4_B4_CTL, 0, 3, cf_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1080 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1081 | static const char * const class_h_dsm_text[] = { |
| 1082 | "ZERO", "RX_HPHL", "RX_SPKR" |
| 1083 | }; |
| 1084 | |
| 1085 | static const struct soc_enum class_h_dsm_enum = |
| 1086 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_CLSH_CTL, 2, 3, class_h_dsm_text); |
| 1087 | |
| 1088 | static const struct snd_kcontrol_new class_h_dsm_mux = |
| 1089 | SOC_DAPM_ENUM("CLASS_H_DSM MUX Mux", class_h_dsm_enum); |
| 1090 | |
Phani Kumar Uppalapati | 5724aa2 | 2013-10-02 12:46:15 -0700 | [diff] [blame] | 1091 | static int tapan_hph_impedance_get(struct snd_kcontrol *kcontrol, |
| 1092 | struct snd_ctl_elem_value *ucontrol) |
| 1093 | { |
| 1094 | uint32_t zl, zr; |
| 1095 | bool hphr; |
| 1096 | struct soc_multi_mixer_control *mc; |
| 1097 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1098 | struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec); |
| 1099 | |
| 1100 | mc = (struct soc_multi_mixer_control *)(kcontrol->private_value); |
| 1101 | |
| 1102 | hphr = mc->shift; |
| 1103 | wcd9xxx_mbhc_get_impedance(&priv->mbhc, &zl, &zr); |
| 1104 | pr_debug("%s: zl %u, zr %u\n", __func__, zl, zr); |
| 1105 | ucontrol->value.integer.value[0] = hphr ? zr : zl; |
| 1106 | |
| 1107 | return 0; |
| 1108 | } |
| 1109 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 1110 | static const struct snd_kcontrol_new tapan_common_snd_controls[] = { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1111 | |
| 1112 | SOC_ENUM_EXT("EAR PA Gain", tapan_ear_pa_gain_enum[0], |
| 1113 | tapan_pa_gain_get, tapan_pa_gain_put), |
| 1114 | |
Damir Didjusto | fc6016e | 2014-02-10 19:00:11 -0800 | [diff] [blame] | 1115 | SOC_SINGLE_TLV("HPHL Volume", TAPAN_A_RX_HPH_L_GAIN, 0, 20, 1, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1116 | line_gain), |
Damir Didjusto | fc6016e | 2014-02-10 19:00:11 -0800 | [diff] [blame] | 1117 | SOC_SINGLE_TLV("HPHR Volume", TAPAN_A_RX_HPH_R_GAIN, 0, 20, 1, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1118 | line_gain), |
| 1119 | |
Damir Didjusto | fc6016e | 2014-02-10 19:00:11 -0800 | [diff] [blame] | 1120 | SOC_SINGLE_TLV("LINEOUT1 Volume", TAPAN_A_RX_LINE_1_GAIN, 0, 20, 1, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1121 | line_gain), |
Damir Didjusto | fc6016e | 2014-02-10 19:00:11 -0800 | [diff] [blame] | 1122 | SOC_SINGLE_TLV("LINEOUT2 Volume", TAPAN_A_RX_LINE_2_GAIN, 0, 20, 1, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1123 | line_gain), |
| 1124 | |
Mohammad Johny Shaik | abb80c6 | 2013-12-27 11:02:02 +0530 | [diff] [blame] | 1125 | SOC_SINGLE_TLV("SPK DRV Volume", TAPAN_A_SPKR_DRV_GAIN, 3, 8, 1, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1126 | line_gain), |
| 1127 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1128 | SOC_SINGLE_TLV("ADC1 Volume", TAPAN_A_TX_1_EN, 2, 19, 0, analog_gain), |
| 1129 | SOC_SINGLE_TLV("ADC2 Volume", TAPAN_A_TX_2_EN, 2, 19, 0, analog_gain), |
| 1130 | SOC_SINGLE_TLV("ADC3 Volume", TAPAN_A_TX_3_EN, 2, 19, 0, analog_gain), |
| 1131 | SOC_SINGLE_TLV("ADC4 Volume", TAPAN_A_TX_4_EN, 2, 19, 0, analog_gain), |
Jay Chokshi | 83b4f613 | 2013-02-14 16:20:56 -0800 | [diff] [blame] | 1132 | SOC_SINGLE_S8_TLV("RX1 Digital Volume", TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 1133 | -84, 40, digital_gain), |
| 1134 | SOC_SINGLE_S8_TLV("RX2 Digital Volume", TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 1135 | -84, 40, digital_gain), |
| 1136 | SOC_SINGLE_S8_TLV("RX3 Digital Volume", TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 1137 | -84, 40, digital_gain), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1138 | |
Jay Chokshi | 83b4f613 | 2013-02-14 16:20:56 -0800 | [diff] [blame] | 1139 | SOC_SINGLE_S8_TLV("DEC1 Volume", TAPAN_A_CDC_TX1_VOL_CTL_GAIN, -84, 40, |
| 1140 | digital_gain), |
| 1141 | SOC_SINGLE_S8_TLV("DEC2 Volume", TAPAN_A_CDC_TX2_VOL_CTL_GAIN, -84, 40, |
| 1142 | digital_gain), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1143 | |
Jay Chokshi | 83b4f613 | 2013-02-14 16:20:56 -0800 | [diff] [blame] | 1144 | SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TAPAN_A_CDC_IIR1_GAIN_B1_CTL, -84, |
| 1145 | 40, digital_gain), |
| 1146 | SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TAPAN_A_CDC_IIR1_GAIN_B2_CTL, -84, |
| 1147 | 40, digital_gain), |
| 1148 | SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TAPAN_A_CDC_IIR1_GAIN_B3_CTL, -84, |
| 1149 | 40, digital_gain), |
| 1150 | SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TAPAN_A_CDC_IIR1_GAIN_B4_CTL, -84, |
| 1151 | 40, digital_gain), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1152 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1153 | SOC_ENUM("TX1 HPF cut off", cf_dec1_enum), |
| 1154 | SOC_ENUM("TX2 HPF cut off", cf_dec2_enum), |
| 1155 | SOC_ENUM("TX3 HPF cut off", cf_dec3_enum), |
| 1156 | SOC_ENUM("TX4 HPF cut off", cf_dec4_enum), |
| 1157 | |
| 1158 | SOC_SINGLE("TX1 HPF Switch", TAPAN_A_CDC_TX1_MUX_CTL, 3, 1, 0), |
| 1159 | SOC_SINGLE("TX2 HPF Switch", TAPAN_A_CDC_TX2_MUX_CTL, 3, 1, 0), |
| 1160 | SOC_SINGLE("TX3 HPF Switch", TAPAN_A_CDC_TX3_MUX_CTL, 3, 1, 0), |
| 1161 | SOC_SINGLE("TX4 HPF Switch", TAPAN_A_CDC_TX4_MUX_CTL, 3, 1, 0), |
| 1162 | |
| 1163 | SOC_SINGLE("RX1 HPF Switch", TAPAN_A_CDC_RX1_B5_CTL, 2, 1, 0), |
| 1164 | SOC_SINGLE("RX2 HPF Switch", TAPAN_A_CDC_RX2_B5_CTL, 2, 1, 0), |
| 1165 | SOC_SINGLE("RX3 HPF Switch", TAPAN_A_CDC_RX3_B5_CTL, 2, 1, 0), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1166 | |
| 1167 | SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum), |
| 1168 | SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum), |
| 1169 | SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1170 | |
| 1171 | SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0, |
| 1172 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 1173 | SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0, |
| 1174 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 1175 | SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0, |
| 1176 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 1177 | SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0, |
| 1178 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 1179 | SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0, |
| 1180 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 1181 | SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0, |
| 1182 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 1183 | SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0, |
| 1184 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 1185 | SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0, |
| 1186 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 1187 | SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0, |
| 1188 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 1189 | SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0, |
| 1190 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 1191 | |
| 1192 | SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5, |
| 1193 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 1194 | SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5, |
| 1195 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 1196 | SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5, |
| 1197 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 1198 | SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5, |
| 1199 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 1200 | SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5, |
| 1201 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 1202 | SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5, |
| 1203 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 1204 | SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5, |
| 1205 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 1206 | SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5, |
| 1207 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 1208 | SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5, |
| 1209 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 1210 | SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5, |
| 1211 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
Phani Kumar Uppalapati | 5724aa2 | 2013-10-02 12:46:15 -0700 | [diff] [blame] | 1212 | |
| 1213 | SOC_SINGLE_EXT("HPHL Impedance", 0, 0, UINT_MAX, 0, |
| 1214 | tapan_hph_impedance_get, NULL), |
| 1215 | SOC_SINGLE_EXT("HPHR Impedance", 0, 1, UINT_MAX, 0, |
| 1216 | tapan_hph_impedance_get, NULL), |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 1217 | }; |
| 1218 | |
| 1219 | static const struct snd_kcontrol_new tapan_9306_snd_controls[] = { |
| 1220 | SOC_SINGLE_TLV("ADC5 Volume", TAPAN_A_TX_5_EN, 2, 19, 0, analog_gain), |
| 1221 | |
| 1222 | SOC_SINGLE_S8_TLV("RX4 Digital Volume", TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 1223 | -84, 40, digital_gain), |
| 1224 | SOC_SINGLE_S8_TLV("DEC3 Volume", TAPAN_A_CDC_TX3_VOL_CTL_GAIN, -84, 40, |
| 1225 | digital_gain), |
| 1226 | SOC_SINGLE_S8_TLV("DEC4 Volume", TAPAN_A_CDC_TX4_VOL_CTL_GAIN, -84, 40, |
| 1227 | digital_gain), |
| 1228 | SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 100, 0, tapan_get_anc_slot, |
| 1229 | tapan_put_anc_slot), |
| 1230 | SOC_ENUM_EXT("ANC Function", tapan_anc_func_enum, tapan_get_anc_func, |
| 1231 | tapan_put_anc_func), |
| 1232 | SOC_SINGLE("RX4 HPF Switch", TAPAN_A_CDC_RX4_B5_CTL, 2, 1, 0), |
| 1233 | SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1234 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1235 | SOC_SINGLE_EXT("COMP0 Switch", SND_SOC_NOPM, COMPANDER_0, 1, 0, |
| 1236 | tapan_get_compander, tapan_set_compander), |
| 1237 | SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, COMPANDER_1, 1, 0, |
| 1238 | tapan_get_compander, tapan_set_compander), |
| 1239 | SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, COMPANDER_2, 1, 0, |
| 1240 | tapan_get_compander, tapan_set_compander), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1241 | }; |
| 1242 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1243 | static const char * const rx_1_2_mix1_text[] = { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1244 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4", |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1245 | "RX5", "AUXRX", "AUXTX1" |
| 1246 | }; |
| 1247 | |
| 1248 | static const char * const rx_3_4_mix1_text[] = { |
| 1249 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4", |
| 1250 | "RX5", "AUXRX", "AUXTX1", "AUXTX2" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1251 | }; |
| 1252 | |
| 1253 | static const char * const rx_mix2_text[] = { |
| 1254 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2" |
| 1255 | }; |
| 1256 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 1257 | static const char * const rx_rdac3_text[] = { |
| 1258 | "DEM1", "DEM2" |
| 1259 | }; |
| 1260 | |
| 1261 | static const char * const rx_rdac4_text[] = { |
| 1262 | "DEM3", "DEM2" |
| 1263 | }; |
| 1264 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1265 | static const char * const rx_rdac5_text[] = { |
| 1266 | "DEM4", "DEM3_INV" |
| 1267 | }; |
| 1268 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1269 | static const char * const sb_tx_1_2_mux_text[] = { |
| 1270 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", |
| 1271 | "RSVD", "RSVD", "RSVD", |
| 1272 | "DEC1", "DEC2", "DEC3", "DEC4" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1273 | }; |
| 1274 | |
| 1275 | static const char * const sb_tx3_mux_text[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1276 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", |
| 1277 | "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", |
| 1278 | "DEC3" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1279 | }; |
| 1280 | |
| 1281 | static const char * const sb_tx4_mux_text[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1282 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", |
| 1283 | "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", |
| 1284 | "DEC4" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1285 | }; |
| 1286 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1287 | static const char * const sb_tx5_mux_text[] = { |
| 1288 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", |
| 1289 | "RSVD", "RSVD", "RSVD", |
| 1290 | "DEC1" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1291 | }; |
| 1292 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1293 | static const char * const dec_1_2_mux_text[] = { |
| 1294 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADCMB", |
| 1295 | "DMIC1", "DMIC2", "DMIC3", "DMIC4" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1296 | }; |
| 1297 | |
| 1298 | static const char * const dec3_mux_text[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1299 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADCMB", |
| 1300 | "DMIC1", "DMIC2", "DMIC3", "DMIC4", |
| 1301 | "ANCFBTUNE1" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1302 | }; |
| 1303 | |
| 1304 | static const char * const dec4_mux_text[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1305 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADCMB", |
| 1306 | "DMIC1", "DMIC2", "DMIC3", "DMIC4", |
| 1307 | "ANCFBTUNE2" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1308 | }; |
| 1309 | |
| 1310 | static const char * const anc_mux_text[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1311 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", |
| 1312 | "RSVD", "RSVD", "RSVD", |
| 1313 | "DMIC1", "DMIC2", "DMIC3", "DMIC4", |
| 1314 | "RSVD", "RSVD" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1315 | }; |
| 1316 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1317 | static const char * const anc1_fb_mux_text[] = { |
| 1318 | "ZERO", "EAR_HPH_L", "EAR_LINE_1", |
| 1319 | }; |
| 1320 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1321 | static const char * const iir1_inp1_text[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1322 | "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", |
| 1323 | "RX1", "RX2", "RX3", "RX4", "RX5" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1324 | }; |
| 1325 | |
| 1326 | static const struct soc_enum rx_mix1_inp1_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1327 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_1_2_mix1_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1328 | |
| 1329 | static const struct soc_enum rx_mix1_inp2_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1330 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_1_2_mix1_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1331 | |
| 1332 | static const struct soc_enum rx_mix1_inp3_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1333 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B2_CTL, 0, 12, rx_1_2_mix1_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1334 | |
| 1335 | static const struct soc_enum rx2_mix1_inp1_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1336 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_1_2_mix1_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1337 | |
| 1338 | static const struct soc_enum rx2_mix1_inp2_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1339 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_1_2_mix1_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1340 | |
| 1341 | static const struct soc_enum rx3_mix1_inp1_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1342 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX3_B1_CTL, 0, 13, rx_3_4_mix1_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1343 | |
| 1344 | static const struct soc_enum rx3_mix1_inp2_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1345 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX3_B1_CTL, 4, 13, rx_3_4_mix1_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1346 | |
Asish Bhattacharya | ba6a49d | 2014-03-19 10:03:45 +0530 | [diff] [blame] | 1347 | static const struct soc_enum rx3_mix1_inp3_chain_enum = |
| 1348 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX3_B2_CTL, 0, 13, rx_3_4_mix1_text); |
| 1349 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1350 | static const struct soc_enum rx4_mix1_inp1_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1351 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B1_CTL, 0, 13, rx_3_4_mix1_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1352 | |
| 1353 | static const struct soc_enum rx4_mix1_inp2_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1354 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B1_CTL, 4, 13, rx_3_4_mix1_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1355 | |
Santosh Mardi | 330ad2a | 2013-11-21 18:12:14 +0530 | [diff] [blame] | 1356 | static const struct soc_enum rx4_mix1_inp3_chain_enum = |
| 1357 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B2_CTL, 0, 13, rx_3_4_mix1_text); |
| 1358 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1359 | static const struct soc_enum rx1_mix2_inp1_chain_enum = |
| 1360 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text); |
| 1361 | |
| 1362 | static const struct soc_enum rx1_mix2_inp2_chain_enum = |
| 1363 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text); |
| 1364 | |
| 1365 | static const struct soc_enum rx2_mix2_inp1_chain_enum = |
| 1366 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text); |
| 1367 | |
| 1368 | static const struct soc_enum rx2_mix2_inp2_chain_enum = |
| 1369 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text); |
| 1370 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1371 | static const struct soc_enum rx4_mix2_inp1_chain_enum = |
| 1372 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B3_CTL, 0, 5, rx_mix2_text); |
| 1373 | |
| 1374 | static const struct soc_enum rx4_mix2_inp2_chain_enum = |
| 1375 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B3_CTL, 3, 5, rx_mix2_text); |
| 1376 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 1377 | static const struct soc_enum rx_rdac3_enum = |
| 1378 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B2_CTL, 4, 2, rx_rdac3_text); |
| 1379 | |
| 1380 | static const struct soc_enum rx_rdac4_enum = |
| 1381 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_MISC, 1, 2, rx_rdac4_text); |
| 1382 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1383 | static const struct soc_enum rx_rdac5_enum = |
| 1384 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_MISC, 2, 2, rx_rdac5_text); |
| 1385 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1386 | static const struct soc_enum sb_tx1_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1387 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B1_CTL, 0, 12, |
| 1388 | sb_tx_1_2_mux_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1389 | |
| 1390 | static const struct soc_enum sb_tx2_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1391 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B2_CTL, 0, 12, |
| 1392 | sb_tx_1_2_mux_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1393 | |
| 1394 | static const struct soc_enum sb_tx3_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1395 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B3_CTL, 0, 11, sb_tx3_mux_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1396 | |
| 1397 | static const struct soc_enum sb_tx4_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1398 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B4_CTL, 0, 12, sb_tx4_mux_text); |
| 1399 | |
| 1400 | static const struct soc_enum sb_tx5_mux_enum = |
| 1401 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1402 | |
| 1403 | static const struct soc_enum dec1_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1404 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B1_CTL, 0, 10, dec_1_2_mux_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1405 | |
| 1406 | static const struct soc_enum dec2_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1407 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B1_CTL, 4, 10, dec_1_2_mux_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1408 | |
| 1409 | static const struct soc_enum dec3_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1410 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B2_CTL, 0, 12, dec3_mux_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1411 | |
| 1412 | static const struct soc_enum dec4_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1413 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B2_CTL, 4, 12, dec4_mux_text); |
| 1414 | |
| 1415 | static const struct soc_enum anc1_mux_enum = |
| 1416 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B1_CTL, 0, 15, anc_mux_text); |
| 1417 | |
| 1418 | static const struct soc_enum anc2_mux_enum = |
| 1419 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B1_CTL, 4, 15, anc_mux_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1420 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1421 | static const struct soc_enum anc1_fb_mux_enum = |
| 1422 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text); |
| 1423 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1424 | static const struct soc_enum iir1_inp1_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1425 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_EQ1_B1_CTL, 0, 10, iir1_inp1_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1426 | |
| 1427 | static const struct snd_kcontrol_new rx_mix1_inp1_mux = |
| 1428 | SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum); |
| 1429 | |
| 1430 | static const struct snd_kcontrol_new rx_mix1_inp2_mux = |
| 1431 | SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum); |
| 1432 | |
| 1433 | static const struct snd_kcontrol_new rx_mix1_inp3_mux = |
| 1434 | SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum); |
| 1435 | |
| 1436 | static const struct snd_kcontrol_new rx2_mix1_inp1_mux = |
| 1437 | SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum); |
| 1438 | |
| 1439 | static const struct snd_kcontrol_new rx2_mix1_inp2_mux = |
| 1440 | SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum); |
| 1441 | |
| 1442 | static const struct snd_kcontrol_new rx3_mix1_inp1_mux = |
| 1443 | SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum); |
| 1444 | |
| 1445 | static const struct snd_kcontrol_new rx3_mix1_inp2_mux = |
| 1446 | SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum); |
| 1447 | |
Asish Bhattacharya | ba6a49d | 2014-03-19 10:03:45 +0530 | [diff] [blame] | 1448 | static const struct snd_kcontrol_new rx3_mix1_inp3_mux = |
| 1449 | SOC_DAPM_ENUM("RX3 MIX1 INP3 Mux", rx3_mix1_inp3_chain_enum); |
| 1450 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1451 | static const struct snd_kcontrol_new rx4_mix1_inp1_mux = |
| 1452 | SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum); |
| 1453 | |
| 1454 | static const struct snd_kcontrol_new rx4_mix1_inp2_mux = |
| 1455 | SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum); |
| 1456 | |
Santosh Mardi | 330ad2a | 2013-11-21 18:12:14 +0530 | [diff] [blame] | 1457 | static const struct snd_kcontrol_new rx4_mix1_inp3_mux = |
| 1458 | SOC_DAPM_ENUM("RX4 MIX1 INP3 Mux", rx4_mix1_inp3_chain_enum); |
| 1459 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1460 | static const struct snd_kcontrol_new rx1_mix2_inp1_mux = |
| 1461 | SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum); |
| 1462 | |
| 1463 | static const struct snd_kcontrol_new rx1_mix2_inp2_mux = |
| 1464 | SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum); |
| 1465 | |
| 1466 | static const struct snd_kcontrol_new rx2_mix2_inp1_mux = |
| 1467 | SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum); |
| 1468 | |
| 1469 | static const struct snd_kcontrol_new rx2_mix2_inp2_mux = |
| 1470 | SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum); |
| 1471 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1472 | static const struct snd_kcontrol_new rx4_mix2_inp1_mux = |
| 1473 | SOC_DAPM_ENUM("RX4 MIX2 INP1 Mux", rx4_mix2_inp1_chain_enum); |
| 1474 | |
| 1475 | static const struct snd_kcontrol_new rx4_mix2_inp2_mux = |
| 1476 | SOC_DAPM_ENUM("RX4 MIX2 INP2 Mux", rx4_mix2_inp2_chain_enum); |
| 1477 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 1478 | static const struct snd_kcontrol_new rx_dac3_mux = |
| 1479 | SOC_DAPM_ENUM("RDAC3 MUX Mux", rx_rdac3_enum); |
| 1480 | |
| 1481 | static const struct snd_kcontrol_new rx_dac4_mux = |
| 1482 | SOC_DAPM_ENUM("RDAC4 MUX Mux", rx_rdac4_enum); |
| 1483 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1484 | static const struct snd_kcontrol_new rx_dac5_mux = |
| 1485 | SOC_DAPM_ENUM("RDAC5 MUX Mux", rx_rdac5_enum); |
| 1486 | |
| 1487 | static const struct snd_kcontrol_new sb_tx1_mux = |
| 1488 | SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum); |
| 1489 | |
| 1490 | static const struct snd_kcontrol_new sb_tx2_mux = |
| 1491 | SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum); |
| 1492 | |
| 1493 | static const struct snd_kcontrol_new sb_tx3_mux = |
| 1494 | SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum); |
| 1495 | |
| 1496 | static const struct snd_kcontrol_new sb_tx4_mux = |
| 1497 | SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum); |
| 1498 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1499 | static const struct snd_kcontrol_new sb_tx5_mux = |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1500 | SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1501 | |
| 1502 | static int wcd9306_put_dec_enum(struct snd_kcontrol *kcontrol, |
| 1503 | struct snd_ctl_elem_value *ucontrol) |
| 1504 | { |
| 1505 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1506 | struct snd_soc_dapm_widget *w = wlist->widgets[0]; |
| 1507 | struct snd_soc_codec *codec = w->codec; |
| 1508 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1509 | unsigned int dec_mux, decimator; |
| 1510 | char *dec_name = NULL; |
| 1511 | char *widget_name = NULL; |
| 1512 | char *temp; |
| 1513 | u16 tx_mux_ctl_reg; |
| 1514 | u8 adc_dmic_sel = 0x0; |
| 1515 | int ret = 0; |
Aravind Kumar | 320ef3a | 2014-03-21 12:32:34 +0530 | [diff] [blame] | 1516 | char *srch = NULL; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1517 | |
| 1518 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 1519 | return -EINVAL; |
| 1520 | |
| 1521 | dec_mux = ucontrol->value.enumerated.item[0]; |
| 1522 | |
| 1523 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 1524 | if (!widget_name) |
| 1525 | return -ENOMEM; |
| 1526 | temp = widget_name; |
| 1527 | |
| 1528 | dec_name = strsep(&widget_name, " "); |
| 1529 | widget_name = temp; |
| 1530 | if (!dec_name) { |
| 1531 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 1532 | ret = -EINVAL; |
| 1533 | goto out; |
| 1534 | } |
Aravind Kumar | 320ef3a | 2014-03-21 12:32:34 +0530 | [diff] [blame] | 1535 | srch = strpbrk(dec_name, "1234"); |
| 1536 | if (srch == NULL) { |
| 1537 | pr_err("%s: Invalid decimator name %s\n", __func__, dec_name); |
| 1538 | return -EINVAL; |
| 1539 | } |
| 1540 | ret = kstrtouint(srch, 10, &decimator); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1541 | if (ret < 0) { |
| 1542 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 1543 | ret = -EINVAL; |
| 1544 | goto out; |
| 1545 | } |
| 1546 | |
| 1547 | dev_dbg(w->dapm->dev, "%s(): widget = %s decimator = %u dec_mux = %u\n" |
| 1548 | , __func__, w->name, decimator, dec_mux); |
| 1549 | |
| 1550 | switch (decimator) { |
| 1551 | case 1: |
| 1552 | case 2: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1553 | if ((dec_mux >= 1) && (dec_mux <= 5)) |
| 1554 | adc_dmic_sel = 0x0; |
| 1555 | else if ((dec_mux >= 6) && (dec_mux <= 9)) |
| 1556 | adc_dmic_sel = 0x1; |
| 1557 | break; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1558 | case 3: |
| 1559 | case 4: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1560 | if ((dec_mux >= 1) && (dec_mux <= 6)) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1561 | adc_dmic_sel = 0x0; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1562 | else if ((dec_mux >= 7) && (dec_mux <= 10)) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1563 | adc_dmic_sel = 0x1; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1564 | break; |
| 1565 | default: |
| 1566 | pr_err("%s: Invalid Decimator = %u\n", __func__, decimator); |
| 1567 | ret = -EINVAL; |
| 1568 | goto out; |
| 1569 | } |
| 1570 | |
| 1571 | tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 1572 | |
| 1573 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel); |
| 1574 | |
| 1575 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 1576 | |
| 1577 | out: |
| 1578 | kfree(widget_name); |
| 1579 | return ret; |
| 1580 | } |
| 1581 | |
| 1582 | #define WCD9306_DEC_ENUM(xname, xenum) \ |
| 1583 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 1584 | .info = snd_soc_info_enum_double, \ |
| 1585 | .get = snd_soc_dapm_get_enum_double, \ |
| 1586 | .put = wcd9306_put_dec_enum, \ |
| 1587 | .private_value = (unsigned long)&xenum } |
| 1588 | |
| 1589 | static const struct snd_kcontrol_new dec1_mux = |
| 1590 | WCD9306_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum); |
| 1591 | |
| 1592 | static const struct snd_kcontrol_new dec2_mux = |
| 1593 | WCD9306_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum); |
| 1594 | |
| 1595 | static const struct snd_kcontrol_new dec3_mux = |
| 1596 | WCD9306_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum); |
| 1597 | |
| 1598 | static const struct snd_kcontrol_new dec4_mux = |
| 1599 | WCD9306_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum); |
| 1600 | |
| 1601 | static const struct snd_kcontrol_new iir1_inp1_mux = |
| 1602 | SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum); |
| 1603 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1604 | static const struct snd_kcontrol_new anc1_mux = |
| 1605 | SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum); |
| 1606 | |
| 1607 | static const struct snd_kcontrol_new anc2_mux = |
| 1608 | SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum); |
| 1609 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1610 | static const struct snd_kcontrol_new anc1_fb_mux = |
| 1611 | SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum); |
| 1612 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1613 | static const struct snd_kcontrol_new dac1_switch[] = { |
| 1614 | SOC_DAPM_SINGLE("Switch", TAPAN_A_RX_EAR_EN, 5, 1, 0) |
| 1615 | }; |
| 1616 | static const struct snd_kcontrol_new hphl_switch[] = { |
| 1617 | SOC_DAPM_SINGLE("Switch", TAPAN_A_RX_HPH_L_DAC_CTL, 6, 1, 0) |
| 1618 | }; |
| 1619 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1620 | static const struct snd_kcontrol_new spk_dac_switch[] = { |
| 1621 | SOC_DAPM_SINGLE("Switch", TAPAN_A_SPKR_DRV_DAC_CTL, 2, 1, 0) |
| 1622 | }; |
| 1623 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1624 | static const struct snd_kcontrol_new hphl_pa_mix[] = { |
| 1625 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN, |
| 1626 | 7, 1, 0), |
| 1627 | }; |
| 1628 | |
| 1629 | static const struct snd_kcontrol_new hphr_pa_mix[] = { |
| 1630 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TAPAN_A_RX_PA_AUX_IN_CONN, |
| 1631 | 6, 1, 0), |
| 1632 | }; |
| 1633 | |
| 1634 | static const struct snd_kcontrol_new ear_pa_mix[] = { |
| 1635 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN, |
| 1636 | 5, 1, 0), |
| 1637 | }; |
| 1638 | static const struct snd_kcontrol_new lineout1_pa_mix[] = { |
| 1639 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN, |
| 1640 | 4, 1, 0), |
| 1641 | }; |
| 1642 | |
| 1643 | static const struct snd_kcontrol_new lineout2_pa_mix[] = { |
| 1644 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TAPAN_A_RX_PA_AUX_IN_CONN, |
| 1645 | 3, 1, 0), |
| 1646 | }; |
| 1647 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1648 | |
| 1649 | /* virtual port entries */ |
| 1650 | static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol, |
| 1651 | struct snd_ctl_elem_value *ucontrol) |
| 1652 | { |
| 1653 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1654 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1655 | |
| 1656 | ucontrol->value.integer.value[0] = widget->value; |
| 1657 | return 0; |
| 1658 | } |
| 1659 | |
| 1660 | static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol, |
| 1661 | struct snd_ctl_elem_value *ucontrol) |
| 1662 | { |
| 1663 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1664 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1665 | struct snd_soc_codec *codec = widget->codec; |
| 1666 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
| 1667 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 1668 | struct soc_multi_mixer_control *mixer = |
| 1669 | ((struct soc_multi_mixer_control *)kcontrol->private_value); |
| 1670 | u32 dai_id = widget->shift; |
| 1671 | u32 port_id = mixer->shift; |
| 1672 | u32 enable = ucontrol->value.integer.value[0]; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1673 | u32 vtable = vport_check_table[dai_id]; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1674 | |
| 1675 | dev_dbg(codec->dev, "%s: wname %s cname %s\n", |
| 1676 | __func__, widget->name, ucontrol->id.name); |
| 1677 | dev_dbg(codec->dev, "%s: value %u shift %d item %ld\n", |
| 1678 | __func__, widget->value, widget->shift, |
| 1679 | ucontrol->value.integer.value[0]); |
| 1680 | |
| 1681 | mutex_lock(&codec->mutex); |
| 1682 | |
| 1683 | if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 1684 | if (dai_id != AIF1_CAP) { |
| 1685 | dev_err(codec->dev, "%s: invalid AIF for I2C mode\n", |
| 1686 | __func__); |
| 1687 | mutex_unlock(&codec->mutex); |
| 1688 | return -EINVAL; |
| 1689 | } |
| 1690 | } |
| 1691 | switch (dai_id) { |
| 1692 | case AIF1_CAP: |
| 1693 | case AIF2_CAP: |
| 1694 | case AIF3_CAP: |
| 1695 | /* only add to the list if value not set |
| 1696 | */ |
| 1697 | if (enable && !(widget->value & 1 << port_id)) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1698 | if (tapan_p->intf_type == |
| 1699 | WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 1700 | vtable = vport_check_table[dai_id]; |
| 1701 | if (tapan_p->intf_type == |
| 1702 | WCD9XXX_INTERFACE_TYPE_I2C) |
| 1703 | vtable = vport_i2s_check_table[dai_id]; |
| 1704 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1705 | if (wcd9xxx_tx_vport_validation( |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1706 | vtable, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1707 | port_id, |
Aravind Kumar | b95c849 | 2014-03-21 12:43:29 +0530 | [diff] [blame] | 1708 | tapan_p->dai, NUM_CODEC_DAIS)) { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1709 | dev_dbg(codec->dev, "%s: TX%u is used by other virtual port\n", |
| 1710 | __func__, port_id + 1); |
| 1711 | mutex_unlock(&codec->mutex); |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 1712 | return 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1713 | } |
| 1714 | widget->value |= 1 << port_id; |
| 1715 | list_add_tail(&core->tx_chs[port_id].list, |
| 1716 | &tapan_p->dai[dai_id].wcd9xxx_ch_list |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1717 | ); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1718 | } else if (!enable && (widget->value & 1 << port_id)) { |
| 1719 | widget->value &= ~(1 << port_id); |
| 1720 | list_del_init(&core->tx_chs[port_id].list); |
| 1721 | } else { |
| 1722 | if (enable) |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1723 | dev_dbg(codec->dev, "%s: TX%u port is used by\n" |
| 1724 | "this virtual port\n", |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1725 | __func__, port_id + 1); |
| 1726 | else |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1727 | dev_dbg(codec->dev, "%s: TX%u port is not used by\n" |
| 1728 | "this virtual port\n", |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1729 | __func__, port_id + 1); |
| 1730 | /* avoid update power function */ |
| 1731 | mutex_unlock(&codec->mutex); |
| 1732 | return 0; |
| 1733 | } |
| 1734 | break; |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1735 | default: |
| 1736 | dev_err(codec->dev, "Unknown AIF %d\n", dai_id); |
| 1737 | mutex_unlock(&codec->mutex); |
| 1738 | return -EINVAL; |
| 1739 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1740 | dev_dbg(codec->dev, "%s: name %s sname %s updated value %u shift %d\n", |
| 1741 | __func__, widget->name, widget->sname, |
| 1742 | widget->value, widget->shift); |
| 1743 | |
| 1744 | snd_soc_dapm_mixer_update_power(widget, kcontrol, enable); |
| 1745 | |
| 1746 | mutex_unlock(&codec->mutex); |
| 1747 | return 0; |
| 1748 | } |
| 1749 | |
| 1750 | static int slim_rx_mux_get(struct snd_kcontrol *kcontrol, |
| 1751 | struct snd_ctl_elem_value *ucontrol) |
| 1752 | { |
| 1753 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1754 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1755 | |
| 1756 | ucontrol->value.enumerated.item[0] = widget->value; |
| 1757 | return 0; |
| 1758 | } |
| 1759 | |
| 1760 | static const char *const slim_rx_mux_text[] = { |
| 1761 | "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB" |
| 1762 | }; |
| 1763 | |
| 1764 | static int slim_rx_mux_put(struct snd_kcontrol *kcontrol, |
| 1765 | struct snd_ctl_elem_value *ucontrol) |
| 1766 | { |
| 1767 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1768 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1769 | struct snd_soc_codec *codec = widget->codec; |
| 1770 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
| 1771 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 1772 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1773 | u32 port_id = widget->shift; |
| 1774 | |
| 1775 | dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n", |
| 1776 | __func__, widget->name, ucontrol->id.name, widget->value, |
| 1777 | widget->shift, ucontrol->value.integer.value[0]); |
| 1778 | |
| 1779 | widget->value = ucontrol->value.enumerated.item[0]; |
| 1780 | |
| 1781 | mutex_lock(&codec->mutex); |
| 1782 | |
| 1783 | if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 1784 | if (widget->value > 1) { |
| 1785 | dev_err(codec->dev, "%s: invalid AIF for I2C mode\n", |
| 1786 | __func__); |
| 1787 | goto err; |
| 1788 | } |
| 1789 | } |
| 1790 | /* value need to match the Virtual port and AIF number |
| 1791 | */ |
| 1792 | switch (widget->value) { |
| 1793 | case 0: |
| 1794 | list_del_init(&core->rx_chs[port_id].list); |
| 1795 | break; |
| 1796 | case 1: |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 1797 | if (wcd9xxx_rx_vport_validation(port_id + |
| 1798 | TAPAN_RX_PORT_START_NUMBER, |
| 1799 | &tapan_p->dai[AIF1_PB].wcd9xxx_ch_list)) { |
| 1800 | dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n", |
| 1801 | __func__, port_id + 1); |
| 1802 | goto rtn; |
| 1803 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1804 | list_add_tail(&core->rx_chs[port_id].list, |
| 1805 | &tapan_p->dai[AIF1_PB].wcd9xxx_ch_list); |
| 1806 | break; |
| 1807 | case 2: |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 1808 | if (wcd9xxx_rx_vport_validation(port_id + |
| 1809 | TAPAN_RX_PORT_START_NUMBER, |
| 1810 | &tapan_p->dai[AIF2_PB].wcd9xxx_ch_list)) { |
| 1811 | dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n", |
| 1812 | __func__, port_id + 1); |
| 1813 | goto rtn; |
| 1814 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1815 | list_add_tail(&core->rx_chs[port_id].list, |
| 1816 | &tapan_p->dai[AIF2_PB].wcd9xxx_ch_list); |
| 1817 | break; |
| 1818 | case 3: |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 1819 | if (wcd9xxx_rx_vport_validation(port_id + |
| 1820 | TAPAN_RX_PORT_START_NUMBER, |
| 1821 | &tapan_p->dai[AIF3_PB].wcd9xxx_ch_list)) { |
| 1822 | dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n", |
| 1823 | __func__, port_id + 1); |
| 1824 | goto rtn; |
| 1825 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1826 | list_add_tail(&core->rx_chs[port_id].list, |
| 1827 | &tapan_p->dai[AIF3_PB].wcd9xxx_ch_list); |
| 1828 | break; |
| 1829 | default: |
| 1830 | pr_err("Unknown AIF %d\n", widget->value); |
| 1831 | goto err; |
| 1832 | } |
| 1833 | |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 1834 | rtn: |
Jay Chokshi | 83b4f613 | 2013-02-14 16:20:56 -0800 | [diff] [blame] | 1835 | snd_soc_dapm_mux_update_power(widget, kcontrol, 1, widget->value, e); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1836 | mutex_unlock(&codec->mutex); |
| 1837 | return 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1838 | err: |
| 1839 | mutex_unlock(&codec->mutex); |
| 1840 | return -EINVAL; |
| 1841 | } |
| 1842 | |
| 1843 | static const struct soc_enum slim_rx_mux_enum = |
| 1844 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text), slim_rx_mux_text); |
| 1845 | |
| 1846 | static const struct snd_kcontrol_new slim_rx_mux[TAPAN_RX_MAX] = { |
| 1847 | SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum, |
| 1848 | slim_rx_mux_get, slim_rx_mux_put), |
| 1849 | SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum, |
| 1850 | slim_rx_mux_get, slim_rx_mux_put), |
| 1851 | SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum, |
| 1852 | slim_rx_mux_get, slim_rx_mux_put), |
| 1853 | SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum, |
| 1854 | slim_rx_mux_get, slim_rx_mux_put), |
| 1855 | SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum, |
| 1856 | slim_rx_mux_get, slim_rx_mux_put), |
| 1857 | }; |
| 1858 | |
| 1859 | static const struct snd_kcontrol_new aif_cap_mixer[] = { |
| 1860 | SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, TAPAN_TX1, 1, 0, |
| 1861 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1862 | SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, TAPAN_TX2, 1, 0, |
| 1863 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1864 | SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, TAPAN_TX3, 1, 0, |
| 1865 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1866 | SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, TAPAN_TX4, 1, 0, |
| 1867 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1868 | SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, TAPAN_TX5, 1, 0, |
| 1869 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1870 | }; |
| 1871 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1872 | static int tapan_codec_enable_adc(struct snd_soc_dapm_widget *w, |
| 1873 | struct snd_kcontrol *kcontrol, int event) |
| 1874 | { |
| 1875 | struct snd_soc_codec *codec = w->codec; |
Phani Kumar Uppalapati | 7c0bf70 | 2013-11-25 13:39:53 -0800 | [diff] [blame] | 1876 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1877 | u16 adc_reg; |
| 1878 | u8 init_bit_shift; |
| 1879 | |
| 1880 | dev_dbg(codec->dev, "%s(): %s %d\n", __func__, w->name, event); |
| 1881 | |
| 1882 | if (w->reg == TAPAN_A_TX_1_EN) { |
| 1883 | init_bit_shift = 7; |
| 1884 | adc_reg = TAPAN_A_TX_1_2_TEST_CTL; |
| 1885 | } else if (w->reg == TAPAN_A_TX_2_EN) { |
| 1886 | init_bit_shift = 6; |
| 1887 | adc_reg = TAPAN_A_TX_1_2_TEST_CTL; |
| 1888 | } else if (w->reg == TAPAN_A_TX_3_EN) { |
| 1889 | init_bit_shift = 6; |
| 1890 | adc_reg = TAPAN_A_TX_1_2_TEST_CTL; |
| 1891 | } else if (w->reg == TAPAN_A_TX_4_EN) { |
| 1892 | init_bit_shift = 7; |
| 1893 | adc_reg = TAPAN_A_TX_4_5_TEST_CTL; |
| 1894 | } else if (w->reg == TAPAN_A_TX_5_EN) { |
| 1895 | init_bit_shift = 6; |
| 1896 | adc_reg = TAPAN_A_TX_4_5_TEST_CTL; |
| 1897 | } else { |
| 1898 | pr_err("%s: Error, invalid adc register\n", __func__); |
| 1899 | return -EINVAL; |
| 1900 | } |
| 1901 | |
| 1902 | switch (event) { |
| 1903 | case SND_SOC_DAPM_PRE_PMU: |
Phani Kumar Uppalapati | 7e3f57d | 2013-12-12 12:26:59 -0800 | [diff] [blame] | 1904 | if (w->reg == TAPAN_A_TX_3_EN || |
| 1905 | w->reg == TAPAN_A_TX_1_EN) |
Phani Kumar Uppalapati | 7c0bf70 | 2013-11-25 13:39:53 -0800 | [diff] [blame] | 1906 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, |
Phani Kumar Uppalapati | 7e3f57d | 2013-12-12 12:26:59 -0800 | [diff] [blame] | 1907 | WCD9XXX_EVENT_PRE_TX_1_3_ON); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1908 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, |
| 1909 | 1 << init_bit_shift); |
| 1910 | break; |
| 1911 | case SND_SOC_DAPM_POST_PMU: |
| 1912 | |
| 1913 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00); |
| 1914 | |
| 1915 | break; |
Phani Kumar Uppalapati | 7c0bf70 | 2013-11-25 13:39:53 -0800 | [diff] [blame] | 1916 | case SND_SOC_DAPM_POST_PMD: |
Phani Kumar Uppalapati | 7e3f57d | 2013-12-12 12:26:59 -0800 | [diff] [blame] | 1917 | if (w->reg == TAPAN_A_TX_3_EN || |
| 1918 | w->reg == TAPAN_A_TX_1_EN) |
Phani Kumar Uppalapati | 7c0bf70 | 2013-11-25 13:39:53 -0800 | [diff] [blame] | 1919 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, |
Phani Kumar Uppalapati | 7e3f57d | 2013-12-12 12:26:59 -0800 | [diff] [blame] | 1920 | WCD9XXX_EVENT_POST_TX_1_3_OFF); |
Phani Kumar Uppalapati | 7c0bf70 | 2013-11-25 13:39:53 -0800 | [diff] [blame] | 1921 | break; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1922 | } |
| 1923 | return 0; |
| 1924 | } |
| 1925 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1926 | static int tapan_codec_enable_aux_pga(struct snd_soc_dapm_widget *w, |
| 1927 | struct snd_kcontrol *kcontrol, int event) |
| 1928 | { |
| 1929 | struct snd_soc_codec *codec = w->codec; |
| 1930 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 1931 | |
| 1932 | dev_dbg(codec->dev, "%s: %d\n", __func__, event); |
| 1933 | |
| 1934 | switch (event) { |
| 1935 | case SND_SOC_DAPM_PRE_PMU: |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 1936 | WCD9XXX_BG_CLK_LOCK(&tapan->resmgr); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1937 | wcd9xxx_resmgr_get_bandgap(&tapan->resmgr, |
| 1938 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 1939 | /* AUX PGA requires RCO or MCLK */ |
| 1940 | wcd9xxx_resmgr_get_clk_block(&tapan->resmgr, WCD9XXX_CLK_RCO); |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 1941 | WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1942 | wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 1); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1943 | break; |
| 1944 | |
| 1945 | case SND_SOC_DAPM_POST_PMD: |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1946 | wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 0); |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 1947 | WCD9XXX_BG_CLK_LOCK(&tapan->resmgr); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1948 | wcd9xxx_resmgr_put_bandgap(&tapan->resmgr, |
| 1949 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 1950 | wcd9xxx_resmgr_put_clk_block(&tapan->resmgr, WCD9XXX_CLK_RCO); |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 1951 | WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1952 | break; |
| 1953 | } |
| 1954 | return 0; |
| 1955 | } |
| 1956 | |
| 1957 | static int tapan_codec_enable_lineout(struct snd_soc_dapm_widget *w, |
| 1958 | struct snd_kcontrol *kcontrol, int event) |
| 1959 | { |
| 1960 | struct snd_soc_codec *codec = w->codec; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1961 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1962 | u16 lineout_gain_reg; |
| 1963 | |
| 1964 | dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name); |
| 1965 | |
| 1966 | switch (w->shift) { |
| 1967 | case 0: |
| 1968 | lineout_gain_reg = TAPAN_A_RX_LINE_1_GAIN; |
| 1969 | break; |
| 1970 | case 1: |
| 1971 | lineout_gain_reg = TAPAN_A_RX_LINE_2_GAIN; |
| 1972 | break; |
| 1973 | default: |
| 1974 | pr_err("%s: Error, incorrect lineout register value\n", |
| 1975 | __func__); |
| 1976 | return -EINVAL; |
| 1977 | } |
| 1978 | |
| 1979 | switch (event) { |
| 1980 | case SND_SOC_DAPM_PRE_PMU: |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1981 | break; |
| 1982 | case SND_SOC_DAPM_POST_PMU: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1983 | wcd9xxx_clsh_fsm(codec, &tapan->clsh_d, |
| 1984 | WCD9XXX_CLSH_STATE_LO, |
| 1985 | WCD9XXX_CLSH_REQ_ENABLE, |
| 1986 | WCD9XXX_CLSH_EVENT_POST_PA); |
| 1987 | dev_dbg(codec->dev, "%s: sleeping 3 ms after %s PA turn on\n", |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1988 | __func__, w->name); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1989 | usleep_range(3000, 3010); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1990 | break; |
| 1991 | case SND_SOC_DAPM_POST_PMD: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1992 | wcd9xxx_clsh_fsm(codec, &tapan->clsh_d, |
| 1993 | WCD9XXX_CLSH_STATE_LO, |
| 1994 | WCD9XXX_CLSH_REQ_DISABLE, |
| 1995 | WCD9XXX_CLSH_EVENT_POST_PA); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1996 | break; |
| 1997 | } |
| 1998 | return 0; |
| 1999 | } |
| 2000 | |
| 2001 | static int tapan_codec_enable_spk_pa(struct snd_soc_dapm_widget *w, |
| 2002 | struct snd_kcontrol *kcontrol, int event) |
| 2003 | { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2004 | struct snd_soc_codec *codec = w->codec; |
| 2005 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 2006 | |
| 2007 | dev_dbg(codec->dev, "%s: %s %d\n", __func__, w->name, event); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2008 | switch (event) { |
| 2009 | case SND_SOC_DAPM_PRE_PMU: |
| 2010 | tapan->spkr_pa_widget_on = true; |
| 2011 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80); |
| 2012 | break; |
| 2013 | case SND_SOC_DAPM_POST_PMD: |
| 2014 | tapan->spkr_pa_widget_on = false; |
| 2015 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x00); |
| 2016 | break; |
| 2017 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2018 | return 0; |
| 2019 | } |
| 2020 | |
| 2021 | static int tapan_codec_enable_dmic(struct snd_soc_dapm_widget *w, |
| 2022 | struct snd_kcontrol *kcontrol, int event) |
| 2023 | { |
| 2024 | struct snd_soc_codec *codec = w->codec; |
| 2025 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 2026 | u8 dmic_clk_en; |
| 2027 | u16 dmic_clk_reg; |
| 2028 | s32 *dmic_clk_cnt; |
| 2029 | unsigned int dmic; |
| 2030 | int ret; |
Aravind Kumar | 320ef3a | 2014-03-21 12:32:34 +0530 | [diff] [blame] | 2031 | char *srch = NULL; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2032 | |
Aravind Kumar | 320ef3a | 2014-03-21 12:32:34 +0530 | [diff] [blame] | 2033 | srch = strpbrk(w->name, "1234"); |
| 2034 | if (srch == NULL) { |
| 2035 | pr_err("%s: Invalid widget name %s\n", __func__, w->name); |
| 2036 | return -EINVAL; |
| 2037 | } |
| 2038 | |
| 2039 | ret = kstrtouint(srch, 10, &dmic); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2040 | if (ret < 0) { |
| 2041 | pr_err("%s: Invalid DMIC line on the codec\n", __func__); |
| 2042 | return -EINVAL; |
| 2043 | } |
| 2044 | |
| 2045 | switch (dmic) { |
| 2046 | case 1: |
| 2047 | case 2: |
| 2048 | dmic_clk_en = 0x01; |
| 2049 | dmic_clk_cnt = &(tapan->dmic_1_2_clk_cnt); |
| 2050 | dmic_clk_reg = TAPAN_A_CDC_CLK_DMIC_B1_CTL; |
| 2051 | dev_dbg(codec->dev, "%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n", |
| 2052 | __func__, event, dmic, *dmic_clk_cnt); |
| 2053 | |
| 2054 | break; |
| 2055 | |
| 2056 | case 3: |
| 2057 | case 4: |
| 2058 | dmic_clk_en = 0x10; |
| 2059 | dmic_clk_cnt = &(tapan->dmic_3_4_clk_cnt); |
| 2060 | dmic_clk_reg = TAPAN_A_CDC_CLK_DMIC_B1_CTL; |
| 2061 | |
| 2062 | dev_dbg(codec->dev, "%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n", |
| 2063 | __func__, event, dmic, *dmic_clk_cnt); |
| 2064 | break; |
| 2065 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2066 | default: |
| 2067 | pr_err("%s: Invalid DMIC Selection\n", __func__); |
| 2068 | return -EINVAL; |
| 2069 | } |
| 2070 | |
| 2071 | switch (event) { |
| 2072 | case SND_SOC_DAPM_PRE_PMU: |
| 2073 | |
| 2074 | (*dmic_clk_cnt)++; |
| 2075 | if (*dmic_clk_cnt == 1) |
| 2076 | snd_soc_update_bits(codec, dmic_clk_reg, |
| 2077 | dmic_clk_en, dmic_clk_en); |
| 2078 | |
| 2079 | break; |
| 2080 | case SND_SOC_DAPM_POST_PMD: |
| 2081 | |
| 2082 | (*dmic_clk_cnt)--; |
| 2083 | if (*dmic_clk_cnt == 0) |
| 2084 | snd_soc_update_bits(codec, dmic_clk_reg, |
| 2085 | dmic_clk_en, 0); |
| 2086 | break; |
| 2087 | } |
| 2088 | return 0; |
| 2089 | } |
| 2090 | |
| 2091 | static int tapan_codec_enable_anc(struct snd_soc_dapm_widget *w, |
| 2092 | struct snd_kcontrol *kcontrol, int event) |
| 2093 | { |
| 2094 | struct snd_soc_codec *codec = w->codec; |
| 2095 | const char *filename; |
| 2096 | const struct firmware *fw; |
| 2097 | int i; |
| 2098 | int ret; |
| 2099 | int num_anc_slots; |
Simmi Pateriya | df675e9 | 2013-04-05 01:15:54 +0530 | [diff] [blame] | 2100 | struct wcd9xxx_anc_header *anc_head; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2101 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 2102 | u32 anc_writes_size = 0; |
| 2103 | int anc_size_remaining; |
| 2104 | u32 *anc_ptr; |
| 2105 | u16 reg; |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2106 | u8 mask, val, old_val; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2107 | |
| 2108 | dev_dbg(codec->dev, "%s %d\n", __func__, event); |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2109 | if (tapan->anc_func == 0) |
| 2110 | return 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2111 | switch (event) { |
| 2112 | case SND_SOC_DAPM_PRE_PMU: |
| 2113 | |
| 2114 | filename = "wcd9306/wcd9306_anc.bin"; |
| 2115 | |
| 2116 | ret = request_firmware(&fw, filename, codec->dev); |
| 2117 | if (ret != 0) { |
| 2118 | dev_err(codec->dev, "Failed to acquire ANC data: %d\n", |
| 2119 | ret); |
| 2120 | return -ENODEV; |
| 2121 | } |
| 2122 | |
Simmi Pateriya | df675e9 | 2013-04-05 01:15:54 +0530 | [diff] [blame] | 2123 | if (fw->size < sizeof(struct wcd9xxx_anc_header)) { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2124 | dev_err(codec->dev, "Not enough data\n"); |
| 2125 | release_firmware(fw); |
| 2126 | return -ENOMEM; |
| 2127 | } |
| 2128 | |
| 2129 | /* First number is the number of register writes */ |
Simmi Pateriya | df675e9 | 2013-04-05 01:15:54 +0530 | [diff] [blame] | 2130 | anc_head = (struct wcd9xxx_anc_header *)(fw->data); |
| 2131 | anc_ptr = (u32 *)((u32)fw->data + |
| 2132 | sizeof(struct wcd9xxx_anc_header)); |
| 2133 | anc_size_remaining = fw->size - |
| 2134 | sizeof(struct wcd9xxx_anc_header); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2135 | num_anc_slots = anc_head->num_anc_slots; |
| 2136 | |
| 2137 | if (tapan->anc_slot >= num_anc_slots) { |
| 2138 | dev_err(codec->dev, "Invalid ANC slot selected\n"); |
| 2139 | release_firmware(fw); |
| 2140 | return -EINVAL; |
| 2141 | } |
| 2142 | |
| 2143 | for (i = 0; i < num_anc_slots; i++) { |
| 2144 | |
| 2145 | if (anc_size_remaining < TAPAN_PACKED_REG_SIZE) { |
| 2146 | dev_err(codec->dev, "Invalid register format\n"); |
| 2147 | release_firmware(fw); |
| 2148 | return -EINVAL; |
| 2149 | } |
| 2150 | anc_writes_size = (u32)(*anc_ptr); |
| 2151 | anc_size_remaining -= sizeof(u32); |
| 2152 | anc_ptr += 1; |
| 2153 | |
| 2154 | if (anc_writes_size * TAPAN_PACKED_REG_SIZE |
| 2155 | > anc_size_remaining) { |
| 2156 | dev_err(codec->dev, "Invalid register format\n"); |
| 2157 | release_firmware(fw); |
| 2158 | return -ENOMEM; |
| 2159 | } |
| 2160 | |
| 2161 | if (tapan->anc_slot == i) |
| 2162 | break; |
| 2163 | |
| 2164 | anc_size_remaining -= (anc_writes_size * |
| 2165 | TAPAN_PACKED_REG_SIZE); |
| 2166 | anc_ptr += anc_writes_size; |
| 2167 | } |
| 2168 | if (i == num_anc_slots) { |
| 2169 | dev_err(codec->dev, "Selected ANC slot not present\n"); |
| 2170 | release_firmware(fw); |
| 2171 | return -ENOMEM; |
| 2172 | } |
| 2173 | |
| 2174 | for (i = 0; i < anc_writes_size; i++) { |
| 2175 | TAPAN_CODEC_UNPACK_ENTRY(anc_ptr[i], reg, |
| 2176 | mask, val); |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2177 | old_val = snd_soc_read(codec, reg); |
| 2178 | snd_soc_write(codec, reg, (old_val & ~mask) | |
| 2179 | (val & mask)); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2180 | } |
| 2181 | release_firmware(fw); |
| 2182 | |
| 2183 | break; |
Damir Didjusto | 1ede84a | 2013-05-23 16:38:11 -0700 | [diff] [blame] | 2184 | case SND_SOC_DAPM_PRE_PMD: |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2185 | msleep(40); |
| 2186 | snd_soc_update_bits(codec, TAPAN_A_CDC_ANC1_B1_CTL, 0x01, 0x00); |
| 2187 | snd_soc_update_bits(codec, TAPAN_A_CDC_ANC2_B1_CTL, 0x02, 0x00); |
| 2188 | msleep(20); |
| 2189 | snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_RESET_CTL, 0x0F); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2190 | snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_CLK_EN_CTL, 0); |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2191 | snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_RESET_CTL, 0xFF); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2192 | break; |
| 2193 | } |
| 2194 | return 0; |
| 2195 | } |
| 2196 | |
| 2197 | static int tapan_codec_enable_micbias(struct snd_soc_dapm_widget *w, |
| 2198 | struct snd_kcontrol *kcontrol, int event) |
| 2199 | { |
| 2200 | struct snd_soc_codec *codec = w->codec; |
| 2201 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2202 | u16 micb_int_reg = 0, micb_ctl_reg = 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2203 | u8 cfilt_sel_val = 0; |
| 2204 | char *internal1_text = "Internal1"; |
| 2205 | char *internal2_text = "Internal2"; |
| 2206 | char *internal3_text = "Internal3"; |
| 2207 | enum wcd9xxx_notify_event e_post_off, e_pre_on, e_post_on; |
| 2208 | |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2209 | pr_debug("%s: w->name %s event %d\n", __func__, w->name, event); |
| 2210 | if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1"))) { |
| 2211 | micb_ctl_reg = TAPAN_A_MICB_1_CTL; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2212 | micb_int_reg = TAPAN_A_MICB_1_INT_RBIAS; |
| 2213 | cfilt_sel_val = tapan->resmgr.pdata->micbias.bias1_cfilt_sel; |
| 2214 | e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_1_ON; |
| 2215 | e_post_on = WCD9XXX_EVENT_POST_MICBIAS_1_ON; |
| 2216 | e_post_off = WCD9XXX_EVENT_POST_MICBIAS_1_OFF; |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2217 | } else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2"))) { |
| 2218 | micb_ctl_reg = TAPAN_A_MICB_2_CTL; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2219 | micb_int_reg = TAPAN_A_MICB_2_INT_RBIAS; |
| 2220 | cfilt_sel_val = tapan->resmgr.pdata->micbias.bias2_cfilt_sel; |
| 2221 | e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_2_ON; |
| 2222 | e_post_on = WCD9XXX_EVENT_POST_MICBIAS_2_ON; |
| 2223 | e_post_off = WCD9XXX_EVENT_POST_MICBIAS_2_OFF; |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2224 | } else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3"))) { |
| 2225 | micb_ctl_reg = TAPAN_A_MICB_3_CTL; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2226 | micb_int_reg = TAPAN_A_MICB_3_INT_RBIAS; |
| 2227 | cfilt_sel_val = tapan->resmgr.pdata->micbias.bias3_cfilt_sel; |
| 2228 | e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_3_ON; |
| 2229 | e_post_on = WCD9XXX_EVENT_POST_MICBIAS_3_ON; |
| 2230 | e_post_off = WCD9XXX_EVENT_POST_MICBIAS_3_OFF; |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2231 | } else { |
| 2232 | pr_err("%s: Error, invalid micbias %s\n", __func__, w->name); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2233 | return -EINVAL; |
| 2234 | } |
| 2235 | |
| 2236 | switch (event) { |
| 2237 | case SND_SOC_DAPM_PRE_PMU: |
| 2238 | /* Let MBHC module know so micbias switch to be off */ |
| 2239 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_pre_on); |
| 2240 | |
| 2241 | /* Get cfilt */ |
| 2242 | wcd9xxx_resmgr_cfilt_get(&tapan->resmgr, cfilt_sel_val); |
| 2243 | |
| 2244 | if (strnstr(w->name, internal1_text, 30)) |
| 2245 | snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0); |
| 2246 | else if (strnstr(w->name, internal2_text, 30)) |
| 2247 | snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C); |
| 2248 | else if (strnstr(w->name, internal3_text, 30)) |
| 2249 | snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3); |
| 2250 | |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2251 | if (micb_ctl_reg == TAPAN_A_MICB_2_CTL) { |
| 2252 | if (++tapan->micb_2_users == 1) |
| 2253 | wcd9xxx_resmgr_add_cond_update_bits( |
| 2254 | &tapan->resmgr, |
| 2255 | WCD9XXX_COND_HPH_MIC, |
| 2256 | micb_ctl_reg, w->shift, |
| 2257 | false); |
| 2258 | pr_debug("%s: micb_2_users %d\n", __func__, |
| 2259 | tapan->micb_2_users); |
| 2260 | } else |
| 2261 | snd_soc_update_bits(codec, micb_ctl_reg, 1 << w->shift, |
| 2262 | 1 << w->shift); |
| 2263 | |
| 2264 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2265 | break; |
| 2266 | case SND_SOC_DAPM_POST_PMU: |
| 2267 | usleep_range(20000, 20000); |
| 2268 | /* Let MBHC module know so micbias is on */ |
| 2269 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_on); |
| 2270 | break; |
| 2271 | case SND_SOC_DAPM_POST_PMD: |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2272 | if (micb_ctl_reg == TAPAN_A_MICB_2_CTL) { |
| 2273 | if (--tapan->micb_2_users == 0) |
| 2274 | wcd9xxx_resmgr_rm_cond_update_bits( |
| 2275 | &tapan->resmgr, |
| 2276 | WCD9XXX_COND_HPH_MIC, |
| 2277 | micb_ctl_reg, 7, |
| 2278 | false); |
| 2279 | pr_debug("%s: micb_2_users %d\n", __func__, |
| 2280 | tapan->micb_2_users); |
| 2281 | WARN(tapan->micb_2_users < 0, |
| 2282 | "Unexpected micbias users %d\n", |
| 2283 | tapan->micb_2_users); |
| 2284 | } else |
| 2285 | snd_soc_update_bits(codec, micb_ctl_reg, 1 << w->shift, |
| 2286 | 0); |
| 2287 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2288 | /* Let MBHC module know so micbias switch to be off */ |
| 2289 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_off); |
| 2290 | |
| 2291 | if (strnstr(w->name, internal1_text, 30)) |
| 2292 | snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00); |
| 2293 | else if (strnstr(w->name, internal2_text, 30)) |
| 2294 | snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00); |
| 2295 | else if (strnstr(w->name, internal3_text, 30)) |
| 2296 | snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0); |
| 2297 | |
| 2298 | /* Put cfilt */ |
| 2299 | wcd9xxx_resmgr_cfilt_put(&tapan->resmgr, cfilt_sel_val); |
| 2300 | break; |
| 2301 | } |
| 2302 | |
| 2303 | return 0; |
| 2304 | } |
| 2305 | |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2306 | /* called under codec_resource_lock acquisition */ |
Phani Kumar Uppalapati | b7266bd | 2013-10-21 14:26:10 -0700 | [diff] [blame] | 2307 | static int tapan_enable_mbhc_micbias(struct snd_soc_codec *codec, bool enable, |
| 2308 | enum wcd9xxx_micbias_num micb_num) |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2309 | { |
| 2310 | int rc; |
Phani Kumar Uppalapati | b7266bd | 2013-10-21 14:26:10 -0700 | [diff] [blame] | 2311 | const char *micbias; |
| 2312 | |
| 2313 | if (micb_num == MBHC_MICBIAS2) |
| 2314 | micbias = DAPM_MICBIAS2_EXTERNAL_STANDALONE; |
| 2315 | else |
| 2316 | return -EINVAL; |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2317 | |
| 2318 | if (enable) |
| 2319 | rc = snd_soc_dapm_force_enable_pin(&codec->dapm, |
Phani Kumar Uppalapati | b7266bd | 2013-10-21 14:26:10 -0700 | [diff] [blame] | 2320 | micbias); |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2321 | else |
| 2322 | rc = snd_soc_dapm_disable_pin(&codec->dapm, |
Phani Kumar Uppalapati | b7266bd | 2013-10-21 14:26:10 -0700 | [diff] [blame] | 2323 | micbias); |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2324 | if (!rc) |
| 2325 | snd_soc_dapm_sync(&codec->dapm); |
| 2326 | pr_debug("%s: leave ret %d\n", __func__, rc); |
| 2327 | return rc; |
| 2328 | } |
| 2329 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2330 | static void tx_hpf_corner_freq_callback(struct work_struct *work) |
| 2331 | { |
| 2332 | struct delayed_work *hpf_delayed_work; |
| 2333 | struct hpf_work *hpf_work; |
| 2334 | struct tapan_priv *tapan; |
| 2335 | struct snd_soc_codec *codec; |
| 2336 | u16 tx_mux_ctl_reg; |
| 2337 | u8 hpf_cut_of_freq; |
| 2338 | |
| 2339 | hpf_delayed_work = to_delayed_work(work); |
| 2340 | hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork); |
| 2341 | tapan = hpf_work->tapan; |
| 2342 | codec = hpf_work->tapan->codec; |
| 2343 | hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq; |
| 2344 | |
| 2345 | tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL + |
| 2346 | (hpf_work->decimator - 1) * 8; |
| 2347 | |
| 2348 | dev_dbg(codec->dev, "%s(): decimator %u hpf_cut_of_freq 0x%x\n", |
| 2349 | __func__, hpf_work->decimator, (unsigned int)hpf_cut_of_freq); |
| 2350 | |
| 2351 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4); |
| 2352 | } |
| 2353 | |
| 2354 | #define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30 |
| 2355 | #define CF_MIN_3DB_4HZ 0x0 |
| 2356 | #define CF_MIN_3DB_75HZ 0x1 |
| 2357 | #define CF_MIN_3DB_150HZ 0x2 |
| 2358 | |
| 2359 | static int tapan_codec_enable_dec(struct snd_soc_dapm_widget *w, |
| 2360 | struct snd_kcontrol *kcontrol, int event) |
| 2361 | { |
| 2362 | struct snd_soc_codec *codec = w->codec; |
| 2363 | unsigned int decimator; |
| 2364 | char *dec_name = NULL; |
| 2365 | char *widget_name = NULL; |
| 2366 | char *temp; |
| 2367 | int ret = 0; |
| 2368 | u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg; |
| 2369 | u8 dec_hpf_cut_of_freq; |
| 2370 | int offset; |
Aravind Kumar | 320ef3a | 2014-03-21 12:32:34 +0530 | [diff] [blame] | 2371 | char *srch = NULL; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2372 | |
| 2373 | dev_dbg(codec->dev, "%s %d\n", __func__, event); |
| 2374 | |
| 2375 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 2376 | if (!widget_name) |
| 2377 | return -ENOMEM; |
| 2378 | temp = widget_name; |
| 2379 | |
| 2380 | dec_name = strsep(&widget_name, " "); |
| 2381 | widget_name = temp; |
| 2382 | if (!dec_name) { |
| 2383 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 2384 | ret = -EINVAL; |
| 2385 | goto out; |
| 2386 | } |
Aravind Kumar | 320ef3a | 2014-03-21 12:32:34 +0530 | [diff] [blame] | 2387 | srch = strpbrk(dec_name, "123456789"); |
| 2388 | if (srch == NULL) { |
| 2389 | pr_err("%s: Invalid decimator name %s\n", __func__, dec_name); |
| 2390 | return -EINVAL; |
| 2391 | } |
| 2392 | ret = kstrtouint(srch, 10, &decimator); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2393 | if (ret < 0) { |
| 2394 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 2395 | ret = -EINVAL; |
| 2396 | goto out; |
| 2397 | } |
| 2398 | |
| 2399 | dev_dbg(codec->dev, "%s(): widget = %s dec_name = %s decimator = %u\n", |
| 2400 | __func__, w->name, dec_name, decimator); |
| 2401 | |
| 2402 | if (w->reg == TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL) { |
| 2403 | dec_reset_reg = TAPAN_A_CDC_CLK_TX_RESET_B1_CTL; |
| 2404 | offset = 0; |
| 2405 | } else if (w->reg == TAPAN_A_CDC_CLK_TX_CLK_EN_B2_CTL) { |
| 2406 | dec_reset_reg = TAPAN_A_CDC_CLK_TX_RESET_B2_CTL; |
| 2407 | offset = 8; |
| 2408 | } else { |
| 2409 | pr_err("%s: Error, incorrect dec\n", __func__); |
| 2410 | ret = -EINVAL; |
| 2411 | goto out; |
| 2412 | } |
| 2413 | |
| 2414 | tx_vol_ctl_reg = TAPAN_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator - 1); |
| 2415 | tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 2416 | |
| 2417 | switch (event) { |
| 2418 | case SND_SOC_DAPM_PRE_PMU: |
| 2419 | |
| 2420 | /* Enableable TX digital mute */ |
| 2421 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 2422 | |
| 2423 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, |
| 2424 | 1 << w->shift); |
| 2425 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0); |
| 2426 | |
| 2427 | dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg); |
| 2428 | |
| 2429 | dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4; |
| 2430 | |
| 2431 | tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq = |
| 2432 | dec_hpf_cut_of_freq; |
| 2433 | |
| 2434 | if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) { |
| 2435 | |
| 2436 | /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */ |
| 2437 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 2438 | CF_MIN_3DB_150HZ << 4); |
| 2439 | } |
| 2440 | |
| 2441 | /* enable HPF */ |
| 2442 | snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00); |
| 2443 | |
| 2444 | break; |
| 2445 | |
| 2446 | case SND_SOC_DAPM_POST_PMU: |
| 2447 | |
| 2448 | /* Disable TX digital mute */ |
| 2449 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00); |
| 2450 | |
| 2451 | if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq != |
| 2452 | CF_MIN_3DB_150HZ) { |
| 2453 | |
| 2454 | schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork, |
| 2455 | msecs_to_jiffies(300)); |
| 2456 | } |
| 2457 | /* apply the digital gain after the decimator is enabled*/ |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2458 | if ((w->shift + offset) < ARRAY_SIZE(tx_digital_gain_reg)) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2459 | snd_soc_write(codec, |
| 2460 | tx_digital_gain_reg[w->shift + offset], |
| 2461 | snd_soc_read(codec, |
| 2462 | tx_digital_gain_reg[w->shift + offset]) |
| 2463 | ); |
| 2464 | |
| 2465 | break; |
| 2466 | |
| 2467 | case SND_SOC_DAPM_PRE_PMD: |
| 2468 | |
| 2469 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 2470 | cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork); |
| 2471 | break; |
| 2472 | |
| 2473 | case SND_SOC_DAPM_POST_PMD: |
| 2474 | |
| 2475 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08); |
| 2476 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 2477 | (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4); |
| 2478 | |
| 2479 | break; |
| 2480 | } |
| 2481 | out: |
| 2482 | kfree(widget_name); |
| 2483 | return ret; |
| 2484 | } |
| 2485 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2486 | static int tapan_codec_enable_vdd_spkr(struct snd_soc_dapm_widget *w, |
| 2487 | struct snd_kcontrol *kcontrol, int event) |
| 2488 | { |
| 2489 | struct snd_soc_codec *codec = w->codec; |
| 2490 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 2491 | |
| 2492 | dev_dbg(codec->dev, "%s: %s %d\n", __func__, w->name, event); |
| 2493 | |
| 2494 | switch (event) { |
| 2495 | case SND_SOC_DAPM_PRE_PMU: |
| 2496 | |
| 2497 | if (spkr_drv_wrnd > 0) { |
| 2498 | WARN_ON(!(snd_soc_read(codec, TAPAN_A_SPKR_DRV_EN) & |
| 2499 | 0x80)); |
| 2500 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, |
| 2501 | 0x00); |
| 2502 | } |
| 2503 | if (TAPAN_IS_1_0(core->version)) |
| 2504 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_DBG_PWRSTG, |
| 2505 | 0x24, 0x00); |
| 2506 | break; |
| 2507 | case SND_SOC_DAPM_POST_PMD: |
| 2508 | if (TAPAN_IS_1_0(core->version)) |
| 2509 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_DBG_PWRSTG, |
| 2510 | 0x24, 0x24); |
| 2511 | if (spkr_drv_wrnd > 0) { |
| 2512 | WARN_ON(!!(snd_soc_read(codec, TAPAN_A_SPKR_DRV_EN) & |
| 2513 | 0x80)); |
| 2514 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, |
| 2515 | 0x80); |
| 2516 | } |
| 2517 | break; |
| 2518 | } |
| 2519 | return 0; |
| 2520 | } |
| 2521 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2522 | static int tapan_codec_enable_interpolator(struct snd_soc_dapm_widget *w, |
| 2523 | struct snd_kcontrol *kcontrol, int event) |
| 2524 | { |
| 2525 | struct snd_soc_codec *codec = w->codec; |
| 2526 | |
| 2527 | dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name); |
| 2528 | |
| 2529 | switch (event) { |
| 2530 | case SND_SOC_DAPM_PRE_PMU: |
| 2531 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_RESET_CTL, |
| 2532 | 1 << w->shift, 1 << w->shift); |
| 2533 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_RESET_CTL, |
| 2534 | 1 << w->shift, 0x0); |
| 2535 | break; |
| 2536 | case SND_SOC_DAPM_POST_PMU: |
| 2537 | /* apply the digital gain after the interpolator is enabled*/ |
| 2538 | if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg)) |
| 2539 | snd_soc_write(codec, |
| 2540 | rx_digital_gain_reg[w->shift], |
| 2541 | snd_soc_read(codec, |
| 2542 | rx_digital_gain_reg[w->shift]) |
| 2543 | ); |
| 2544 | break; |
| 2545 | } |
| 2546 | return 0; |
| 2547 | } |
| 2548 | |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2549 | /* called under codec_resource_lock acquisition */ |
| 2550 | static int __tapan_codec_enable_ldo_h(struct snd_soc_dapm_widget *w, |
| 2551 | struct snd_kcontrol *kcontrol, int event) |
| 2552 | { |
| 2553 | struct snd_soc_codec *codec = w->codec; |
| 2554 | struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec); |
| 2555 | |
| 2556 | pr_debug("%s: enter\n", __func__); |
| 2557 | switch (event) { |
| 2558 | case SND_SOC_DAPM_PRE_PMU: |
| 2559 | /* |
| 2560 | * ldo_h_users is protected by codec->mutex, don't need |
| 2561 | * additional mutex |
| 2562 | */ |
| 2563 | if (++priv->ldo_h_users == 1) { |
| 2564 | WCD9XXX_BG_CLK_LOCK(&priv->resmgr); |
| 2565 | wcd9xxx_resmgr_get_bandgap(&priv->resmgr, |
| 2566 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 2567 | wcd9xxx_resmgr_get_clk_block(&priv->resmgr, |
| 2568 | WCD9XXX_CLK_RCO); |
| 2569 | snd_soc_update_bits(codec, TAPAN_A_LDO_H_MODE_1, 1 << 7, |
| 2570 | 1 << 7); |
| 2571 | wcd9xxx_resmgr_put_clk_block(&priv->resmgr, |
| 2572 | WCD9XXX_CLK_RCO); |
| 2573 | WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr); |
| 2574 | pr_debug("%s: ldo_h_users %d\n", __func__, |
| 2575 | priv->ldo_h_users); |
| 2576 | /* LDO enable requires 1ms to settle down */ |
| 2577 | usleep_range(1000, 1010); |
| 2578 | } |
| 2579 | break; |
| 2580 | case SND_SOC_DAPM_POST_PMD: |
| 2581 | if (--priv->ldo_h_users == 0) { |
| 2582 | WCD9XXX_BG_CLK_LOCK(&priv->resmgr); |
| 2583 | wcd9xxx_resmgr_get_clk_block(&priv->resmgr, |
| 2584 | WCD9XXX_CLK_RCO); |
| 2585 | snd_soc_update_bits(codec, TAPAN_A_LDO_H_MODE_1, 1 << 7, |
| 2586 | 0); |
| 2587 | wcd9xxx_resmgr_put_clk_block(&priv->resmgr, |
| 2588 | WCD9XXX_CLK_RCO); |
| 2589 | wcd9xxx_resmgr_put_bandgap(&priv->resmgr, |
| 2590 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 2591 | WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr); |
| 2592 | pr_debug("%s: ldo_h_users %d\n", __func__, |
| 2593 | priv->ldo_h_users); |
| 2594 | } |
| 2595 | WARN(priv->ldo_h_users < 0, "Unexpected ldo_h users %d\n", |
| 2596 | priv->ldo_h_users); |
| 2597 | break; |
| 2598 | } |
| 2599 | pr_debug("%s: leave\n", __func__); |
| 2600 | return 0; |
| 2601 | } |
| 2602 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2603 | static int tapan_codec_enable_ldo_h(struct snd_soc_dapm_widget *w, |
| 2604 | struct snd_kcontrol *kcontrol, int event) |
| 2605 | { |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 2606 | int rc; |
| 2607 | rc = __tapan_codec_enable_ldo_h(w, kcontrol, event); |
| 2608 | return rc; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | static int tapan_codec_enable_rx_bias(struct snd_soc_dapm_widget *w, |
| 2612 | struct snd_kcontrol *kcontrol, int event) |
| 2613 | { |
| 2614 | struct snd_soc_codec *codec = w->codec; |
| 2615 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 2616 | |
| 2617 | dev_dbg(codec->dev, "%s %d\n", __func__, event); |
| 2618 | |
| 2619 | switch (event) { |
| 2620 | case SND_SOC_DAPM_PRE_PMU: |
| 2621 | wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 1); |
| 2622 | break; |
| 2623 | case SND_SOC_DAPM_POST_PMD: |
| 2624 | wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 0); |
| 2625 | break; |
| 2626 | } |
| 2627 | return 0; |
| 2628 | } |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2629 | |
| 2630 | |
| 2631 | static int tapan_hphl_dac_event(struct snd_soc_dapm_widget *w, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2632 | struct snd_kcontrol *kcontrol, int event) |
| 2633 | { |
| 2634 | struct snd_soc_codec *codec = w->codec; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2635 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2636 | |
| 2637 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 2638 | |
| 2639 | switch (event) { |
| 2640 | case SND_SOC_DAPM_PRE_PMU: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2641 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, |
| 2642 | 0x02, 0x02); |
| 2643 | wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d, |
| 2644 | WCD9XXX_CLSH_STATE_HPHL, |
| 2645 | WCD9XXX_CLSH_REQ_ENABLE, |
| 2646 | WCD9XXX_CLSH_EVENT_PRE_DAC); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2647 | break; |
| 2648 | case SND_SOC_DAPM_POST_PMD: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2649 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, |
| 2650 | 0x02, 0x00); |
| 2651 | } |
| 2652 | return 0; |
| 2653 | } |
| 2654 | |
| 2655 | static int tapan_hphr_dac_event(struct snd_soc_dapm_widget *w, |
| 2656 | struct snd_kcontrol *kcontrol, int event) |
| 2657 | { |
| 2658 | struct snd_soc_codec *codec = w->codec; |
| 2659 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
| 2660 | |
| 2661 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 2662 | |
| 2663 | switch (event) { |
| 2664 | case SND_SOC_DAPM_PRE_PMU: |
| 2665 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, |
| 2666 | 0x04, 0x04); |
| 2667 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 2668 | wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d, |
| 2669 | WCD9XXX_CLSH_STATE_HPHR, |
| 2670 | WCD9XXX_CLSH_REQ_ENABLE, |
| 2671 | WCD9XXX_CLSH_EVENT_PRE_DAC); |
| 2672 | break; |
| 2673 | case SND_SOC_DAPM_POST_PMD: |
| 2674 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, |
| 2675 | 0x04, 0x00); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2676 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 2677 | break; |
| 2678 | } |
| 2679 | return 0; |
| 2680 | } |
| 2681 | |
| 2682 | static int tapan_hph_pa_event(struct snd_soc_dapm_widget *w, |
| 2683 | struct snd_kcontrol *kcontrol, int event) |
| 2684 | { |
| 2685 | struct snd_soc_codec *codec = w->codec; |
| 2686 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 2687 | enum wcd9xxx_notify_event e_pre_on, e_post_off; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2688 | u8 req_clsh_state; |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 2689 | u32 pa_settle_time = TAPAN_HPH_PA_SETTLE_COMP_OFF; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2690 | |
| 2691 | dev_dbg(codec->dev, "%s: %s event = %d\n", __func__, w->name, event); |
| 2692 | if (w->shift == 5) { |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2693 | e_pre_on = WCD9XXX_EVENT_PRE_HPHL_PA_ON; |
| 2694 | e_post_off = WCD9XXX_EVENT_POST_HPHL_PA_OFF; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2695 | req_clsh_state = WCD9XXX_CLSH_STATE_HPHR; |
Phani Kumar Uppalapati | eca9a10 | 2013-06-18 11:02:38 -0700 | [diff] [blame] | 2696 | } else if (w->shift == 4) { |
| 2697 | e_pre_on = WCD9XXX_EVENT_PRE_HPHR_PA_ON; |
| 2698 | e_post_off = WCD9XXX_EVENT_POST_HPHR_PA_OFF; |
| 2699 | req_clsh_state = WCD9XXX_CLSH_STATE_HPHL; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2700 | } else { |
| 2701 | pr_err("%s: Invalid w->shift %d\n", __func__, w->shift); |
| 2702 | return -EINVAL; |
| 2703 | } |
| 2704 | |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 2705 | if (tapan->comp_enabled[COMPANDER_1]) |
| 2706 | pa_settle_time = TAPAN_HPH_PA_SETTLE_COMP_ON; |
| 2707 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2708 | switch (event) { |
| 2709 | case SND_SOC_DAPM_PRE_PMU: |
| 2710 | /* Let MBHC module know PA is turning on */ |
| 2711 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_pre_on); |
| 2712 | break; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2713 | case SND_SOC_DAPM_POST_PMU: |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 2714 | dev_dbg(codec->dev, "%s: sleep %d ms after %s PA enable.\n", |
| 2715 | __func__, pa_settle_time / 1000, w->name); |
| 2716 | /* Time needed for PA to settle */ |
| 2717 | usleep_range(pa_settle_time, pa_settle_time + 1000); |
| 2718 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2719 | wcd9xxx_clsh_fsm(codec, &tapan->clsh_d, |
| 2720 | req_clsh_state, |
| 2721 | WCD9XXX_CLSH_REQ_ENABLE, |
| 2722 | WCD9XXX_CLSH_EVENT_POST_PA); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2723 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2724 | break; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2725 | case SND_SOC_DAPM_POST_PMD: |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 2726 | dev_dbg(codec->dev, "%s: sleep %d ms after %s PA disable.\n", |
| 2727 | __func__, pa_settle_time / 1000, w->name); |
| 2728 | /* Time needed for PA to settle */ |
| 2729 | usleep_range(pa_settle_time, pa_settle_time + 1000); |
| 2730 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2731 | /* Let MBHC module know PA turned off */ |
| 2732 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_off); |
| 2733 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2734 | wcd9xxx_clsh_fsm(codec, &tapan->clsh_d, |
| 2735 | req_clsh_state, |
| 2736 | WCD9XXX_CLSH_REQ_DISABLE, |
| 2737 | WCD9XXX_CLSH_EVENT_POST_PA); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2738 | break; |
| 2739 | } |
| 2740 | return 0; |
| 2741 | } |
| 2742 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2743 | static int tapan_codec_enable_anc_hph(struct snd_soc_dapm_widget *w, |
| 2744 | struct snd_kcontrol *kcontrol, int event) |
| 2745 | { |
| 2746 | struct snd_soc_codec *codec = w->codec; |
| 2747 | int ret = 0; |
| 2748 | |
| 2749 | switch (event) { |
| 2750 | case SND_SOC_DAPM_PRE_PMU: |
| 2751 | ret = tapan_hph_pa_event(w, kcontrol, event); |
| 2752 | if (w->shift == 4) { |
| 2753 | ret |= tapan_codec_enable_anc(w, kcontrol, event); |
| 2754 | msleep(50); |
| 2755 | } |
| 2756 | break; |
| 2757 | case SND_SOC_DAPM_POST_PMU: |
| 2758 | if (w->shift == 4) { |
| 2759 | snd_soc_update_bits(codec, |
| 2760 | TAPAN_A_RX_HPH_CNP_EN, 0x30, 0x30); |
| 2761 | msleep(30); |
| 2762 | } |
| 2763 | ret = tapan_hph_pa_event(w, kcontrol, event); |
| 2764 | break; |
| 2765 | case SND_SOC_DAPM_PRE_PMD: |
| 2766 | if (w->shift == 5) { |
| 2767 | snd_soc_update_bits(codec, |
| 2768 | TAPAN_A_RX_HPH_CNP_EN, 0x30, 0x00); |
| 2769 | msleep(40); |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2770 | snd_soc_update_bits(codec, |
| 2771 | TAPAN_A_TX_7_MBHC_EN, 0x80, 00); |
| 2772 | ret |= tapan_codec_enable_anc(w, kcontrol, event); |
| 2773 | } |
Damir Didjusto | 1ede84a | 2013-05-23 16:38:11 -0700 | [diff] [blame] | 2774 | break; |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2775 | case SND_SOC_DAPM_POST_PMD: |
| 2776 | ret = tapan_hph_pa_event(w, kcontrol, event); |
| 2777 | break; |
| 2778 | } |
| 2779 | return ret; |
| 2780 | } |
| 2781 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2782 | static const struct snd_soc_dapm_widget tapan_dapm_i2s_widgets[] = { |
| 2783 | SND_SOC_DAPM_SUPPLY("I2S_CLK", TAPAN_A_CDC_CLK_I2S_CTL, |
| 2784 | 4, 0, NULL, 0), |
| 2785 | }; |
| 2786 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2787 | static int tapan_lineout_dac_event(struct snd_soc_dapm_widget *w, |
| 2788 | struct snd_kcontrol *kcontrol, int event) |
| 2789 | { |
| 2790 | struct snd_soc_codec *codec = w->codec; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2791 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2792 | |
| 2793 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 2794 | |
| 2795 | switch (event) { |
| 2796 | case SND_SOC_DAPM_PRE_PMU: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2797 | wcd9xxx_clsh_fsm(codec, &tapan->clsh_d, |
| 2798 | WCD9XXX_CLSH_STATE_LO, |
| 2799 | WCD9XXX_CLSH_REQ_ENABLE, |
| 2800 | WCD9XXX_CLSH_EVENT_PRE_DAC); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2801 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 2802 | break; |
| 2803 | |
| 2804 | case SND_SOC_DAPM_POST_PMD: |
| 2805 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 2806 | break; |
| 2807 | } |
| 2808 | return 0; |
| 2809 | } |
| 2810 | |
| 2811 | static int tapan_spk_dac_event(struct snd_soc_dapm_widget *w, |
| 2812 | struct snd_kcontrol *kcontrol, int event) |
| 2813 | { |
| 2814 | struct snd_soc_codec *codec = w->codec; |
| 2815 | |
| 2816 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 2817 | return 0; |
| 2818 | } |
| 2819 | |
| 2820 | static const struct snd_soc_dapm_route audio_i2s_map[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2821 | {"I2S_CLK", NULL, "CDC_CONN"}, |
| 2822 | {"SLIM RX1", NULL, "I2S_CLK"}, |
| 2823 | {"SLIM RX2", NULL, "I2S_CLK"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2824 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2825 | {"SLIM TX1 MUX", NULL, "I2S_CLK"}, |
| 2826 | {"SLIM TX2 MUX", NULL, "I2S_CLK"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2827 | }; |
| 2828 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 2829 | static const struct snd_soc_dapm_route wcd9306_map[] = { |
| 2830 | {"SLIM TX1 MUX", "RMIX4", "RX4 MIX1"}, |
| 2831 | {"SLIM TX2 MUX", "RMIX4", "RX4 MIX1"}, |
| 2832 | {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"}, |
| 2833 | {"SLIM TX4 MUX", "RMIX4", "RX4 MIX1"}, |
| 2834 | {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2835 | {"SLIM TX1 MUX", "DEC3", "DEC3 MUX"}, |
| 2836 | {"SLIM TX1 MUX", "DEC4", "DEC4 MUX"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2837 | {"SLIM TX2 MUX", "DEC3", "DEC3 MUX"}, |
| 2838 | {"SLIM TX2 MUX", "DEC4", "DEC4 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2839 | {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2840 | {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2841 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2842 | {"ANC EAR", NULL, "ANC EAR PA"}, |
| 2843 | {"ANC EAR PA", NULL, "EAR_PA_MIXER"}, |
| 2844 | {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"}, |
| 2845 | {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"}, |
| 2846 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2847 | {"ANC HEADPHONE", NULL, "ANC HPHL"}, |
| 2848 | {"ANC HEADPHONE", NULL, "ANC HPHR"}, |
| 2849 | |
| 2850 | {"ANC HPHL", NULL, "HPHL_PA_MIXER"}, |
| 2851 | {"ANC HPHR", NULL, "HPHR_PA_MIXER"}, |
| 2852 | |
| 2853 | {"ANC1 MUX", "ADC1", "ADC1"}, |
| 2854 | {"ANC1 MUX", "ADC2", "ADC2"}, |
| 2855 | {"ANC1 MUX", "ADC3", "ADC3"}, |
| 2856 | {"ANC1 MUX", "ADC4", "ADC4"}, |
| 2857 | {"ANC1 MUX", "ADC5", "ADC5"}, |
| 2858 | {"ANC1 MUX", "DMIC1", "DMIC1"}, |
| 2859 | {"ANC1 MUX", "DMIC2", "DMIC2"}, |
| 2860 | {"ANC1 MUX", "DMIC3", "DMIC3"}, |
| 2861 | {"ANC1 MUX", "DMIC4", "DMIC4"}, |
| 2862 | {"ANC2 MUX", "ADC1", "ADC1"}, |
| 2863 | {"ANC2 MUX", "ADC2", "ADC2"}, |
| 2864 | {"ANC2 MUX", "ADC3", "ADC3"}, |
| 2865 | {"ANC2 MUX", "ADC4", "ADC4"}, |
| 2866 | {"ANC2 MUX", "ADC5", "ADC5"}, |
| 2867 | {"ANC2 MUX", "DMIC1", "DMIC1"}, |
| 2868 | {"ANC2 MUX", "DMIC2", "DMIC2"}, |
| 2869 | {"ANC2 MUX", "DMIC3", "DMIC3"}, |
| 2870 | {"ANC2 MUX", "DMIC4", "DMIC4"}, |
| 2871 | |
| 2872 | {"ANC HPHR", NULL, "CDC_CONN"}, |
| 2873 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 2874 | {"RDAC5 MUX", "DEM4", "RX4 MIX2"}, |
| 2875 | {"SPK DAC", "Switch", "RX4 MIX2"}, |
| 2876 | |
| 2877 | {"RX1 MIX2", NULL, "ANC1 MUX"}, |
| 2878 | {"RX2 MIX2", NULL, "ANC2 MUX"}, |
| 2879 | |
| 2880 | {"RX1 MIX1", NULL, "COMP1_CLK"}, |
| 2881 | {"RX2 MIX1", NULL, "COMP1_CLK"}, |
| 2882 | {"RX3 MIX1", NULL, "COMP2_CLK"}, |
| 2883 | {"RX4 MIX1", NULL, "COMP0_CLK"}, |
| 2884 | |
| 2885 | {"RX4 MIX1", NULL, "RX4 MIX1 INP1"}, |
| 2886 | {"RX4 MIX1", NULL, "RX4 MIX1 INP2"}, |
| 2887 | {"RX4 MIX2", NULL, "RX4 MIX1"}, |
| 2888 | {"RX4 MIX2", NULL, "RX4 MIX2 INP1"}, |
| 2889 | {"RX4 MIX2", NULL, "RX4 MIX2 INP2"}, |
| 2890 | |
| 2891 | {"RX4 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 2892 | {"RX4 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 2893 | {"RX4 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 2894 | {"RX4 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 2895 | {"RX4 MIX1 INP1", "RX5", "SLIM RX5"}, |
| 2896 | {"RX4 MIX1 INP1", "IIR1", "IIR1"}, |
| 2897 | {"RX4 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 2898 | {"RX4 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 2899 | {"RX4 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 2900 | {"RX4 MIX1 INP2", "RX5", "SLIM RX5"}, |
| 2901 | {"RX4 MIX1 INP2", "RX4", "SLIM RX4"}, |
| 2902 | {"RX4 MIX1 INP2", "IIR1", "IIR1"}, |
| 2903 | {"RX4 MIX2 INP1", "IIR1", "IIR1"}, |
| 2904 | {"RX4 MIX2 INP2", "IIR1", "IIR1"}, |
| 2905 | |
| 2906 | {"DEC1 MUX", "DMIC3", "DMIC3"}, |
| 2907 | {"DEC1 MUX", "DMIC4", "DMIC4"}, |
| 2908 | {"DEC2 MUX", "DMIC3", "DMIC3"}, |
| 2909 | {"DEC2 MUX", "DMIC4", "DMIC4"}, |
| 2910 | |
| 2911 | {"DEC3 MUX", "ADC1", "ADC1"}, |
| 2912 | {"DEC3 MUX", "ADC2", "ADC2"}, |
| 2913 | {"DEC3 MUX", "ADC3", "ADC3"}, |
| 2914 | {"DEC3 MUX", "ADC4", "ADC4"}, |
| 2915 | {"DEC3 MUX", "ADC5", "ADC5"}, |
| 2916 | {"DEC3 MUX", "DMIC1", "DMIC1"}, |
| 2917 | {"DEC3 MUX", "DMIC2", "DMIC2"}, |
| 2918 | {"DEC3 MUX", "DMIC3", "DMIC3"}, |
| 2919 | {"DEC3 MUX", "DMIC4", "DMIC4"}, |
| 2920 | {"DEC3 MUX", NULL, "CDC_CONN"}, |
| 2921 | |
| 2922 | {"DEC4 MUX", "ADC1", "ADC1"}, |
| 2923 | {"DEC4 MUX", "ADC2", "ADC2"}, |
| 2924 | {"DEC4 MUX", "ADC3", "ADC3"}, |
| 2925 | {"DEC4 MUX", "ADC4", "ADC4"}, |
| 2926 | {"DEC4 MUX", "ADC5", "ADC5"}, |
| 2927 | {"DEC4 MUX", "DMIC1", "DMIC1"}, |
| 2928 | {"DEC4 MUX", "DMIC2", "DMIC2"}, |
| 2929 | {"DEC4 MUX", "DMIC3", "DMIC3"}, |
| 2930 | {"DEC4 MUX", "DMIC4", "DMIC4"}, |
| 2931 | {"DEC4 MUX", NULL, "CDC_CONN"}, |
| 2932 | |
| 2933 | {"ADC5", NULL, "AMIC5"}, |
| 2934 | |
| 2935 | {"AUX_PGA_Left", NULL, "AMIC5"}, |
| 2936 | |
| 2937 | {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"}, |
| 2938 | {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"}, |
| 2939 | |
| 2940 | {"MIC BIAS3 Internal1", NULL, "LDO_H"}, |
| 2941 | {"MIC BIAS3 Internal2", NULL, "LDO_H"}, |
| 2942 | {"MIC BIAS3 External", NULL, "LDO_H"}, |
| 2943 | }; |
| 2944 | |
| 2945 | static const struct snd_soc_dapm_route audio_map[] = { |
| 2946 | /* SLIMBUS Connections */ |
| 2947 | {"AIF1 CAP", NULL, "AIF1_CAP Mixer"}, |
| 2948 | {"AIF2 CAP", NULL, "AIF2_CAP Mixer"}, |
| 2949 | {"AIF3 CAP", NULL, "AIF3_CAP Mixer"}, |
| 2950 | |
| 2951 | /* SLIM_MIXER("AIF1_CAP Mixer"),*/ |
| 2952 | {"AIF1_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 2953 | {"AIF1_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 2954 | {"AIF1_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 2955 | {"AIF1_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 2956 | {"AIF1_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
| 2957 | /* SLIM_MIXER("AIF2_CAP Mixer"),*/ |
| 2958 | {"AIF2_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 2959 | {"AIF2_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 2960 | {"AIF2_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 2961 | {"AIF2_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 2962 | {"AIF2_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
| 2963 | /* SLIM_MIXER("AIF3_CAP Mixer"),*/ |
| 2964 | {"AIF3_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 2965 | {"AIF3_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 2966 | {"AIF3_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 2967 | {"AIF3_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 2968 | {"AIF3_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
| 2969 | |
| 2970 | {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"}, |
| 2971 | {"SLIM TX1 MUX", "DEC2", "DEC2 MUX"}, |
| 2972 | {"SLIM TX1 MUX", "RMIX1", "RX1 MIX1"}, |
| 2973 | {"SLIM TX1 MUX", "RMIX2", "RX2 MIX1"}, |
| 2974 | {"SLIM TX1 MUX", "RMIX3", "RX3 MIX1"}, |
| 2975 | |
| 2976 | {"SLIM TX2 MUX", "DEC1", "DEC1 MUX"}, |
| 2977 | {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"}, |
| 2978 | {"SLIM TX2 MUX", "RMIX1", "RX1 MIX1"}, |
| 2979 | {"SLIM TX2 MUX", "RMIX2", "RX2 MIX1"}, |
| 2980 | {"SLIM TX2 MUX", "RMIX3", "RX3 MIX1"}, |
| 2981 | |
| 2982 | {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"}, |
| 2983 | {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"}, |
| 2984 | {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"}, |
| 2985 | |
| 2986 | {"SLIM TX4 MUX", "RMIX1", "RX1 MIX1"}, |
| 2987 | {"SLIM TX4 MUX", "RMIX2", "RX2 MIX1"}, |
| 2988 | {"SLIM TX4 MUX", "RMIX3", "RX3 MIX1"}, |
| 2989 | |
| 2990 | {"SLIM TX5 MUX", "DEC1", "DEC1 MUX"}, |
| 2991 | {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"}, |
| 2992 | {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"}, |
| 2993 | {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"}, |
| 2994 | |
| 2995 | /* Earpiece (RX MIX1) */ |
| 2996 | {"EAR", NULL, "EAR PA"}, |
| 2997 | {"EAR PA", NULL, "EAR_PA_MIXER"}, |
| 2998 | {"EAR_PA_MIXER", NULL, "DAC1"}, |
| 2999 | {"DAC1", NULL, "RX_BIAS"}, |
| 3000 | {"DAC1", NULL, "CDC_CP_VDD"}, |
| 3001 | |
| 3002 | |
| 3003 | /* Headset (RX MIX1 and RX MIX2) */ |
| 3004 | {"HEADPHONE", NULL, "HPHL"}, |
| 3005 | {"HEADPHONE", NULL, "HPHR"}, |
| 3006 | |
| 3007 | {"HPHL", NULL, "HPHL_PA_MIXER"}, |
| 3008 | {"HPHL_PA_MIXER", NULL, "HPHL DAC"}, |
| 3009 | {"HPHL DAC", NULL, "RX_BIAS"}, |
| 3010 | {"HPHL DAC", NULL, "CDC_CP_VDD"}, |
| 3011 | |
| 3012 | {"HPHR", NULL, "HPHR_PA_MIXER"}, |
| 3013 | {"HPHR_PA_MIXER", NULL, "HPHR DAC"}, |
| 3014 | {"HPHR DAC", NULL, "RX_BIAS"}, |
| 3015 | {"HPHR DAC", NULL, "CDC_CP_VDD"}, |
| 3016 | |
| 3017 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3018 | {"DAC1", "Switch", "CLASS_H_DSM MUX"}, |
| 3019 | {"HPHL DAC", "Switch", "CLASS_H_DSM MUX"}, |
Bhalchandra Gajare | 363f3f5 | 2013-10-08 18:43:22 -0700 | [diff] [blame] | 3020 | {"HPHR DAC", NULL, "RDAC3 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3021 | |
| 3022 | {"LINEOUT1", NULL, "LINEOUT1 PA"}, |
| 3023 | {"LINEOUT2", NULL, "LINEOUT2 PA"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3024 | {"SPK_OUT", NULL, "SPK PA"}, |
| 3025 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3026 | {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"}, |
| 3027 | {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3028 | {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"}, |
| 3029 | {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"}, |
| 3030 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3031 | |
| 3032 | {"RDAC5 MUX", "DEM3_INV", "RX3 MIX1"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3033 | {"LINEOUT2 DAC", NULL, "RDAC5 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3034 | |
Bhalchandra Gajare | 363f3f5 | 2013-10-08 18:43:22 -0700 | [diff] [blame] | 3035 | {"RDAC4 MUX", "DEM3", "RX3 MIX1"}, |
| 3036 | {"RDAC4 MUX", "DEM2", "RX2 CHAIN"}, |
| 3037 | {"LINEOUT1 DAC", NULL, "RDAC4 MUX"}, |
| 3038 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3039 | {"SPK PA", NULL, "SPK DAC"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3040 | {"SPK DAC", NULL, "VDD_SPKDRV"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3041 | |
| 3042 | {"RX1 CHAIN", NULL, "RX1 MIX2"}, |
| 3043 | {"RX2 CHAIN", NULL, "RX2 MIX2"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3044 | {"CLASS_H_DSM MUX", "RX_HPHL", "RX1 CHAIN"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3045 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3046 | {"LINEOUT1 DAC", NULL, "RX_BIAS"}, |
| 3047 | {"LINEOUT2 DAC", NULL, "RX_BIAS"}, |
Bhalchandra Gajare | 5b4199c | 2013-07-03 14:35:43 -0700 | [diff] [blame] | 3048 | {"LINEOUT1 DAC", NULL, "CDC_CP_VDD"}, |
| 3049 | {"LINEOUT2 DAC", NULL, "CDC_CP_VDD"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3050 | |
Bhalchandra Gajare | 363f3f5 | 2013-10-08 18:43:22 -0700 | [diff] [blame] | 3051 | {"RDAC3 MUX", "DEM2", "RX2 CHAIN"}, |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 3052 | {"RDAC3 MUX", "DEM1", "RX1 CHAIN"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3053 | |
| 3054 | {"RX1 MIX1", NULL, "RX1 MIX1 INP1"}, |
| 3055 | {"RX1 MIX1", NULL, "RX1 MIX1 INP2"}, |
| 3056 | {"RX1 MIX1", NULL, "RX1 MIX1 INP3"}, |
| 3057 | {"RX2 MIX1", NULL, "RX2 MIX1 INP1"}, |
| 3058 | {"RX2 MIX1", NULL, "RX2 MIX1 INP2"}, |
| 3059 | {"RX3 MIX1", NULL, "RX3 MIX1 INP1"}, |
| 3060 | {"RX3 MIX1", NULL, "RX3 MIX1 INP2"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3061 | {"RX1 MIX2", NULL, "RX1 MIX1"}, |
| 3062 | {"RX1 MIX2", NULL, "RX1 MIX2 INP1"}, |
| 3063 | {"RX1 MIX2", NULL, "RX1 MIX2 INP2"}, |
| 3064 | {"RX2 MIX2", NULL, "RX2 MIX1"}, |
| 3065 | {"RX2 MIX2", NULL, "RX2 MIX2 INP1"}, |
| 3066 | {"RX2 MIX2", NULL, "RX2 MIX2 INP2"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3067 | |
| 3068 | /* SLIM_MUX("AIF1_PB", "AIF1 PB"),*/ |
| 3069 | {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3070 | {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3071 | {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3072 | {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3073 | {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3074 | /* SLIM_MUX("AIF2_PB", "AIF2 PB"),*/ |
| 3075 | {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3076 | {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3077 | {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3078 | {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3079 | {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3080 | /* SLIM_MUX("AIF3_PB", "AIF3 PB"),*/ |
| 3081 | {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3082 | {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3083 | {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3084 | {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3085 | {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3086 | |
| 3087 | {"SLIM RX1", NULL, "SLIM RX1 MUX"}, |
| 3088 | {"SLIM RX2", NULL, "SLIM RX2 MUX"}, |
| 3089 | {"SLIM RX3", NULL, "SLIM RX3 MUX"}, |
| 3090 | {"SLIM RX4", NULL, "SLIM RX4 MUX"}, |
| 3091 | {"SLIM RX5", NULL, "SLIM RX5 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3092 | |
| 3093 | {"RX1 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3094 | {"RX1 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 3095 | {"RX1 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3096 | {"RX1 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 3097 | {"RX1 MIX1 INP1", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3098 | {"RX1 MIX1 INP1", "IIR1", "IIR1"}, |
| 3099 | {"RX1 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3100 | {"RX1 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 3101 | {"RX1 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3102 | {"RX1 MIX1 INP2", "RX4", "SLIM RX4"}, |
| 3103 | {"RX1 MIX1 INP2", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3104 | {"RX1 MIX1 INP2", "IIR1", "IIR1"}, |
| 3105 | {"RX1 MIX1 INP3", "RX1", "SLIM RX1"}, |
| 3106 | {"RX1 MIX1 INP3", "RX2", "SLIM RX2"}, |
| 3107 | {"RX1 MIX1 INP3", "RX3", "SLIM RX3"}, |
| 3108 | {"RX1 MIX1 INP3", "RX4", "SLIM RX4"}, |
| 3109 | {"RX1 MIX1 INP3", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3110 | {"RX2 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3111 | {"RX2 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 3112 | {"RX2 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3113 | {"RX2 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 3114 | {"RX2 MIX1 INP1", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3115 | {"RX2 MIX1 INP1", "IIR1", "IIR1"}, |
| 3116 | {"RX2 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3117 | {"RX2 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 3118 | {"RX2 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3119 | {"RX2 MIX1 INP2", "RX4", "SLIM RX4"}, |
| 3120 | {"RX2 MIX1 INP2", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3121 | {"RX2 MIX1 INP2", "IIR1", "IIR1"}, |
| 3122 | {"RX3 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3123 | {"RX3 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 3124 | {"RX3 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3125 | {"RX3 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 3126 | {"RX3 MIX1 INP1", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3127 | {"RX3 MIX1 INP1", "IIR1", "IIR1"}, |
| 3128 | {"RX3 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3129 | {"RX3 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 3130 | {"RX3 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3131 | {"RX3 MIX1 INP2", "RX4", "SLIM RX4"}, |
| 3132 | {"RX3 MIX1 INP2", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3133 | {"RX3 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3134 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3135 | {"RX1 MIX2 INP1", "IIR1", "IIR1"}, |
| 3136 | {"RX1 MIX2 INP2", "IIR1", "IIR1"}, |
| 3137 | {"RX2 MIX2 INP1", "IIR1", "IIR1"}, |
| 3138 | {"RX2 MIX2 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3139 | |
| 3140 | /* Decimator Inputs */ |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3141 | {"DEC1 MUX", "ADC1", "ADC1"}, |
| 3142 | {"DEC1 MUX", "ADC2", "ADC2"}, |
| 3143 | {"DEC1 MUX", "ADC3", "ADC3"}, |
| 3144 | {"DEC1 MUX", "ADC4", "ADC4"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3145 | {"DEC1 MUX", "DMIC1", "DMIC1"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3146 | {"DEC1 MUX", "DMIC2", "DMIC2"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3147 | {"DEC1 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3148 | |
| 3149 | {"DEC2 MUX", "ADC1", "ADC1"}, |
| 3150 | {"DEC2 MUX", "ADC2", "ADC2"}, |
| 3151 | {"DEC2 MUX", "ADC3", "ADC3"}, |
| 3152 | {"DEC2 MUX", "ADC4", "ADC4"}, |
| 3153 | {"DEC2 MUX", "DMIC1", "DMIC1"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3154 | {"DEC2 MUX", "DMIC2", "DMIC2"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3155 | {"DEC2 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3156 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3157 | /* ADC Connections */ |
| 3158 | {"ADC1", NULL, "AMIC1"}, |
| 3159 | {"ADC2", NULL, "AMIC2"}, |
| 3160 | {"ADC3", NULL, "AMIC3"}, |
| 3161 | {"ADC4", NULL, "AMIC4"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3162 | |
| 3163 | /* AUX PGA Connections */ |
| 3164 | {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3165 | {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3166 | {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3167 | {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3168 | {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3169 | |
| 3170 | {"IIR1", NULL, "IIR1 INP1 MUX"}, |
| 3171 | {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"}, |
| 3172 | {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3173 | |
| 3174 | {"MIC BIAS1 Internal1", NULL, "LDO_H"}, |
| 3175 | {"MIC BIAS1 Internal2", NULL, "LDO_H"}, |
| 3176 | {"MIC BIAS1 External", NULL, "LDO_H"}, |
| 3177 | {"MIC BIAS2 Internal1", NULL, "LDO_H"}, |
| 3178 | {"MIC BIAS2 Internal2", NULL, "LDO_H"}, |
| 3179 | {"MIC BIAS2 Internal3", NULL, "LDO_H"}, |
| 3180 | {"MIC BIAS2 External", NULL, "LDO_H"}, |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 3181 | {DAPM_MICBIAS2_EXTERNAL_STANDALONE, NULL, "LDO_H Standalone"}, |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 3182 | }; |
| 3183 | |
| 3184 | static const struct snd_soc_dapm_route wcd9302_map[] = { |
| 3185 | {"SPK DAC", "Switch", "RX3 MIX1"}, |
| 3186 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 3187 | |
| 3188 | {"RDAC5 MUX", "DEM4", "RX3 MIX1"}, |
| 3189 | {"RDAC5 MUX", "DEM3_INV", "RDAC4 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3190 | }; |
| 3191 | |
| 3192 | static int tapan_readable(struct snd_soc_codec *ssc, unsigned int reg) |
| 3193 | { |
| 3194 | return tapan_reg_readable[reg]; |
| 3195 | } |
| 3196 | |
| 3197 | static bool tapan_is_digital_gain_register(unsigned int reg) |
| 3198 | { |
| 3199 | bool rtn = false; |
| 3200 | switch (reg) { |
| 3201 | case TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL: |
| 3202 | case TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL: |
| 3203 | case TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL: |
| 3204 | case TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL: |
| 3205 | case TAPAN_A_CDC_TX1_VOL_CTL_GAIN: |
| 3206 | case TAPAN_A_CDC_TX2_VOL_CTL_GAIN: |
| 3207 | case TAPAN_A_CDC_TX3_VOL_CTL_GAIN: |
| 3208 | case TAPAN_A_CDC_TX4_VOL_CTL_GAIN: |
| 3209 | rtn = true; |
| 3210 | break; |
| 3211 | default: |
| 3212 | break; |
| 3213 | } |
| 3214 | return rtn; |
| 3215 | } |
| 3216 | |
| 3217 | static int tapan_volatile(struct snd_soc_codec *ssc, unsigned int reg) |
| 3218 | { |
Damir Didjusto | d6aea99 | 2013-09-03 21:18:59 -0700 | [diff] [blame] | 3219 | |
| 3220 | int i = 0; |
| 3221 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3222 | /* Registers lower than 0x100 are top level registers which can be |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3223 | * written by the Tapan core driver. |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3224 | */ |
| 3225 | |
| 3226 | if ((reg >= TAPAN_A_CDC_MBHC_EN_CTL) || (reg < 0x100)) |
| 3227 | return 1; |
| 3228 | |
| 3229 | /* IIR Coeff registers are not cacheable */ |
| 3230 | if ((reg >= TAPAN_A_CDC_IIR1_COEF_B1_CTL) && |
| 3231 | (reg <= TAPAN_A_CDC_IIR2_COEF_B2_CTL)) |
| 3232 | return 1; |
| 3233 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 3234 | /* ANC filter registers are not cacheable */ |
| 3235 | if ((reg >= TAPAN_A_CDC_ANC1_IIR_B1_CTL) && |
| 3236 | (reg <= TAPAN_A_CDC_ANC1_LPF_B2_CTL)) |
| 3237 | return 1; |
| 3238 | if ((reg >= TAPAN_A_CDC_ANC2_IIR_B1_CTL) && |
| 3239 | (reg <= TAPAN_A_CDC_ANC2_LPF_B2_CTL)) |
| 3240 | return 1; |
| 3241 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3242 | /* Digital gain register is not cacheable so we have to write |
| 3243 | * the setting even it is the same |
| 3244 | */ |
| 3245 | if (tapan_is_digital_gain_register(reg)) |
| 3246 | return 1; |
| 3247 | |
| 3248 | /* HPH status registers */ |
| 3249 | if (reg == TAPAN_A_RX_HPH_L_STATUS || reg == TAPAN_A_RX_HPH_R_STATUS) |
| 3250 | return 1; |
| 3251 | |
| 3252 | if (reg == TAPAN_A_MBHC_INSERT_DET_STATUS) |
| 3253 | return 1; |
| 3254 | |
Damir Didjusto | d6aea99 | 2013-09-03 21:18:59 -0700 | [diff] [blame] | 3255 | for (i = 0; i < ARRAY_SIZE(audio_reg_cfg); i++) |
| 3256 | if (audio_reg_cfg[i].reg_logical_addr - |
| 3257 | TAPAN_REGISTER_START_OFFSET == reg) |
| 3258 | return 1; |
| 3259 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3260 | return 0; |
| 3261 | } |
| 3262 | |
| 3263 | #define TAPAN_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) |
Venkat Sudhir | bb44447 | 2014-01-14 10:03:23 -0800 | [diff] [blame] | 3264 | #define TAPAN_FORMATS_S16_S24_LE (SNDRV_PCM_FMTBIT_S16_LE | \ |
| 3265 | SNDRV_PCM_FORMAT_S24_LE) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3266 | static int tapan_write(struct snd_soc_codec *codec, unsigned int reg, |
| 3267 | unsigned int value) |
| 3268 | { |
| 3269 | int ret; |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 3270 | struct wcd9xxx *wcd9xxx = codec->control_data; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3271 | |
| 3272 | if (reg == SND_SOC_NOPM) |
| 3273 | return 0; |
| 3274 | |
| 3275 | BUG_ON(reg > TAPAN_MAX_REGISTER); |
| 3276 | |
| 3277 | if (!tapan_volatile(codec, reg)) { |
| 3278 | ret = snd_soc_cache_write(codec, reg, value); |
| 3279 | if (ret != 0) |
| 3280 | dev_err(codec->dev, "Cache write to %x failed: %d\n", |
| 3281 | reg, ret); |
| 3282 | } |
| 3283 | |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 3284 | return wcd9xxx_reg_write(&wcd9xxx->core_res, reg, value); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3285 | } |
| 3286 | static unsigned int tapan_read(struct snd_soc_codec *codec, |
| 3287 | unsigned int reg) |
| 3288 | { |
| 3289 | unsigned int val; |
| 3290 | int ret; |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 3291 | struct wcd9xxx *wcd9xxx = codec->control_data; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3292 | |
| 3293 | if (reg == SND_SOC_NOPM) |
| 3294 | return 0; |
| 3295 | |
| 3296 | BUG_ON(reg > TAPAN_MAX_REGISTER); |
| 3297 | |
| 3298 | if (!tapan_volatile(codec, reg) && tapan_readable(codec, reg) && |
| 3299 | reg < codec->driver->reg_cache_size) { |
| 3300 | ret = snd_soc_cache_read(codec, reg, &val); |
| 3301 | if (ret >= 0) { |
| 3302 | return val; |
| 3303 | } else |
| 3304 | dev_err(codec->dev, "Cache read from %x failed: %d\n", |
| 3305 | reg, ret); |
| 3306 | } |
| 3307 | |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 3308 | val = wcd9xxx_reg_read(&wcd9xxx->core_res, reg); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3309 | return val; |
| 3310 | } |
| 3311 | |
| 3312 | static int tapan_startup(struct snd_pcm_substream *substream, |
| 3313 | struct snd_soc_dai *dai) |
| 3314 | { |
| 3315 | struct wcd9xxx *tapan_core = dev_get_drvdata(dai->codec->dev->parent); |
| 3316 | dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n", |
| 3317 | __func__, substream->name, substream->stream); |
| 3318 | if ((tapan_core != NULL) && |
| 3319 | (tapan_core->dev != NULL) && |
| 3320 | (tapan_core->dev->parent != NULL)) |
| 3321 | pm_runtime_get_sync(tapan_core->dev->parent); |
| 3322 | |
| 3323 | return 0; |
| 3324 | } |
| 3325 | |
| 3326 | static void tapan_shutdown(struct snd_pcm_substream *substream, |
| 3327 | struct snd_soc_dai *dai) |
| 3328 | { |
| 3329 | struct wcd9xxx *tapan_core = dev_get_drvdata(dai->codec->dev->parent); |
Phani Kumar Uppalapati | e2a18e2 | 2013-10-24 14:32:54 -0700 | [diff] [blame] | 3330 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(dai->codec); |
| 3331 | u32 active = 0; |
| 3332 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3333 | dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n", |
| 3334 | __func__, substream->name, substream->stream); |
Phani Kumar Uppalapati | e2a18e2 | 2013-10-24 14:32:54 -0700 | [diff] [blame] | 3335 | |
Aravind Kumar | 320ef3a | 2014-03-21 12:32:34 +0530 | [diff] [blame] | 3336 | if (dai->id < NUM_CODEC_DAIS) { |
Phani Kumar Uppalapati | e2a18e2 | 2013-10-24 14:32:54 -0700 | [diff] [blame] | 3337 | if (tapan->dai[dai->id].ch_mask) { |
| 3338 | active = 1; |
| 3339 | dev_dbg(dai->codec->dev, "%s(): Codec DAI: chmask[%d] = 0x%lx\n", |
| 3340 | __func__, dai->id, |
| 3341 | tapan->dai[dai->id].ch_mask); |
| 3342 | } |
| 3343 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3344 | if ((tapan_core != NULL) && |
| 3345 | (tapan_core->dev != NULL) && |
Phani Kumar Uppalapati | e2a18e2 | 2013-10-24 14:32:54 -0700 | [diff] [blame] | 3346 | (tapan_core->dev->parent != NULL) && |
| 3347 | (active == 0)) { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3348 | pm_runtime_mark_last_busy(tapan_core->dev->parent); |
| 3349 | pm_runtime_put(tapan_core->dev->parent); |
Phani Kumar Uppalapati | e2a18e2 | 2013-10-24 14:32:54 -0700 | [diff] [blame] | 3350 | dev_dbg(dai->codec->dev, "%s: unvote requested", __func__); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3351 | } |
| 3352 | } |
| 3353 | |
Bhalchandra Gajare | 4e3dd85 | 2013-08-19 17:21:23 -0700 | [diff] [blame] | 3354 | static void tapan_set_vdd_cx_current(struct snd_soc_codec *codec, |
| 3355 | int current_uA) |
| 3356 | { |
| 3357 | struct regulator *cx_regulator; |
| 3358 | int ret; |
| 3359 | |
| 3360 | cx_regulator = tapan_codec_find_regulator(codec, |
| 3361 | "cdc-vdd-cx"); |
| 3362 | |
| 3363 | if (!cx_regulator) { |
| 3364 | dev_err(codec->dev, "%s: Regulator %s not defined\n", |
| 3365 | __func__, "cdc-vdd-cx-supply"); |
| 3366 | return; |
| 3367 | } |
| 3368 | |
| 3369 | ret = regulator_set_optimum_mode(cx_regulator, current_uA); |
| 3370 | if (ret < 0) |
| 3371 | dev_err(codec->dev, |
| 3372 | "%s: Failed to set vdd_cx current to %d\n", |
| 3373 | __func__, current_uA); |
| 3374 | } |
| 3375 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3376 | int tapan_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, bool dapm) |
| 3377 | { |
| 3378 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 3379 | |
| 3380 | dev_dbg(codec->dev, "%s: mclk_enable = %u, dapm = %d\n", __func__, |
| 3381 | mclk_enable, dapm); |
| 3382 | |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 3383 | WCD9XXX_BG_CLK_LOCK(&tapan->resmgr); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3384 | if (mclk_enable) { |
Bhalchandra Gajare | 4e3dd85 | 2013-08-19 17:21:23 -0700 | [diff] [blame] | 3385 | tapan_set_vdd_cx_current(codec, TAPAN_VDD_CX_OPTIMAL_UA); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3386 | wcd9xxx_resmgr_get_bandgap(&tapan->resmgr, |
| 3387 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 3388 | wcd9xxx_resmgr_get_clk_block(&tapan->resmgr, WCD9XXX_CLK_MCLK); |
| 3389 | } else { |
| 3390 | /* Put clock and BG */ |
| 3391 | wcd9xxx_resmgr_put_clk_block(&tapan->resmgr, WCD9XXX_CLK_MCLK); |
| 3392 | wcd9xxx_resmgr_put_bandgap(&tapan->resmgr, |
| 3393 | WCD9XXX_BANDGAP_AUDIO_MODE); |
Bhalchandra Gajare | 4e3dd85 | 2013-08-19 17:21:23 -0700 | [diff] [blame] | 3394 | /* Set the vdd cx power rail sleep mode current */ |
| 3395 | tapan_set_vdd_cx_current(codec, TAPAN_VDD_CX_SLEEP_UA); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3396 | } |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 3397 | WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3398 | |
| 3399 | return 0; |
| 3400 | } |
| 3401 | |
| 3402 | static int tapan_set_dai_sysclk(struct snd_soc_dai *dai, |
| 3403 | int clk_id, unsigned int freq, int dir) |
| 3404 | { |
| 3405 | dev_dbg(dai->codec->dev, "%s\n", __func__); |
| 3406 | return 0; |
| 3407 | } |
| 3408 | |
| 3409 | static int tapan_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 3410 | { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3411 | u8 val = 0; |
| 3412 | struct snd_soc_codec *codec = dai->codec; |
| 3413 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 3414 | |
| 3415 | dev_dbg(codec->dev, "%s\n", __func__); |
| 3416 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 3417 | case SND_SOC_DAIFMT_CBS_CFS: |
| 3418 | /* CPU is master */ |
| 3419 | if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 3420 | if (dai->id == AIF1_CAP) |
| 3421 | snd_soc_update_bits(codec, |
| 3422 | TAPAN_A_CDC_CLK_I2S_CTL, |
| 3423 | TAPAN_I2S_MASTER_MODE_MASK, 0); |
| 3424 | else if (dai->id == AIF1_PB) |
| 3425 | snd_soc_update_bits(codec, |
| 3426 | TAPAN_A_CDC_CLK_I2S_CTL, |
| 3427 | TAPAN_I2S_MASTER_MODE_MASK, 0); |
| 3428 | } |
| 3429 | break; |
| 3430 | case SND_SOC_DAIFMT_CBM_CFM: |
| 3431 | /* CPU is slave */ |
| 3432 | if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 3433 | val = TAPAN_I2S_MASTER_MODE_MASK; |
| 3434 | if (dai->id == AIF1_CAP) |
| 3435 | snd_soc_update_bits(codec, |
| 3436 | TAPAN_A_CDC_CLK_I2S_CTL, val, val); |
| 3437 | else if (dai->id == AIF1_PB) |
| 3438 | snd_soc_update_bits(codec, |
| 3439 | TAPAN_A_CDC_CLK_I2S_CTL, val, val); |
| 3440 | } |
| 3441 | break; |
| 3442 | default: |
| 3443 | return -EINVAL; |
| 3444 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3445 | return 0; |
| 3446 | } |
| 3447 | |
| 3448 | static int tapan_set_channel_map(struct snd_soc_dai *dai, |
| 3449 | unsigned int tx_num, unsigned int *tx_slot, |
| 3450 | unsigned int rx_num, unsigned int *rx_slot) |
| 3451 | |
| 3452 | { |
| 3453 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(dai->codec); |
| 3454 | struct wcd9xxx *core = dev_get_drvdata(dai->codec->dev->parent); |
Aravind Kumar | 320ef3a | 2014-03-21 12:32:34 +0530 | [diff] [blame] | 3455 | if (!tx_slot || !rx_slot) { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3456 | pr_err("%s: Invalid\n", __func__); |
| 3457 | return -EINVAL; |
| 3458 | } |
| 3459 | dev_dbg(dai->codec->dev, "%s(): dai_name = %s DAI-ID %x\n", |
| 3460 | __func__, dai->name, dai->id); |
| 3461 | dev_dbg(dai->codec->dev, "%s(): tx_ch %d rx_ch %d\n intf_type %d\n", |
| 3462 | __func__, tx_num, rx_num, tapan->intf_type); |
| 3463 | |
| 3464 | if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 3465 | wcd9xxx_init_slimslave(core, core->slim->laddr, |
| 3466 | tx_num, tx_slot, rx_num, rx_slot); |
| 3467 | return 0; |
| 3468 | } |
| 3469 | |
| 3470 | static int tapan_get_channel_map(struct snd_soc_dai *dai, |
| 3471 | unsigned int *tx_num, unsigned int *tx_slot, |
| 3472 | unsigned int *rx_num, unsigned int *rx_slot) |
| 3473 | |
| 3474 | { |
| 3475 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(dai->codec); |
| 3476 | u32 i = 0; |
| 3477 | struct wcd9xxx_ch *ch; |
| 3478 | |
| 3479 | switch (dai->id) { |
| 3480 | case AIF1_PB: |
| 3481 | case AIF2_PB: |
| 3482 | case AIF3_PB: |
| 3483 | if (!rx_slot || !rx_num) { |
| 3484 | pr_err("%s: Invalid rx_slot %d or rx_num %d\n", |
| 3485 | __func__, (u32) rx_slot, (u32) rx_num); |
| 3486 | return -EINVAL; |
| 3487 | } |
| 3488 | list_for_each_entry(ch, &tapan_p->dai[dai->id].wcd9xxx_ch_list, |
| 3489 | list) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3490 | dev_dbg(dai->codec->dev, "%s: rx_slot[%d] %d, ch->ch_num %d\n", |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3491 | __func__, i, rx_slot[i], ch->ch_num); |
| 3492 | rx_slot[i++] = ch->ch_num; |
| 3493 | } |
| 3494 | dev_dbg(dai->codec->dev, "%s: rx_num %d\n", __func__, i); |
| 3495 | *rx_num = i; |
| 3496 | break; |
| 3497 | case AIF1_CAP: |
| 3498 | case AIF2_CAP: |
| 3499 | case AIF3_CAP: |
| 3500 | if (!tx_slot || !tx_num) { |
| 3501 | pr_err("%s: Invalid tx_slot %d or tx_num %d\n", |
| 3502 | __func__, (u32) tx_slot, (u32) tx_num); |
| 3503 | return -EINVAL; |
| 3504 | } |
| 3505 | list_for_each_entry(ch, &tapan_p->dai[dai->id].wcd9xxx_ch_list, |
| 3506 | list) { |
| 3507 | dev_dbg(dai->codec->dev, "%s: tx_slot[%d] %d, ch->ch_num %d\n", |
| 3508 | __func__, i, tx_slot[i], ch->ch_num); |
| 3509 | tx_slot[i++] = ch->ch_num; |
| 3510 | } |
| 3511 | dev_dbg(dai->codec->dev, "%s: tx_num %d\n", __func__, i); |
| 3512 | *tx_num = i; |
| 3513 | break; |
| 3514 | |
| 3515 | default: |
| 3516 | pr_err("%s: Invalid DAI ID %x\n", __func__, dai->id); |
| 3517 | break; |
| 3518 | } |
| 3519 | |
| 3520 | return 0; |
| 3521 | } |
| 3522 | |
| 3523 | static int tapan_set_interpolator_rate(struct snd_soc_dai *dai, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3524 | u8 rx_fs_rate_reg_val, u32 compander_fs, u32 sample_rate) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3525 | { |
| 3526 | u32 j; |
| 3527 | u8 rx_mix1_inp; |
| 3528 | u16 rx_mix_1_reg_1, rx_mix_1_reg_2; |
| 3529 | u16 rx_fs_reg; |
| 3530 | u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val; |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 3531 | u8 rdac5_mux; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3532 | struct snd_soc_codec *codec = dai->codec; |
| 3533 | struct wcd9xxx_ch *ch; |
| 3534 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 3535 | |
| 3536 | list_for_each_entry(ch, &tapan->dai[dai->id].wcd9xxx_ch_list, list) { |
| 3537 | /* for RX port starting from 16 instead of 10 like tabla */ |
| 3538 | rx_mix1_inp = ch->port + RX_MIX1_INP_SEL_RX1 - |
| 3539 | TAPAN_TX_PORT_NUMBER; |
| 3540 | if ((rx_mix1_inp < RX_MIX1_INP_SEL_RX1) || |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3541 | (rx_mix1_inp > RX_MIX1_INP_SEL_RX5)) { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3542 | pr_err("%s: Invalid TAPAN_RX%u port. Dai ID is %d\n", |
| 3543 | __func__, rx_mix1_inp - 5 , dai->id); |
| 3544 | return -EINVAL; |
| 3545 | } |
| 3546 | |
| 3547 | rx_mix_1_reg_1 = TAPAN_A_CDC_CONN_RX1_B1_CTL; |
| 3548 | |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 3549 | rdac5_mux = snd_soc_read(codec, TAPAN_A_CDC_CONN_MISC); |
| 3550 | rdac5_mux = (rdac5_mux & 0x04) >> 2; |
| 3551 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3552 | for (j = 0; j < NUM_INTERPOLATORS; j++) { |
| 3553 | rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1; |
| 3554 | |
| 3555 | rx_mix_1_reg_1_val = snd_soc_read(codec, |
| 3556 | rx_mix_1_reg_1); |
| 3557 | rx_mix_1_reg_2_val = snd_soc_read(codec, |
| 3558 | rx_mix_1_reg_2); |
| 3559 | |
| 3560 | if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) || |
| 3561 | (((rx_mix_1_reg_1_val >> 4) & 0x0F) |
| 3562 | == rx_mix1_inp) || |
| 3563 | ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) { |
| 3564 | |
| 3565 | rx_fs_reg = TAPAN_A_CDC_RX1_B5_CTL + 8 * j; |
| 3566 | |
| 3567 | dev_dbg(codec->dev, "%s: AIF_PB DAI(%d) connected to RX%u\n", |
| 3568 | __func__, dai->id, j + 1); |
| 3569 | |
| 3570 | dev_dbg(codec->dev, "%s: set RX%u sample rate to %u\n", |
| 3571 | __func__, j + 1, sample_rate); |
| 3572 | |
| 3573 | snd_soc_update_bits(codec, rx_fs_reg, |
| 3574 | 0xE0, rx_fs_rate_reg_val); |
| 3575 | |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 3576 | if (comp_rx_path[j] < COMPANDER_MAX) { |
| 3577 | if ((j == 3) && (rdac5_mux == 1)) |
| 3578 | tapan->comp_fs[COMPANDER_0] = |
| 3579 | compander_fs; |
| 3580 | else |
| 3581 | tapan->comp_fs[comp_rx_path[j]] |
| 3582 | = compander_fs; |
| 3583 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3584 | } |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 3585 | if (j <= 1) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3586 | rx_mix_1_reg_1 += 3; |
| 3587 | else |
| 3588 | rx_mix_1_reg_1 += 2; |
| 3589 | } |
| 3590 | } |
| 3591 | return 0; |
| 3592 | } |
| 3593 | |
| 3594 | static int tapan_set_decimator_rate(struct snd_soc_dai *dai, |
| 3595 | u8 tx_fs_rate_reg_val, u32 sample_rate) |
| 3596 | { |
| 3597 | struct snd_soc_codec *codec = dai->codec; |
| 3598 | struct wcd9xxx_ch *ch; |
| 3599 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 3600 | u32 tx_port; |
| 3601 | u16 tx_port_reg, tx_fs_reg; |
| 3602 | u8 tx_port_reg_val; |
| 3603 | s8 decimator; |
| 3604 | |
| 3605 | list_for_each_entry(ch, &tapan->dai[dai->id].wcd9xxx_ch_list, list) { |
| 3606 | |
| 3607 | tx_port = ch->port + 1; |
| 3608 | dev_dbg(codec->dev, "%s: dai->id = %d, tx_port = %d", |
| 3609 | __func__, dai->id, tx_port); |
| 3610 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3611 | if ((tx_port < 1) || (tx_port > TAPAN_SLIM_CODEC_TX_PORTS)) { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3612 | pr_err("%s: Invalid SLIM TX%u port. DAI ID is %d\n", |
| 3613 | __func__, tx_port, dai->id); |
| 3614 | return -EINVAL; |
| 3615 | } |
| 3616 | |
| 3617 | tx_port_reg = TAPAN_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1); |
| 3618 | tx_port_reg_val = snd_soc_read(codec, tx_port_reg); |
| 3619 | |
| 3620 | decimator = 0; |
| 3621 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3622 | tx_port_reg_val = tx_port_reg_val & 0x0F; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3623 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3624 | if ((tx_port_reg_val >= 0x8) && |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3625 | (tx_port_reg_val <= 0x11)) { |
| 3626 | |
| 3627 | decimator = (tx_port_reg_val - 0x8) + 1; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3628 | } |
| 3629 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3630 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3631 | if (decimator) { /* SLIM_TX port has a DEC as input */ |
| 3632 | |
| 3633 | tx_fs_reg = TAPAN_A_CDC_TX1_CLK_FS_CTL + |
| 3634 | 8 * (decimator - 1); |
| 3635 | |
| 3636 | dev_dbg(codec->dev, "%s: set DEC%u (-> SLIM_TX%u) rate to %u\n", |
| 3637 | __func__, decimator, tx_port, sample_rate); |
| 3638 | |
| 3639 | snd_soc_update_bits(codec, tx_fs_reg, 0x07, |
| 3640 | tx_fs_rate_reg_val); |
| 3641 | |
| 3642 | } else { |
| 3643 | if ((tx_port_reg_val >= 0x1) && |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3644 | (tx_port_reg_val <= 0x4)) { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3645 | |
| 3646 | dev_dbg(codec->dev, "%s: RMIX%u going to SLIM TX%u\n", |
| 3647 | __func__, tx_port_reg_val, tx_port); |
| 3648 | |
| 3649 | } else if ((tx_port_reg_val >= 0x8) && |
| 3650 | (tx_port_reg_val <= 0x11)) { |
| 3651 | |
| 3652 | pr_err("%s: ERROR: Should not be here\n", |
| 3653 | __func__); |
| 3654 | pr_err("%s: ERROR: DEC connected to SLIM TX%u\n", |
| 3655 | __func__, tx_port); |
| 3656 | return -EINVAL; |
| 3657 | |
| 3658 | } else if (tx_port_reg_val == 0) { |
| 3659 | dev_dbg(codec->dev, "%s: no signal to SLIM TX%u\n", |
| 3660 | __func__, tx_port); |
| 3661 | } else { |
| 3662 | pr_err("%s: ERROR: wrong signal to SLIM TX%u\n", |
| 3663 | __func__, tx_port); |
| 3664 | pr_err("%s: ERROR: wrong signal = %u\n", |
| 3665 | __func__, tx_port_reg_val); |
| 3666 | return -EINVAL; |
| 3667 | } |
| 3668 | } |
| 3669 | } |
| 3670 | return 0; |
| 3671 | } |
| 3672 | |
Venkat Sudhir | bb44447 | 2014-01-14 10:03:23 -0800 | [diff] [blame] | 3673 | static void tapan_set_rxsb_port_format(struct snd_pcm_hw_params *params, |
| 3674 | struct snd_soc_dai *dai) |
| 3675 | { |
| 3676 | struct snd_soc_codec *codec = dai->codec; |
| 3677 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
| 3678 | struct wcd9xxx_codec_dai_data *cdc_dai; |
| 3679 | struct wcd9xxx_ch *ch; |
| 3680 | int port; |
| 3681 | u8 bit_sel; |
| 3682 | u16 sb_ctl_reg, field_shift; |
| 3683 | |
| 3684 | switch (params_format(params)) { |
| 3685 | case SNDRV_PCM_FORMAT_S16_LE: |
| 3686 | bit_sel = 0x2; |
| 3687 | tapan_p->dai[dai->id].bit_width = 16; |
| 3688 | break; |
| 3689 | case SNDRV_PCM_FORMAT_S24_LE: |
| 3690 | bit_sel = 0x0; |
| 3691 | tapan_p->dai[dai->id].bit_width = 24; |
| 3692 | break; |
| 3693 | default: |
| 3694 | dev_err(codec->dev, "Invalid format %x\n", |
| 3695 | params_format(params)); |
| 3696 | return; |
| 3697 | } |
| 3698 | |
| 3699 | cdc_dai = &tapan_p->dai[dai->id]; |
| 3700 | |
| 3701 | list_for_each_entry(ch, &cdc_dai->wcd9xxx_ch_list, list) { |
| 3702 | port = wcd9xxx_get_slave_port(ch->ch_num); |
| 3703 | |
| 3704 | if (IS_ERR_VALUE(port) || |
| 3705 | !TAPAN_VALIDATE_RX_SBPORT_RANGE(port)) { |
| 3706 | dev_warn(codec->dev, |
| 3707 | "%s: invalid port ID %d returned for RX DAI\n", |
| 3708 | __func__, port); |
| 3709 | return; |
| 3710 | } |
| 3711 | |
| 3712 | port = TAPAN_CONVERT_RX_SBPORT_ID(port); |
| 3713 | |
| 3714 | if (port <= 3) { |
| 3715 | sb_ctl_reg = TAPAN_A_CDC_CONN_RX_SB_B1_CTL; |
| 3716 | field_shift = port << 1; |
| 3717 | } else if (port <= 4) { |
| 3718 | sb_ctl_reg = TAPAN_A_CDC_CONN_RX_SB_B2_CTL; |
| 3719 | field_shift = (port - 4) << 1; |
| 3720 | } else { /* should not happen */ |
| 3721 | dev_warn(codec->dev, |
| 3722 | "%s: bad port ID %d\n", __func__, port); |
| 3723 | return; |
| 3724 | } |
| 3725 | |
| 3726 | dev_dbg(codec->dev, "%s: sb_ctl_reg %x field_shift %x\n" |
| 3727 | "bit_sel %x\n", __func__, sb_ctl_reg, field_shift, |
| 3728 | bit_sel); |
| 3729 | snd_soc_update_bits(codec, sb_ctl_reg, 0x3 << field_shift, |
| 3730 | bit_sel << field_shift); |
| 3731 | } |
| 3732 | } |
| 3733 | |
| 3734 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3735 | static int tapan_hw_params(struct snd_pcm_substream *substream, |
| 3736 | struct snd_pcm_hw_params *params, |
| 3737 | struct snd_soc_dai *dai) |
| 3738 | { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3739 | struct snd_soc_codec *codec = dai->codec; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3740 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(dai->codec); |
| 3741 | u8 tx_fs_rate, rx_fs_rate; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3742 | u32 compander_fs; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3743 | int ret; |
| 3744 | |
| 3745 | dev_dbg(dai->codec->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", |
| 3746 | __func__, dai->name, dai->id, |
| 3747 | params_rate(params), params_channels(params)); |
| 3748 | |
| 3749 | switch (params_rate(params)) { |
| 3750 | case 8000: |
| 3751 | tx_fs_rate = 0x00; |
| 3752 | rx_fs_rate = 0x00; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3753 | compander_fs = COMPANDER_FS_8KHZ; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3754 | break; |
| 3755 | case 16000: |
| 3756 | tx_fs_rate = 0x01; |
| 3757 | rx_fs_rate = 0x20; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3758 | compander_fs = COMPANDER_FS_16KHZ; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3759 | break; |
| 3760 | case 32000: |
| 3761 | tx_fs_rate = 0x02; |
| 3762 | rx_fs_rate = 0x40; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3763 | compander_fs = COMPANDER_FS_32KHZ; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3764 | break; |
| 3765 | case 48000: |
| 3766 | tx_fs_rate = 0x03; |
| 3767 | rx_fs_rate = 0x60; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3768 | compander_fs = COMPANDER_FS_48KHZ; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3769 | break; |
| 3770 | case 96000: |
| 3771 | tx_fs_rate = 0x04; |
| 3772 | rx_fs_rate = 0x80; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3773 | compander_fs = COMPANDER_FS_96KHZ; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3774 | break; |
| 3775 | case 192000: |
| 3776 | tx_fs_rate = 0x05; |
| 3777 | rx_fs_rate = 0xA0; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3778 | compander_fs = COMPANDER_FS_192KHZ; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3779 | break; |
| 3780 | default: |
| 3781 | pr_err("%s: Invalid sampling rate %d\n", __func__, |
| 3782 | params_rate(params)); |
| 3783 | return -EINVAL; |
| 3784 | } |
| 3785 | |
| 3786 | switch (substream->stream) { |
| 3787 | case SNDRV_PCM_STREAM_CAPTURE: |
| 3788 | ret = tapan_set_decimator_rate(dai, tx_fs_rate, |
| 3789 | params_rate(params)); |
| 3790 | if (ret < 0) { |
| 3791 | pr_err("%s: set decimator rate failed %d\n", __func__, |
| 3792 | ret); |
| 3793 | return ret; |
| 3794 | } |
| 3795 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3796 | if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 3797 | switch (params_format(params)) { |
| 3798 | case SNDRV_PCM_FORMAT_S16_LE: |
| 3799 | snd_soc_update_bits(codec, |
| 3800 | TAPAN_A_CDC_CLK_I2S_CTL, |
| 3801 | 0x20, 0x20); |
| 3802 | break; |
| 3803 | case SNDRV_PCM_FORMAT_S32_LE: |
| 3804 | snd_soc_update_bits(codec, |
| 3805 | TAPAN_A_CDC_CLK_I2S_CTL, |
| 3806 | 0x20, 0x00); |
| 3807 | break; |
| 3808 | default: |
| 3809 | pr_err("invalid format\n"); |
| 3810 | break; |
| 3811 | } |
| 3812 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_I2S_CTL, |
| 3813 | 0x07, tx_fs_rate); |
| 3814 | } else { |
| 3815 | tapan->dai[dai->id].rate = params_rate(params); |
| 3816 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3817 | break; |
| 3818 | |
| 3819 | case SNDRV_PCM_STREAM_PLAYBACK: |
| 3820 | ret = tapan_set_interpolator_rate(dai, rx_fs_rate, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3821 | compander_fs, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3822 | params_rate(params)); |
| 3823 | if (ret < 0) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3824 | dev_err(codec->dev, "%s: set decimator rate failed %d\n", |
| 3825 | __func__, ret); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3826 | return ret; |
| 3827 | } |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3828 | if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 3829 | switch (params_format(params)) { |
| 3830 | case SNDRV_PCM_FORMAT_S16_LE: |
| 3831 | snd_soc_update_bits(codec, |
| 3832 | TAPAN_A_CDC_CLK_I2S_CTL, |
| 3833 | 0x20, 0x20); |
| 3834 | break; |
| 3835 | case SNDRV_PCM_FORMAT_S32_LE: |
| 3836 | snd_soc_update_bits(codec, |
| 3837 | TAPAN_A_CDC_CLK_I2S_CTL, |
| 3838 | 0x20, 0x00); |
| 3839 | break; |
| 3840 | default: |
| 3841 | dev_err(codec->dev, "invalid format\n"); |
| 3842 | break; |
| 3843 | } |
| 3844 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_I2S_CTL, |
| 3845 | 0x03, (rx_fs_rate >> 0x05)); |
| 3846 | } else { |
Venkat Sudhir | bb44447 | 2014-01-14 10:03:23 -0800 | [diff] [blame] | 3847 | tapan_set_rxsb_port_format(params, dai); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3848 | tapan->dai[dai->id].rate = params_rate(params); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3849 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3850 | break; |
| 3851 | default: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3852 | dev_err(codec->dev, "%s: Invalid stream type %d\n", __func__, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3853 | substream->stream); |
| 3854 | return -EINVAL; |
| 3855 | } |
| 3856 | |
| 3857 | return 0; |
| 3858 | } |
| 3859 | |
| 3860 | static struct snd_soc_dai_ops tapan_dai_ops = { |
| 3861 | .startup = tapan_startup, |
| 3862 | .shutdown = tapan_shutdown, |
| 3863 | .hw_params = tapan_hw_params, |
| 3864 | .set_sysclk = tapan_set_dai_sysclk, |
| 3865 | .set_fmt = tapan_set_dai_fmt, |
| 3866 | .set_channel_map = tapan_set_channel_map, |
| 3867 | .get_channel_map = tapan_get_channel_map, |
| 3868 | }; |
| 3869 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 3870 | static struct snd_soc_dai_driver tapan9302_dai[] = { |
| 3871 | { |
| 3872 | .name = "tapan9302_rx1", |
| 3873 | .id = AIF1_PB, |
| 3874 | .playback = { |
| 3875 | .stream_name = "AIF1 Playback", |
| 3876 | .rates = WCD9302_RATES, |
| 3877 | .formats = TAPAN_FORMATS, |
| 3878 | .rate_max = 48000, |
| 3879 | .rate_min = 8000, |
| 3880 | .channels_min = 1, |
| 3881 | .channels_max = 2, |
| 3882 | }, |
| 3883 | .ops = &tapan_dai_ops, |
| 3884 | }, |
| 3885 | { |
| 3886 | .name = "tapan9302_tx1", |
| 3887 | .id = AIF1_CAP, |
| 3888 | .capture = { |
| 3889 | .stream_name = "AIF1 Capture", |
| 3890 | .rates = WCD9302_RATES, |
| 3891 | .formats = TAPAN_FORMATS, |
| 3892 | .rate_max = 48000, |
| 3893 | .rate_min = 8000, |
| 3894 | .channels_min = 1, |
| 3895 | .channels_max = 4, |
| 3896 | }, |
| 3897 | .ops = &tapan_dai_ops, |
| 3898 | }, |
| 3899 | { |
| 3900 | .name = "tapan9302_rx2", |
| 3901 | .id = AIF2_PB, |
| 3902 | .playback = { |
| 3903 | .stream_name = "AIF2 Playback", |
| 3904 | .rates = WCD9302_RATES, |
| 3905 | .formats = TAPAN_FORMATS, |
| 3906 | .rate_min = 8000, |
| 3907 | .rate_max = 48000, |
| 3908 | .channels_min = 1, |
| 3909 | .channels_max = 2, |
| 3910 | }, |
| 3911 | .ops = &tapan_dai_ops, |
| 3912 | }, |
| 3913 | { |
| 3914 | .name = "tapan9302_tx2", |
| 3915 | .id = AIF2_CAP, |
| 3916 | .capture = { |
| 3917 | .stream_name = "AIF2 Capture", |
| 3918 | .rates = WCD9302_RATES, |
| 3919 | .formats = TAPAN_FORMATS, |
| 3920 | .rate_max = 48000, |
| 3921 | .rate_min = 8000, |
| 3922 | .channels_min = 1, |
| 3923 | .channels_max = 4, |
| 3924 | }, |
| 3925 | .ops = &tapan_dai_ops, |
| 3926 | }, |
| 3927 | { |
| 3928 | .name = "tapan9302_tx3", |
| 3929 | .id = AIF3_CAP, |
| 3930 | .capture = { |
| 3931 | .stream_name = "AIF3 Capture", |
| 3932 | .rates = WCD9302_RATES, |
| 3933 | .formats = TAPAN_FORMATS, |
| 3934 | .rate_max = 48000, |
| 3935 | .rate_min = 8000, |
| 3936 | .channels_min = 1, |
| 3937 | .channels_max = 2, |
| 3938 | }, |
| 3939 | .ops = &tapan_dai_ops, |
| 3940 | }, |
| 3941 | { |
| 3942 | .name = "tapan9302_rx3", |
| 3943 | .id = AIF3_PB, |
| 3944 | .playback = { |
| 3945 | .stream_name = "AIF3 Playback", |
| 3946 | .rates = WCD9302_RATES, |
| 3947 | .formats = TAPAN_FORMATS, |
| 3948 | .rate_min = 8000, |
| 3949 | .rate_max = 48000, |
| 3950 | .channels_min = 1, |
| 3951 | .channels_max = 2, |
| 3952 | }, |
| 3953 | .ops = &tapan_dai_ops, |
| 3954 | }, |
| 3955 | }; |
| 3956 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3957 | static struct snd_soc_dai_driver tapan_dai[] = { |
| 3958 | { |
| 3959 | .name = "tapan_rx1", |
| 3960 | .id = AIF1_PB, |
| 3961 | .playback = { |
| 3962 | .stream_name = "AIF1 Playback", |
| 3963 | .rates = WCD9306_RATES, |
Venkat Sudhir | bb44447 | 2014-01-14 10:03:23 -0800 | [diff] [blame] | 3964 | .formats = TAPAN_FORMATS_S16_S24_LE, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3965 | .rate_max = 192000, |
| 3966 | .rate_min = 8000, |
| 3967 | .channels_min = 1, |
| 3968 | .channels_max = 2, |
| 3969 | }, |
| 3970 | .ops = &tapan_dai_ops, |
| 3971 | }, |
| 3972 | { |
| 3973 | .name = "tapan_tx1", |
| 3974 | .id = AIF1_CAP, |
| 3975 | .capture = { |
| 3976 | .stream_name = "AIF1 Capture", |
| 3977 | .rates = WCD9306_RATES, |
| 3978 | .formats = TAPAN_FORMATS, |
| 3979 | .rate_max = 192000, |
| 3980 | .rate_min = 8000, |
| 3981 | .channels_min = 1, |
| 3982 | .channels_max = 4, |
| 3983 | }, |
| 3984 | .ops = &tapan_dai_ops, |
| 3985 | }, |
| 3986 | { |
| 3987 | .name = "tapan_rx2", |
| 3988 | .id = AIF2_PB, |
| 3989 | .playback = { |
| 3990 | .stream_name = "AIF2 Playback", |
| 3991 | .rates = WCD9306_RATES, |
Venkat Sudhir | bb44447 | 2014-01-14 10:03:23 -0800 | [diff] [blame] | 3992 | .formats = TAPAN_FORMATS_S16_S24_LE, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3993 | .rate_min = 8000, |
| 3994 | .rate_max = 192000, |
| 3995 | .channels_min = 1, |
| 3996 | .channels_max = 2, |
| 3997 | }, |
| 3998 | .ops = &tapan_dai_ops, |
| 3999 | }, |
| 4000 | { |
| 4001 | .name = "tapan_tx2", |
| 4002 | .id = AIF2_CAP, |
| 4003 | .capture = { |
| 4004 | .stream_name = "AIF2 Capture", |
| 4005 | .rates = WCD9306_RATES, |
| 4006 | .formats = TAPAN_FORMATS, |
| 4007 | .rate_max = 192000, |
| 4008 | .rate_min = 8000, |
| 4009 | .channels_min = 1, |
| 4010 | .channels_max = 4, |
| 4011 | }, |
| 4012 | .ops = &tapan_dai_ops, |
| 4013 | }, |
| 4014 | { |
| 4015 | .name = "tapan_tx3", |
| 4016 | .id = AIF3_CAP, |
| 4017 | .capture = { |
| 4018 | .stream_name = "AIF3 Capture", |
| 4019 | .rates = WCD9306_RATES, |
| 4020 | .formats = TAPAN_FORMATS, |
| 4021 | .rate_max = 48000, |
| 4022 | .rate_min = 8000, |
| 4023 | .channels_min = 1, |
| 4024 | .channels_max = 2, |
| 4025 | }, |
| 4026 | .ops = &tapan_dai_ops, |
| 4027 | }, |
| 4028 | { |
| 4029 | .name = "tapan_rx3", |
| 4030 | .id = AIF3_PB, |
| 4031 | .playback = { |
| 4032 | .stream_name = "AIF3 Playback", |
| 4033 | .rates = WCD9306_RATES, |
Venkat Sudhir | bb44447 | 2014-01-14 10:03:23 -0800 | [diff] [blame] | 4034 | .formats = TAPAN_FORMATS_S16_S24_LE, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4035 | .rate_min = 8000, |
| 4036 | .rate_max = 192000, |
| 4037 | .channels_min = 1, |
| 4038 | .channels_max = 2, |
| 4039 | }, |
| 4040 | .ops = &tapan_dai_ops, |
| 4041 | }, |
| 4042 | }; |
| 4043 | |
| 4044 | static struct snd_soc_dai_driver tapan_i2s_dai[] = { |
| 4045 | { |
| 4046 | .name = "tapan_i2s_rx1", |
| 4047 | .id = AIF1_PB, |
| 4048 | .playback = { |
| 4049 | .stream_name = "AIF1 Playback", |
| 4050 | .rates = WCD9306_RATES, |
| 4051 | .formats = TAPAN_FORMATS, |
| 4052 | .rate_max = 192000, |
| 4053 | .rate_min = 8000, |
| 4054 | .channels_min = 1, |
| 4055 | .channels_max = 4, |
| 4056 | }, |
| 4057 | .ops = &tapan_dai_ops, |
| 4058 | }, |
| 4059 | { |
| 4060 | .name = "tapan_i2s_tx1", |
| 4061 | .id = AIF1_CAP, |
| 4062 | .capture = { |
| 4063 | .stream_name = "AIF1 Capture", |
| 4064 | .rates = WCD9306_RATES, |
| 4065 | .formats = TAPAN_FORMATS, |
| 4066 | .rate_max = 192000, |
| 4067 | .rate_min = 8000, |
| 4068 | .channels_min = 1, |
| 4069 | .channels_max = 4, |
| 4070 | }, |
| 4071 | .ops = &tapan_dai_ops, |
| 4072 | }, |
| 4073 | }; |
| 4074 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4075 | static int tapan_codec_enable_slim_chmask(struct wcd9xxx_codec_dai_data *dai, |
| 4076 | bool up) |
| 4077 | { |
| 4078 | int ret = 0; |
| 4079 | struct wcd9xxx_ch *ch; |
| 4080 | |
| 4081 | if (up) { |
| 4082 | list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) { |
| 4083 | ret = wcd9xxx_get_slave_port(ch->ch_num); |
| 4084 | if (ret < 0) { |
| 4085 | pr_debug("%s: Invalid slave port ID: %d\n", |
| 4086 | __func__, ret); |
| 4087 | ret = -EINVAL; |
| 4088 | } else { |
| 4089 | set_bit(ret, &dai->ch_mask); |
| 4090 | } |
| 4091 | } |
| 4092 | } else { |
| 4093 | ret = wait_event_timeout(dai->dai_wait, (dai->ch_mask == 0), |
| 4094 | msecs_to_jiffies( |
| 4095 | TAPAN_SLIM_CLOSE_TIMEOUT)); |
| 4096 | if (!ret) { |
| 4097 | pr_debug("%s: Slim close tx/rx wait timeout\n", |
| 4098 | __func__); |
| 4099 | ret = -ETIMEDOUT; |
| 4100 | } else { |
| 4101 | ret = 0; |
| 4102 | } |
| 4103 | } |
| 4104 | return ret; |
| 4105 | } |
| 4106 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4107 | static int tapan_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
| 4108 | struct snd_kcontrol *kcontrol, |
| 4109 | int event) |
| 4110 | { |
| 4111 | struct wcd9xxx *core; |
| 4112 | struct snd_soc_codec *codec = w->codec; |
| 4113 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4114 | int ret = 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4115 | struct wcd9xxx_codec_dai_data *dai; |
| 4116 | |
| 4117 | core = dev_get_drvdata(codec->dev->parent); |
| 4118 | |
| 4119 | dev_dbg(codec->dev, "%s: event called! codec name %s\n", |
| 4120 | __func__, w->codec->name); |
| 4121 | dev_dbg(codec->dev, "%s: num_dai %d stream name %s event %d\n", |
| 4122 | __func__, w->codec->num_dai, w->sname, event); |
| 4123 | |
| 4124 | /* Execute the callback only if interface type is slimbus */ |
| 4125 | if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 4126 | return 0; |
| 4127 | |
| 4128 | dai = &tapan_p->dai[w->shift]; |
| 4129 | dev_dbg(codec->dev, "%s: w->name %s w->shift %d event %d\n", |
| 4130 | __func__, w->name, w->shift, event); |
| 4131 | |
| 4132 | switch (event) { |
| 4133 | case SND_SOC_DAPM_POST_PMU: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4134 | (void) tapan_codec_enable_slim_chmask(dai, true); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4135 | ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list, |
| 4136 | dai->rate, dai->bit_width, |
| 4137 | &dai->grph); |
| 4138 | break; |
| 4139 | case SND_SOC_DAPM_POST_PMD: |
| 4140 | ret = wcd9xxx_close_slim_sch_rx(core, &dai->wcd9xxx_ch_list, |
| 4141 | dai->grph); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4142 | ret = tapan_codec_enable_slim_chmask(dai, false); |
| 4143 | if (ret < 0) { |
| 4144 | ret = wcd9xxx_disconnect_port(core, |
| 4145 | &dai->wcd9xxx_ch_list, |
| 4146 | dai->grph); |
| 4147 | dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n", |
| 4148 | __func__, ret); |
| 4149 | } |
Phani Kumar Uppalapati | e2a18e2 | 2013-10-24 14:32:54 -0700 | [diff] [blame] | 4150 | if ((core != NULL) && |
| 4151 | (core->dev != NULL) && |
| 4152 | (core->dev->parent != NULL)) { |
| 4153 | pm_runtime_mark_last_busy(core->dev->parent); |
| 4154 | pm_runtime_put(core->dev->parent); |
| 4155 | dev_dbg(codec->dev, "%s: unvote requested", __func__); |
| 4156 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4157 | break; |
| 4158 | } |
| 4159 | return ret; |
| 4160 | } |
| 4161 | |
| 4162 | static int tapan_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
| 4163 | struct snd_kcontrol *kcontrol, |
| 4164 | int event) |
| 4165 | { |
| 4166 | struct wcd9xxx *core; |
| 4167 | struct snd_soc_codec *codec = w->codec; |
| 4168 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
| 4169 | u32 ret = 0; |
| 4170 | struct wcd9xxx_codec_dai_data *dai; |
| 4171 | |
| 4172 | core = dev_get_drvdata(codec->dev->parent); |
| 4173 | |
| 4174 | dev_dbg(codec->dev, "%s: event called! codec name %s\n", |
| 4175 | __func__, w->codec->name); |
| 4176 | dev_dbg(codec->dev, "%s: num_dai %d stream name %s\n", |
| 4177 | __func__, w->codec->num_dai, w->sname); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4178 | /* Execute the callback only if interface type is slimbus */ |
| 4179 | if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 4180 | return 0; |
| 4181 | |
| 4182 | dev_dbg(codec->dev, "%s(): w->name %s event %d w->shift %d\n", |
| 4183 | __func__, w->name, event, w->shift); |
| 4184 | |
| 4185 | dai = &tapan_p->dai[w->shift]; |
| 4186 | switch (event) { |
| 4187 | case SND_SOC_DAPM_POST_PMU: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4188 | (void) tapan_codec_enable_slim_chmask(dai, true); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4189 | ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 4190 | dai->rate, dai->bit_width, |
| 4191 | &dai->grph); |
| 4192 | break; |
| 4193 | case SND_SOC_DAPM_POST_PMD: |
| 4194 | ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 4195 | dai->grph); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4196 | ret = tapan_codec_enable_slim_chmask(dai, false); |
| 4197 | if (ret < 0) { |
| 4198 | ret = wcd9xxx_disconnect_port(core, |
| 4199 | &dai->wcd9xxx_ch_list, |
| 4200 | dai->grph); |
| 4201 | dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n", |
| 4202 | __func__, ret); |
| 4203 | } |
Phani Kumar Uppalapati | e2a18e2 | 2013-10-24 14:32:54 -0700 | [diff] [blame] | 4204 | if ((core != NULL) && |
| 4205 | (core->dev != NULL) && |
| 4206 | (core->dev->parent != NULL)) { |
| 4207 | pm_runtime_mark_last_busy(core->dev->parent); |
| 4208 | pm_runtime_put(core->dev->parent); |
| 4209 | dev_dbg(codec->dev, "%s: unvote requested", __func__); |
| 4210 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4211 | break; |
| 4212 | } |
| 4213 | return ret; |
| 4214 | } |
| 4215 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4216 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4217 | static int tapan_codec_enable_ear_pa(struct snd_soc_dapm_widget *w, |
| 4218 | struct snd_kcontrol *kcontrol, int event) |
| 4219 | { |
| 4220 | struct snd_soc_codec *codec = w->codec; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4221 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4222 | |
| 4223 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 4224 | |
| 4225 | switch (event) { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4226 | case SND_SOC_DAPM_POST_PMU: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4227 | wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d, |
| 4228 | WCD9XXX_CLSH_STATE_EAR, |
| 4229 | WCD9XXX_CLSH_REQ_ENABLE, |
| 4230 | WCD9XXX_CLSH_EVENT_POST_PA); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4231 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4232 | usleep_range(5000, 5010); |
| 4233 | break; |
| 4234 | case SND_SOC_DAPM_POST_PMD: |
| 4235 | wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d, |
| 4236 | WCD9XXX_CLSH_STATE_EAR, |
| 4237 | WCD9XXX_CLSH_REQ_DISABLE, |
| 4238 | WCD9XXX_CLSH_EVENT_POST_PA); |
| 4239 | usleep_range(5000, 5010); |
| 4240 | } |
| 4241 | return 0; |
| 4242 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4243 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4244 | static int tapan_codec_ear_dac_event(struct snd_soc_dapm_widget *w, |
| 4245 | struct snd_kcontrol *kcontrol, int event) |
| 4246 | { |
| 4247 | struct snd_soc_codec *codec = w->codec; |
| 4248 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
| 4249 | |
| 4250 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 4251 | |
| 4252 | switch (event) { |
| 4253 | case SND_SOC_DAPM_PRE_PMU: |
| 4254 | wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d, |
| 4255 | WCD9XXX_CLSH_STATE_EAR, |
| 4256 | WCD9XXX_CLSH_REQ_ENABLE, |
| 4257 | WCD9XXX_CLSH_EVENT_PRE_DAC); |
| 4258 | break; |
| 4259 | } |
| 4260 | |
| 4261 | return 0; |
| 4262 | } |
| 4263 | |
Shruthi Krishna | efb0a1c | 2014-03-26 18:33:31 -0700 | [diff] [blame] | 4264 | static int tapan_codec_iir_mux_event(struct snd_soc_dapm_widget *w, |
| 4265 | struct snd_kcontrol *kcontrol, int event) |
| 4266 | { |
| 4267 | struct snd_soc_codec *codec = w->codec; |
| 4268 | pr_debug("%s: event = %d\n", __func__, event); |
| 4269 | |
| 4270 | switch (event) { |
| 4271 | case SND_SOC_DAPM_POST_PMU: |
| 4272 | snd_soc_write(codec, w->reg, snd_soc_read(codec, w->reg)); |
| 4273 | break; |
| 4274 | case SND_SOC_DAPM_POST_PMD: |
| 4275 | snd_soc_write(codec, w->reg, snd_soc_read(codec, w->reg)); |
| 4276 | break; |
| 4277 | } |
| 4278 | return 0; |
| 4279 | } |
| 4280 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4281 | static int tapan_codec_dsm_mux_event(struct snd_soc_dapm_widget *w, |
| 4282 | struct snd_kcontrol *kcontrol, int event) |
| 4283 | { |
| 4284 | struct snd_soc_codec *codec = w->codec; |
| 4285 | u8 reg_val, zoh_mux_val = 0x00; |
| 4286 | |
| 4287 | dev_dbg(codec->dev, "%s: event = %d\n", __func__, event); |
| 4288 | |
| 4289 | switch (event) { |
| 4290 | case SND_SOC_DAPM_POST_PMU: |
| 4291 | reg_val = snd_soc_read(codec, TAPAN_A_CDC_CONN_CLSH_CTL); |
| 4292 | |
| 4293 | if ((reg_val & 0x30) == 0x10) |
| 4294 | zoh_mux_val = 0x04; |
| 4295 | else if ((reg_val & 0x30) == 0x20) |
| 4296 | zoh_mux_val = 0x08; |
| 4297 | |
| 4298 | if (zoh_mux_val != 0x00) |
| 4299 | snd_soc_update_bits(codec, |
| 4300 | TAPAN_A_CDC_CONN_CLSH_CTL, |
| 4301 | 0x0C, zoh_mux_val); |
| 4302 | break; |
| 4303 | |
| 4304 | case SND_SOC_DAPM_POST_PMD: |
| 4305 | snd_soc_update_bits(codec, TAPAN_A_CDC_CONN_CLSH_CTL, |
| 4306 | 0x0C, 0x00); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4307 | break; |
| 4308 | } |
| 4309 | return 0; |
| 4310 | } |
| 4311 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 4312 | static int tapan_codec_enable_anc_ear(struct snd_soc_dapm_widget *w, |
| 4313 | struct snd_kcontrol *kcontrol, int event) |
| 4314 | { |
| 4315 | struct snd_soc_codec *codec = w->codec; |
| 4316 | int ret = 0; |
| 4317 | |
| 4318 | switch (event) { |
| 4319 | case SND_SOC_DAPM_PRE_PMU: |
| 4320 | ret = tapan_codec_enable_anc(w, kcontrol, event); |
| 4321 | msleep(50); |
| 4322 | snd_soc_update_bits(codec, TAPAN_A_RX_EAR_EN, 0x10, 0x10); |
| 4323 | break; |
| 4324 | case SND_SOC_DAPM_POST_PMU: |
| 4325 | ret = tapan_codec_enable_ear_pa(w, kcontrol, event); |
| 4326 | break; |
| 4327 | case SND_SOC_DAPM_PRE_PMD: |
| 4328 | snd_soc_update_bits(codec, TAPAN_A_RX_EAR_EN, 0x10, 0x00); |
| 4329 | msleep(40); |
| 4330 | ret |= tapan_codec_enable_anc(w, kcontrol, event); |
| 4331 | break; |
| 4332 | case SND_SOC_DAPM_POST_PMD: |
| 4333 | ret = tapan_codec_enable_ear_pa(w, kcontrol, event); |
| 4334 | break; |
| 4335 | } |
| 4336 | return ret; |
| 4337 | } |
| 4338 | |
Bhalchandra Gajare | 5b4199c | 2013-07-03 14:35:43 -0700 | [diff] [blame] | 4339 | static int tapan_codec_chargepump_vdd_event(struct snd_soc_dapm_widget *w, |
| 4340 | struct snd_kcontrol *kcontrol, int event) |
| 4341 | { |
| 4342 | struct snd_soc_codec *codec = w->codec; |
| 4343 | struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec); |
| 4344 | int ret = 0, i; |
| 4345 | |
| 4346 | pr_info("%s: event = %d\n", __func__, event); |
| 4347 | |
| 4348 | |
| 4349 | if (!priv->cp_regulators[CP_REG_BUCK] |
| 4350 | && !priv->cp_regulators[CP_REG_BHELPER]) { |
| 4351 | pr_err("%s: No power supply defined for ChargePump\n", |
| 4352 | __func__); |
| 4353 | return -EINVAL; |
| 4354 | } |
| 4355 | |
| 4356 | switch (event) { |
| 4357 | case SND_SOC_DAPM_PRE_PMU: |
| 4358 | for (i = 0; i < CP_REG_MAX ; i++) { |
| 4359 | if (!priv->cp_regulators[i]) |
| 4360 | continue; |
| 4361 | |
| 4362 | ret = regulator_enable(priv->cp_regulators[i]); |
| 4363 | if (ret) { |
| 4364 | pr_err("%s: CP Regulator enable failed, index = %d\n", |
| 4365 | __func__, i); |
| 4366 | continue; |
| 4367 | } else { |
| 4368 | pr_debug("%s: Enabled CP regulator, index %d\n", |
| 4369 | __func__, i); |
| 4370 | } |
| 4371 | } |
| 4372 | break; |
| 4373 | case SND_SOC_DAPM_POST_PMD: |
| 4374 | for (i = 0; i < CP_REG_MAX; i++) { |
| 4375 | if (!priv->cp_regulators[i]) |
| 4376 | continue; |
| 4377 | |
| 4378 | ret = regulator_disable(priv->cp_regulators[i]); |
| 4379 | if (ret) { |
| 4380 | pr_err("%s: CP Regulator disable failed, index = %d\n", |
| 4381 | __func__, i); |
| 4382 | return ret; |
| 4383 | } else { |
| 4384 | pr_debug("%s: Disabled CP regulator %d\n", |
| 4385 | __func__, i); |
| 4386 | } |
| 4387 | } |
| 4388 | break; |
| 4389 | } |
| 4390 | return 0; |
| 4391 | } |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4392 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 4393 | static const struct snd_soc_dapm_widget tapan_9306_dapm_widgets[] = { |
| 4394 | /* RX4 MIX1 mux inputs */ |
| 4395 | SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4396 | &rx4_mix1_inp1_mux), |
| 4397 | SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4398 | &rx4_mix1_inp2_mux), |
| 4399 | SND_SOC_DAPM_MUX("RX4 MIX1 INP3", SND_SOC_NOPM, 0, 0, |
Santosh Mardi | 330ad2a | 2013-11-21 18:12:14 +0530 | [diff] [blame] | 4400 | &rx4_mix1_inp3_mux), |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 4401 | |
| 4402 | /* RX4 MIX2 mux inputs */ |
| 4403 | SND_SOC_DAPM_MUX("RX4 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 4404 | &rx4_mix2_inp1_mux), |
| 4405 | SND_SOC_DAPM_MUX("RX4 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 4406 | &rx4_mix2_inp2_mux), |
| 4407 | |
| 4408 | SND_SOC_DAPM_MIXER("RX4 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4409 | |
| 4410 | SND_SOC_DAPM_MIXER_E("RX4 MIX2", TAPAN_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL, |
| 4411 | 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4412 | SND_SOC_DAPM_POST_PMU), |
| 4413 | |
| 4414 | SND_SOC_DAPM_MUX_E("DEC3 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 2, 0, |
| 4415 | &dec3_mux, tapan_codec_enable_dec, |
| 4416 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4417 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 4418 | |
| 4419 | SND_SOC_DAPM_MUX_E("DEC4 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 3, 0, |
| 4420 | &dec4_mux, tapan_codec_enable_dec, |
| 4421 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4422 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 4423 | |
| 4424 | SND_SOC_DAPM_SUPPLY("COMP0_CLK", SND_SOC_NOPM, 0, 0, |
| 4425 | tapan_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 4426 | SND_SOC_DAPM_PRE_PMD), |
| 4427 | SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 1, 0, |
| 4428 | tapan_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 4429 | SND_SOC_DAPM_PRE_PMD), |
| 4430 | SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 2, 0, |
| 4431 | tapan_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 4432 | SND_SOC_DAPM_PRE_PMD), |
| 4433 | |
| 4434 | SND_SOC_DAPM_INPUT("AMIC5"), |
| 4435 | SND_SOC_DAPM_ADC_E("ADC5", NULL, TAPAN_A_TX_5_EN, 7, 0, |
| 4436 | tapan_codec_enable_adc, SND_SOC_DAPM_POST_PMU), |
| 4437 | |
| 4438 | SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux), |
| 4439 | SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux), |
| 4440 | |
| 4441 | SND_SOC_DAPM_OUTPUT("ANC HEADPHONE"), |
| 4442 | SND_SOC_DAPM_PGA_E("ANC HPHL", SND_SOC_NOPM, 5, 0, NULL, 0, |
| 4443 | tapan_codec_enable_anc_hph, |
| 4444 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD | |
| 4445 | SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_POST_PMU), |
| 4446 | SND_SOC_DAPM_PGA_E("ANC HPHR", SND_SOC_NOPM, 4, 0, NULL, 0, |
| 4447 | tapan_codec_enable_anc_hph, SND_SOC_DAPM_PRE_PMU | |
| 4448 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD | |
| 4449 | SND_SOC_DAPM_POST_PMU), |
| 4450 | SND_SOC_DAPM_OUTPUT("ANC EAR"), |
| 4451 | SND_SOC_DAPM_PGA_E("ANC EAR PA", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 4452 | tapan_codec_enable_anc_ear, |
| 4453 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD | |
| 4454 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4455 | SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux), |
| 4456 | |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 4457 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", SND_SOC_NOPM, 7, 0, |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 4458 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4459 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 4460 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", SND_SOC_NOPM, 7, 0, |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 4461 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4462 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 4463 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", SND_SOC_NOPM, 7, 0, |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 4464 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4465 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4466 | |
| 4467 | SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0, |
| 4468 | tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4469 | SND_SOC_DAPM_POST_PMD), |
| 4470 | |
| 4471 | SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0, |
| 4472 | tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4473 | SND_SOC_DAPM_POST_PMD), |
| 4474 | }; |
| 4475 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4476 | /* Todo: Have seperate dapm widgets for I2S and Slimbus. |
| 4477 | * Might Need to have callbacks registered only for slimbus |
| 4478 | */ |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 4479 | static const struct snd_soc_dapm_widget tapan_common_dapm_widgets[] = { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4480 | |
| 4481 | SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM, |
| 4482 | AIF1_PB, 0, tapan_codec_enable_slimrx, |
| 4483 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4484 | SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM, |
| 4485 | AIF2_PB, 0, tapan_codec_enable_slimrx, |
| 4486 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4487 | SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM, |
| 4488 | AIF3_PB, 0, tapan_codec_enable_slimrx, |
| 4489 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4490 | |
| 4491 | SND_SOC_DAPM_MUX("SLIM RX1 MUX", SND_SOC_NOPM, TAPAN_RX1, 0, |
| 4492 | &slim_rx_mux[TAPAN_RX1]), |
| 4493 | SND_SOC_DAPM_MUX("SLIM RX2 MUX", SND_SOC_NOPM, TAPAN_RX2, 0, |
| 4494 | &slim_rx_mux[TAPAN_RX2]), |
| 4495 | SND_SOC_DAPM_MUX("SLIM RX3 MUX", SND_SOC_NOPM, TAPAN_RX3, 0, |
| 4496 | &slim_rx_mux[TAPAN_RX3]), |
| 4497 | SND_SOC_DAPM_MUX("SLIM RX4 MUX", SND_SOC_NOPM, TAPAN_RX4, 0, |
| 4498 | &slim_rx_mux[TAPAN_RX4]), |
| 4499 | SND_SOC_DAPM_MUX("SLIM RX5 MUX", SND_SOC_NOPM, TAPAN_RX5, 0, |
| 4500 | &slim_rx_mux[TAPAN_RX5]), |
| 4501 | |
| 4502 | SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4503 | SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4504 | SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4505 | SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4506 | SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4507 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4508 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4509 | /* RX1 MIX1 mux inputs */ |
| 4510 | SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4511 | &rx_mix1_inp1_mux), |
| 4512 | SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4513 | &rx_mix1_inp2_mux), |
| 4514 | SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0, |
| 4515 | &rx_mix1_inp3_mux), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4516 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4517 | /* RX2 MIX1 mux inputs */ |
| 4518 | SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4519 | &rx2_mix1_inp1_mux), |
| 4520 | SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4521 | &rx2_mix1_inp2_mux), |
| 4522 | SND_SOC_DAPM_MUX("RX2 MIX1 INP3", SND_SOC_NOPM, 0, 0, |
| 4523 | &rx2_mix1_inp2_mux), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4524 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4525 | /* RX3 MIX1 mux inputs */ |
| 4526 | SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4527 | &rx3_mix1_inp1_mux), |
| 4528 | SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4529 | &rx3_mix1_inp2_mux), |
| 4530 | SND_SOC_DAPM_MUX("RX3 MIX1 INP3", SND_SOC_NOPM, 0, 0, |
Asish Bhattacharya | ba6a49d | 2014-03-19 10:03:45 +0530 | [diff] [blame] | 4531 | &rx3_mix1_inp3_mux), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4532 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4533 | /* RX1 MIX2 mux inputs */ |
| 4534 | SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 4535 | &rx1_mix2_inp1_mux), |
| 4536 | SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 4537 | &rx1_mix2_inp2_mux), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4538 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4539 | /* RX2 MIX2 mux inputs */ |
| 4540 | SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 4541 | &rx2_mix2_inp1_mux), |
| 4542 | SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 4543 | &rx2_mix2_inp2_mux), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4544 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4545 | SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4546 | SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4547 | |
| 4548 | SND_SOC_DAPM_MIXER_E("RX1 MIX2", TAPAN_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL, |
| 4549 | 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4550 | SND_SOC_DAPM_POST_PMU), |
| 4551 | SND_SOC_DAPM_MIXER_E("RX2 MIX2", TAPAN_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL, |
| 4552 | 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4553 | SND_SOC_DAPM_POST_PMU), |
| 4554 | SND_SOC_DAPM_MIXER_E("RX3 MIX1", TAPAN_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL, |
| 4555 | 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4556 | SND_SOC_DAPM_POST_PMU), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4557 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4558 | SND_SOC_DAPM_MIXER("RX1 CHAIN", TAPAN_A_CDC_RX1_B6_CTL, 5, 0, |
| 4559 | NULL, 0), |
| 4560 | SND_SOC_DAPM_MIXER("RX2 CHAIN", TAPAN_A_CDC_RX2_B6_CTL, 5, 0, |
| 4561 | NULL, 0), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4562 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4563 | SND_SOC_DAPM_MUX_E("CLASS_H_DSM MUX", SND_SOC_NOPM, 0, 0, |
| 4564 | &class_h_dsm_mux, tapan_codec_dsm_mux_event, |
| 4565 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4566 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4567 | /* RX Bias */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4568 | SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0, |
| 4569 | tapan_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU | |
| 4570 | SND_SOC_DAPM_POST_PMD), |
| 4571 | |
Bhalchandra Gajare | 5b4199c | 2013-07-03 14:35:43 -0700 | [diff] [blame] | 4572 | /* CDC_CP_VDD */ |
| 4573 | SND_SOC_DAPM_SUPPLY("CDC_CP_VDD", SND_SOC_NOPM, 0, 0, |
| 4574 | tapan_codec_chargepump_vdd_event, SND_SOC_DAPM_PRE_PMU | |
| 4575 | SND_SOC_DAPM_POST_PMD), |
| 4576 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4577 | /*EAR */ |
| 4578 | SND_SOC_DAPM_PGA_E("EAR PA", TAPAN_A_RX_EAR_EN, 4, 0, NULL, 0, |
| 4579 | tapan_codec_enable_ear_pa, SND_SOC_DAPM_POST_PMU | |
| 4580 | SND_SOC_DAPM_POST_PMD), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4581 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4582 | SND_SOC_DAPM_MIXER_E("DAC1", TAPAN_A_RX_EAR_EN, 6, 0, dac1_switch, |
| 4583 | ARRAY_SIZE(dac1_switch), tapan_codec_ear_dac_event, |
| 4584 | SND_SOC_DAPM_PRE_PMU), |
| 4585 | |
| 4586 | /* Headphone Left */ |
| 4587 | SND_SOC_DAPM_PGA_E("HPHL", TAPAN_A_RX_HPH_CNP_EN, 5, 0, NULL, 0, |
| 4588 | tapan_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 4589 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4590 | |
| 4591 | SND_SOC_DAPM_MIXER_E("HPHL DAC", TAPAN_A_RX_HPH_L_DAC_CTL, 7, 0, |
| 4592 | hphl_switch, ARRAY_SIZE(hphl_switch), tapan_hphl_dac_event, |
| 4593 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4594 | |
| 4595 | /* Headphone Right */ |
| 4596 | SND_SOC_DAPM_PGA_E("HPHR", TAPAN_A_RX_HPH_CNP_EN, 4, 0, NULL, 0, |
| 4597 | tapan_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 4598 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4599 | |
| 4600 | SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TAPAN_A_RX_HPH_R_DAC_CTL, 7, 0, |
| 4601 | tapan_hphr_dac_event, |
| 4602 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4603 | |
| 4604 | /* LINEOUT1*/ |
| 4605 | SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TAPAN_A_RX_LINE_1_DAC_CTL, 7, 0 |
| 4606 | , tapan_lineout_dac_event, |
| 4607 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4608 | |
| 4609 | SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TAPAN_A_RX_LINE_CNP_EN, 0, 0, NULL, |
| 4610 | 0, tapan_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4611 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4612 | |
| 4613 | /* LINEOUT2*/ |
| 4614 | SND_SOC_DAPM_MUX("RDAC5 MUX", SND_SOC_NOPM, 0, 0, |
| 4615 | &rx_dac5_mux), |
| 4616 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 4617 | /* LINEOUT1*/ |
| 4618 | SND_SOC_DAPM_MUX("RDAC4 MUX", SND_SOC_NOPM, 0, 0, |
| 4619 | &rx_dac4_mux), |
| 4620 | |
| 4621 | SND_SOC_DAPM_MUX("RDAC3 MUX", SND_SOC_NOPM, 0, 0, |
| 4622 | &rx_dac3_mux), |
| 4623 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4624 | SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TAPAN_A_RX_LINE_2_DAC_CTL, 7, 0 |
| 4625 | , tapan_lineout_dac_event, |
| 4626 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4627 | |
| 4628 | SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TAPAN_A_RX_LINE_CNP_EN, 1, 0, NULL, |
| 4629 | 0, tapan_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4630 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4631 | |
| 4632 | /* CLASS-D SPK */ |
| 4633 | SND_SOC_DAPM_MIXER_E("SPK DAC", SND_SOC_NOPM, 0, 0, |
| 4634 | spk_dac_switch, ARRAY_SIZE(spk_dac_switch), tapan_spk_dac_event, |
| 4635 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4636 | |
| 4637 | SND_SOC_DAPM_PGA_E("SPK PA", SND_SOC_NOPM, 0, 0 , NULL, |
| 4638 | 0, tapan_codec_enable_spk_pa, |
| 4639 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4640 | |
| 4641 | SND_SOC_DAPM_SUPPLY("VDD_SPKDRV", SND_SOC_NOPM, 0, 0, |
| 4642 | tapan_codec_enable_vdd_spkr, |
| 4643 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4644 | |
| 4645 | SND_SOC_DAPM_OUTPUT("EAR"), |
| 4646 | SND_SOC_DAPM_OUTPUT("HEADPHONE"), |
| 4647 | SND_SOC_DAPM_OUTPUT("LINEOUT1"), |
| 4648 | SND_SOC_DAPM_OUTPUT("LINEOUT2"), |
| 4649 | SND_SOC_DAPM_OUTPUT("SPK_OUT"), |
| 4650 | |
| 4651 | /* TX Path*/ |
| 4652 | SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0, |
| 4653 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 4654 | |
| 4655 | SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0, |
| 4656 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 4657 | |
| 4658 | SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0, |
| 4659 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 4660 | |
| 4661 | SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, TAPAN_TX1, 0, |
| 4662 | &sb_tx1_mux), |
| 4663 | SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, TAPAN_TX2, 0, |
| 4664 | &sb_tx2_mux), |
| 4665 | SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, TAPAN_TX3, 0, |
| 4666 | &sb_tx3_mux), |
| 4667 | SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, TAPAN_TX4, 0, |
| 4668 | &sb_tx4_mux), |
| 4669 | SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, TAPAN_TX5, 0, |
| 4670 | &sb_tx5_mux), |
| 4671 | |
| 4672 | SND_SOC_DAPM_SUPPLY("CDC_CONN", WCD9XXX_A_CDC_CLK_OTHR_CTL, 2, 0, NULL, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4673 | 0), |
| 4674 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4675 | /* Decimator MUX */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4676 | SND_SOC_DAPM_MUX_E("DEC1 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0, 0, |
| 4677 | &dec1_mux, tapan_codec_enable_dec, |
| 4678 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4679 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 4680 | |
| 4681 | SND_SOC_DAPM_MUX_E("DEC2 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 1, 0, |
| 4682 | &dec2_mux, tapan_codec_enable_dec, |
| 4683 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4684 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 4685 | |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 4686 | SND_SOC_DAPM_SUPPLY("LDO_H", SND_SOC_NOPM, 7, 0, |
| 4687 | tapan_codec_enable_ldo_h, |
| 4688 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4689 | |
| 4690 | /* |
| 4691 | * DAPM 'LDO_H Standalone' is to be powered by mbhc driver after |
| 4692 | * acquring codec_resource lock. |
| 4693 | * So call __tapan_codec_enable_ldo_h instead and avoid deadlock. |
| 4694 | */ |
| 4695 | SND_SOC_DAPM_SUPPLY("LDO_H Standalone", SND_SOC_NOPM, 7, 0, |
| 4696 | __tapan_codec_enable_ldo_h, |
| 4697 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4698 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4699 | SND_SOC_DAPM_INPUT("AMIC1"), |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 4700 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", SND_SOC_NOPM, 7, 0, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4701 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4702 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 4703 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", SND_SOC_NOPM, 7, 0, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4704 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4705 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 4706 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", SND_SOC_NOPM, 7, 0, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4707 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4708 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4709 | |
| 4710 | SND_SOC_DAPM_ADC_E("ADC1", NULL, TAPAN_A_TX_1_EN, 7, 0, |
| 4711 | tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 4712 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4713 | SND_SOC_DAPM_ADC_E("ADC2", NULL, TAPAN_A_TX_2_EN, 7, 0, |
| 4714 | tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 4715 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4716 | |
| 4717 | SND_SOC_DAPM_INPUT("AMIC3"), |
| 4718 | SND_SOC_DAPM_ADC_E("ADC3", NULL, TAPAN_A_TX_3_EN, 7, 0, |
| 4719 | tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 4720 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4721 | |
| 4722 | SND_SOC_DAPM_INPUT("AMIC4"), |
| 4723 | SND_SOC_DAPM_ADC_E("ADC4", NULL, TAPAN_A_TX_4_EN, 7, 0, |
| 4724 | tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 4725 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4726 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4727 | SND_SOC_DAPM_INPUT("AMIC2"), |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 4728 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", SND_SOC_NOPM, 7, 0, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4729 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4730 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 4731 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", SND_SOC_NOPM, 7, 0, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4732 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4733 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 4734 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", SND_SOC_NOPM, 7, 0, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4735 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4736 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 4737 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", SND_SOC_NOPM, 7, 0, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4738 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4739 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4740 | |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 4741 | SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS2_EXTERNAL_STANDALONE, SND_SOC_NOPM, |
| 4742 | 7, 0, tapan_codec_enable_micbias, |
| 4743 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4744 | SND_SOC_DAPM_POST_PMD), |
| 4745 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4746 | SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM, |
| 4747 | AIF1_CAP, 0, tapan_codec_enable_slimtx, |
| 4748 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4749 | |
| 4750 | SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM, |
| 4751 | AIF2_CAP, 0, tapan_codec_enable_slimtx, |
| 4752 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4753 | |
| 4754 | SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM, |
| 4755 | AIF3_CAP, 0, tapan_codec_enable_slimtx, |
| 4756 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4757 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4758 | /* Digital Mic Inputs */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4759 | SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0, |
| 4760 | tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4761 | SND_SOC_DAPM_POST_PMD), |
| 4762 | |
| 4763 | SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0, |
| 4764 | tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4765 | SND_SOC_DAPM_POST_PMD), |
| 4766 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4767 | /* Sidetone */ |
Shruthi Krishna | efb0a1c | 2014-03-26 18:33:31 -0700 | [diff] [blame] | 4768 | SND_SOC_DAPM_MUX_E("IIR1 INP1 MUX", TAPAN_A_CDC_IIR1_GAIN_B1_CTL, 0, 0, |
| 4769 | &iir1_inp1_mux, tapan_codec_iir_mux_event, |
| 4770 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4771 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4772 | SND_SOC_DAPM_PGA("IIR1", TAPAN_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0), |
| 4773 | |
| 4774 | /* AUX PGA */ |
| 4775 | SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TAPAN_A_RX_AUX_SW_CTL, 7, 0, |
| 4776 | tapan_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 4777 | SND_SOC_DAPM_POST_PMD), |
| 4778 | |
| 4779 | SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TAPAN_A_RX_AUX_SW_CTL, 6, 0, |
| 4780 | tapan_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 4781 | SND_SOC_DAPM_POST_PMD), |
| 4782 | |
| 4783 | /* Lineout, ear and HPH PA Mixers */ |
| 4784 | |
| 4785 | SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4786 | ear_pa_mix, ARRAY_SIZE(ear_pa_mix)), |
| 4787 | |
| 4788 | SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4789 | hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)), |
| 4790 | |
| 4791 | SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4792 | hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)), |
| 4793 | |
| 4794 | SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4795 | lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)), |
| 4796 | |
| 4797 | SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4798 | lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4799 | }; |
| 4800 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4801 | static irqreturn_t tapan_slimbus_irq(int irq, void *data) |
| 4802 | { |
| 4803 | struct tapan_priv *priv = data; |
| 4804 | struct snd_soc_codec *codec = priv->codec; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4805 | unsigned long status = 0; |
| 4806 | int i, j, port_id, k; |
| 4807 | u32 bit; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4808 | u8 val; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4809 | bool tx, cleared; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4810 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4811 | for (i = TAPAN_SLIM_PGD_PORT_INT_STATUS_RX_0, j = 0; |
| 4812 | i <= TAPAN_SLIM_PGD_PORT_INT_STATUS_TX_1; i++, j++) { |
| 4813 | val = wcd9xxx_interface_reg_read(codec->control_data, i); |
| 4814 | status |= ((u32)val << (8 * j)); |
| 4815 | } |
| 4816 | |
| 4817 | for_each_set_bit(j, &status, 32) { |
| 4818 | tx = (j >= 16 ? true : false); |
| 4819 | port_id = (tx ? j - 16 : j); |
| 4820 | val = wcd9xxx_interface_reg_read(codec->control_data, |
| 4821 | TAPAN_SLIM_PGD_PORT_INT_RX_SOURCE0 + j); |
| 4822 | if (val & TAPAN_SLIM_IRQ_OVERFLOW) |
| 4823 | pr_err_ratelimited( |
| 4824 | "%s: overflow error on %s port %d, value %x\n", |
| 4825 | __func__, (tx ? "TX" : "RX"), port_id, val); |
| 4826 | if (val & TAPAN_SLIM_IRQ_UNDERFLOW) |
| 4827 | pr_err_ratelimited( |
| 4828 | "%s: underflow error on %s port %d, value %x\n", |
| 4829 | __func__, (tx ? "TX" : "RX"), port_id, val); |
| 4830 | if (val & TAPAN_SLIM_IRQ_PORT_CLOSED) { |
| 4831 | /* |
| 4832 | * INT SOURCE register starts from RX to TX |
| 4833 | * but port number in the ch_mask is in opposite way |
| 4834 | */ |
| 4835 | bit = (tx ? j - 16 : j + 16); |
| 4836 | dev_dbg(codec->dev, "%s: %s port %d closed value %x, bit %u\n", |
| 4837 | __func__, (tx ? "TX" : "RX"), port_id, val, |
| 4838 | bit); |
| 4839 | for (k = 0, cleared = false; k < NUM_CODEC_DAIS; k++) { |
| 4840 | dev_dbg(codec->dev, "%s: priv->dai[%d].ch_mask = 0x%lx\n", |
| 4841 | __func__, k, priv->dai[k].ch_mask); |
| 4842 | if (test_and_clear_bit(bit, |
| 4843 | &priv->dai[k].ch_mask)) { |
| 4844 | cleared = true; |
| 4845 | if (!priv->dai[k].ch_mask) |
| 4846 | wake_up(&priv->dai[k].dai_wait); |
| 4847 | /* |
| 4848 | * There are cases when multiple DAIs |
| 4849 | * might be using the same slimbus |
| 4850 | * channel. Hence don't break here. |
| 4851 | */ |
| 4852 | } |
| 4853 | } |
| 4854 | WARN(!cleared, |
| 4855 | "Couldn't find slimbus %s port %d for closing\n", |
| 4856 | (tx ? "TX" : "RX"), port_id); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4857 | } |
| 4858 | wcd9xxx_interface_reg_write(codec->control_data, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4859 | TAPAN_SLIM_PGD_PORT_INT_CLR_RX_0 + |
| 4860 | (j / 8), |
| 4861 | 1 << (j % 8)); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4862 | } |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4863 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4864 | return IRQ_HANDLED; |
| 4865 | } |
| 4866 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4867 | static int tapan_handle_pdata(struct tapan_priv *tapan) |
| 4868 | { |
| 4869 | struct snd_soc_codec *codec = tapan->codec; |
| 4870 | struct wcd9xxx_pdata *pdata = tapan->resmgr.pdata; |
| 4871 | int k1, k2, k3, rc = 0; |
Aravind Kumar | 320ef3a | 2014-03-21 12:32:34 +0530 | [diff] [blame] | 4872 | u8 txfe_bypass; |
| 4873 | u8 txfe_buff; |
| 4874 | u8 flag; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4875 | u8 i = 0, j = 0; |
| 4876 | u8 val_txfe = 0, value = 0; |
Damir Didjusto | 5f553e9 | 2013-10-02 14:54:31 -0700 | [diff] [blame] | 4877 | u8 dmic_sample_rate_value = 0; |
| 4878 | u8 dmic_b1_ctl_value = 0; |
| 4879 | u8 anc_ctl_value = 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4880 | |
| 4881 | if (!pdata) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4882 | dev_err(codec->dev, "%s: NULL pdata\n", __func__); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4883 | rc = -ENODEV; |
| 4884 | goto done; |
| 4885 | } |
Aravind Kumar | 320ef3a | 2014-03-21 12:32:34 +0530 | [diff] [blame] | 4886 | txfe_bypass = pdata->amic_settings.txfe_enable; |
| 4887 | txfe_buff = pdata->amic_settings.txfe_buff; |
| 4888 | flag = pdata->amic_settings.use_pdata; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4889 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4890 | /* Make sure settings are correct */ |
| 4891 | if ((pdata->micbias.ldoh_v > WCD9XXX_LDOH_3P0_V) || |
| 4892 | (pdata->micbias.bias1_cfilt_sel > WCD9XXX_CFILT3_SEL) || |
| 4893 | (pdata->micbias.bias2_cfilt_sel > WCD9XXX_CFILT3_SEL) || |
| 4894 | (pdata->micbias.bias3_cfilt_sel > WCD9XXX_CFILT3_SEL)) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4895 | dev_err(codec->dev, "%s: Invalid ldoh voltage or bias cfilt\n", |
| 4896 | __func__); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4897 | rc = -EINVAL; |
| 4898 | goto done; |
| 4899 | } |
| 4900 | /* figure out k value */ |
| 4901 | k1 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt1_mv); |
| 4902 | k2 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt2_mv); |
| 4903 | k3 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt3_mv); |
| 4904 | |
| 4905 | if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4906 | dev_err(codec->dev, |
| 4907 | "%s: could not get K value. k1 = %d k2 = %d k3 = %d\n", |
| 4908 | __func__, k1, k2, k3); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4909 | rc = -EINVAL; |
| 4910 | goto done; |
| 4911 | } |
| 4912 | /* Set voltage level and always use LDO */ |
| 4913 | snd_soc_update_bits(codec, TAPAN_A_LDO_H_MODE_1, 0x0C, |
| 4914 | (pdata->micbias.ldoh_v << 2)); |
| 4915 | |
| 4916 | snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_1_VAL, 0xFC, (k1 << 2)); |
| 4917 | snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_2_VAL, 0xFC, (k2 << 2)); |
| 4918 | snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_3_VAL, 0xFC, (k3 << 2)); |
| 4919 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4920 | i = 0; |
| 4921 | while (i < 5) { |
| 4922 | if (flag & (0x01 << i)) { |
| 4923 | val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00; |
| 4924 | val_txfe = val_txfe | |
| 4925 | ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00); |
| 4926 | snd_soc_update_bits(codec, |
| 4927 | TAPAN_A_TX_1_2_TEST_EN + j * 10, |
| 4928 | 0x30, val_txfe); |
| 4929 | } |
| 4930 | if (flag & (0x01 << (i + 1))) { |
| 4931 | val_txfe = (txfe_bypass & |
| 4932 | (0x01 << (i + 1))) ? 0x02 : 0x00; |
| 4933 | val_txfe |= (txfe_buff & |
| 4934 | (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 4935 | snd_soc_update_bits(codec, |
| 4936 | TAPAN_A_TX_1_2_TEST_EN + j * 10, |
| 4937 | 0x03, val_txfe); |
| 4938 | } |
| 4939 | /* Tapan only has TAPAN_A_TX_1_2_TEST_EN and |
| 4940 | TAPAN_A_TX_4_5_TEST_EN reg */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4941 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4942 | if (i == 0) { |
| 4943 | i = 3; |
| 4944 | continue; |
| 4945 | } else if (i == 3) { |
| 4946 | break; |
| 4947 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4948 | } |
| 4949 | |
| 4950 | if (pdata->ocp.use_pdata) { |
| 4951 | /* not defined in CODEC specification */ |
| 4952 | if (pdata->ocp.hph_ocp_limit == 1 || |
| 4953 | pdata->ocp.hph_ocp_limit == 5) { |
| 4954 | rc = -EINVAL; |
| 4955 | goto done; |
| 4956 | } |
| 4957 | snd_soc_update_bits(codec, TAPAN_A_RX_COM_OCP_CTL, |
| 4958 | 0x0F, pdata->ocp.num_attempts); |
| 4959 | snd_soc_write(codec, TAPAN_A_RX_COM_OCP_COUNT, |
| 4960 | ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time)); |
| 4961 | snd_soc_update_bits(codec, TAPAN_A_RX_HPH_OCP_CTL, |
| 4962 | 0xE0, (pdata->ocp.hph_ocp_limit << 5)); |
| 4963 | } |
| 4964 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4965 | /* Set micbias capless mode with tail current */ |
| 4966 | value = (pdata->micbias.bias1_cap_mode == MICBIAS_EXT_BYP_CAP ? |
| 4967 | 0x00 : 0x10); |
| 4968 | snd_soc_update_bits(codec, TAPAN_A_MICB_1_CTL, 0x10, value); |
| 4969 | value = (pdata->micbias.bias2_cap_mode == MICBIAS_EXT_BYP_CAP ? |
| 4970 | 0x00 : 0x10); |
| 4971 | snd_soc_update_bits(codec, TAPAN_A_MICB_2_CTL, 0x10, value); |
| 4972 | value = (pdata->micbias.bias3_cap_mode == MICBIAS_EXT_BYP_CAP ? |
| 4973 | 0x00 : 0x10); |
| 4974 | snd_soc_update_bits(codec, TAPAN_A_MICB_3_CTL, 0x10, value); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4975 | |
Damir Didjusto | 5f553e9 | 2013-10-02 14:54:31 -0700 | [diff] [blame] | 4976 | /* Set the DMIC sample rate */ |
| 4977 | if (pdata->mclk_rate == TAPAN_MCLK_CLK_9P6MHZ) { |
| 4978 | switch (pdata->dmic_sample_rate) { |
| 4979 | case WCD9XXX_DMIC_SAMPLE_RATE_2P4MHZ: |
| 4980 | dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_4; |
| 4981 | dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_4; |
| 4982 | anc_ctl_value = WCD9XXX_ANC_DMIC_X2_OFF; |
| 4983 | break; |
| 4984 | case WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ: |
| 4985 | dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_2; |
| 4986 | dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_2; |
| 4987 | anc_ctl_value = WCD9XXX_ANC_DMIC_X2_ON; |
| 4988 | break; |
| 4989 | case WCD9XXX_DMIC_SAMPLE_RATE_3P2MHZ: |
| 4990 | case WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED: |
| 4991 | dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_3; |
| 4992 | dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_3; |
| 4993 | anc_ctl_value = WCD9XXX_ANC_DMIC_X2_OFF; |
| 4994 | break; |
| 4995 | default: |
| 4996 | dev_err(codec->dev, |
| 4997 | "%s Invalid sample rate %d for mclk %d\n", |
| 4998 | __func__, pdata->dmic_sample_rate, |
| 4999 | pdata->mclk_rate); |
| 5000 | rc = -EINVAL; |
| 5001 | goto done; |
| 5002 | } |
| 5003 | } else if (pdata->mclk_rate == TAPAN_MCLK_CLK_12P288MHZ) { |
| 5004 | switch (pdata->dmic_sample_rate) { |
| 5005 | case WCD9XXX_DMIC_SAMPLE_RATE_3P072MHZ: |
| 5006 | dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_4; |
| 5007 | dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_4; |
| 5008 | anc_ctl_value = WCD9XXX_ANC_DMIC_X2_OFF; |
| 5009 | break; |
| 5010 | case WCD9XXX_DMIC_SAMPLE_RATE_6P144MHZ: |
| 5011 | dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_2; |
| 5012 | dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_2; |
| 5013 | anc_ctl_value = WCD9XXX_ANC_DMIC_X2_ON; |
| 5014 | break; |
| 5015 | case WCD9XXX_DMIC_SAMPLE_RATE_4P096MHZ: |
| 5016 | case WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED: |
| 5017 | dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_3; |
| 5018 | dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_3; |
| 5019 | anc_ctl_value = WCD9XXX_ANC_DMIC_X2_OFF; |
| 5020 | break; |
| 5021 | default: |
| 5022 | dev_err(codec->dev, |
| 5023 | "%s Invalid sample rate %d for mclk %d\n", |
| 5024 | __func__, pdata->dmic_sample_rate, |
| 5025 | pdata->mclk_rate); |
| 5026 | rc = -EINVAL; |
| 5027 | goto done; |
| 5028 | } |
| 5029 | } else { |
| 5030 | dev_err(codec->dev, "%s MCLK is not set!\n", __func__); |
| 5031 | rc = -EINVAL; |
| 5032 | goto done; |
| 5033 | } |
| 5034 | |
| 5035 | snd_soc_update_bits(codec, TAPAN_A_CDC_TX1_DMIC_CTL, |
| 5036 | 0x7, dmic_sample_rate_value); |
| 5037 | snd_soc_update_bits(codec, TAPAN_A_CDC_TX2_DMIC_CTL, |
| 5038 | 0x7, dmic_sample_rate_value); |
| 5039 | snd_soc_update_bits(codec, TAPAN_A_CDC_TX3_DMIC_CTL, |
| 5040 | 0x7, dmic_sample_rate_value); |
| 5041 | snd_soc_update_bits(codec, TAPAN_A_CDC_TX4_DMIC_CTL, |
| 5042 | 0x7, dmic_sample_rate_value); |
| 5043 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_DMIC_B1_CTL, |
| 5044 | 0xEE, dmic_b1_ctl_value); |
| 5045 | snd_soc_update_bits(codec, TAPAN_A_CDC_ANC1_B2_CTL, |
| 5046 | 0x1, anc_ctl_value); |
| 5047 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5048 | done: |
| 5049 | return rc; |
| 5050 | } |
| 5051 | |
| 5052 | static const struct tapan_reg_mask_val tapan_reg_defaults[] = { |
| 5053 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5054 | /* enable QFUSE for wcd9306 */ |
| 5055 | TAPAN_REG_VAL(TAPAN_A_QFUSE_CTL, 0x03), |
| 5056 | |
| 5057 | /* PROGRAM_THE_0P85V_VBG_REFERENCE = V_0P858V */ |
| 5058 | TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x04), |
| 5059 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5060 | TAPAN_REG_VAL(TAPAN_A_CDC_CLK_POWER_CTL, 0x03), |
| 5061 | |
| 5062 | /* EAR PA deafults */ |
| 5063 | TAPAN_REG_VAL(TAPAN_A_RX_EAR_CMBUFF, 0x05), |
| 5064 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5065 | /* RX1 and RX2 defaults */ |
| 5066 | TAPAN_REG_VAL(TAPAN_A_CDC_RX1_B6_CTL, 0xA0), |
| 5067 | TAPAN_REG_VAL(TAPAN_A_CDC_RX2_B6_CTL, 0xA0), |
| 5068 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5069 | /* Heaset set Right from RX2 */ |
| 5070 | TAPAN_REG_VAL(TAPAN_A_CDC_CONN_RX2_B2_CTL, 0x10), |
| 5071 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5072 | |
| 5073 | /* |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5074 | * The following only need to be written for Tapan 1.0 parts. |
| 5075 | * Tapan 2.0 will have appropriate defaults for these registers. |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5076 | */ |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5077 | |
| 5078 | /* Required defaults for class H operation */ |
| 5079 | /* borrowed from Taiko class-h */ |
| 5080 | TAPAN_REG_VAL(TAPAN_A_RX_HPH_CHOP_CTL, 0xF4), |
| 5081 | TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x08), |
| 5082 | TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_1, 0x5B), |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 5083 | TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_3, 0x6F), |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5084 | |
| 5085 | /* TODO: Check below reg writes conflict with above */ |
| 5086 | /* PROGRAM_THE_0P85V_VBG_REFERENCE = V_0P858V */ |
| 5087 | TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x04), |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5088 | TAPAN_REG_VAL(TAPAN_A_RX_HPH_CHOP_CTL, 0x74), |
| 5089 | TAPAN_REG_VAL(TAPAN_A_RX_BUCK_BIAS1, 0x62), |
| 5090 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5091 | /* Choose max non-overlap time for NCP */ |
| 5092 | TAPAN_REG_VAL(TAPAN_A_NCP_CLK, 0xFC), |
| 5093 | /* Use 25mV/50mV for deltap/m to reduce ripple */ |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5094 | TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_VCL_1, 0x08), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5095 | /* |
| 5096 | * Set DISABLE_MODE_SEL<1:0> to 0b10 (disable PWM in auto mode). |
| 5097 | * Note that the other bits of this register will be changed during |
| 5098 | * Rx PA bring up. |
| 5099 | */ |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5100 | TAPAN_REG_VAL(WCD9XXX_A_BUCK_MODE_3, 0xCE), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5101 | /* Reduce HPH DAC bias to 70% */ |
| 5102 | TAPAN_REG_VAL(TAPAN_A_RX_HPH_BIAS_PA, 0x7A), |
| 5103 | /*Reduce EAR DAC bias to 70% */ |
| 5104 | TAPAN_REG_VAL(TAPAN_A_RX_EAR_BIAS_PA, 0x76), |
| 5105 | /* Reduce LINE DAC bias to 70% */ |
| 5106 | TAPAN_REG_VAL(TAPAN_A_RX_LINE_BIAS_PA, 0x78), |
| 5107 | |
| 5108 | /* |
| 5109 | * There is a diode to pull down the micbias while doing |
| 5110 | * insertion detection. This diode can cause leakage. |
| 5111 | * Set bit 0 to 1 to prevent leakage. |
| 5112 | * Setting this bit of micbias 2 prevents leakage for all other micbias. |
| 5113 | */ |
| 5114 | TAPAN_REG_VAL(TAPAN_A_MICB_2_MBHC, 0x41), |
| 5115 | |
Bhalchandra Gajare | 7c73952 | 2013-06-20 15:31:02 -0700 | [diff] [blame] | 5116 | /* |
| 5117 | * Default register settings to support dynamic change of |
| 5118 | * vdd_buck between 1.8 volts and 2.15 volts. |
| 5119 | */ |
| 5120 | TAPAN_REG_VAL(TAPAN_A_BUCK_MODE_2, 0xAA), |
| 5121 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5122 | }; |
| 5123 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5124 | static const struct tapan_reg_mask_val tapan_2_x_reg_reset_values[] = { |
| 5125 | |
| 5126 | TAPAN_REG_VAL(TAPAN_A_TX_7_MBHC_EN, 0x6C), |
| 5127 | TAPAN_REG_VAL(TAPAN_A_BUCK_CTRL_CCL_4, 0x51), |
| 5128 | TAPAN_REG_VAL(TAPAN_A_RX_HPH_CNP_WG_CTL, 0xDA), |
| 5129 | TAPAN_REG_VAL(TAPAN_A_RX_EAR_CNP, 0xC0), |
| 5130 | TAPAN_REG_VAL(TAPAN_A_RX_LINE_1_TEST, 0x02), |
| 5131 | TAPAN_REG_VAL(TAPAN_A_RX_LINE_2_TEST, 0x02), |
| 5132 | TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_OCP_CTL, 0x97), |
| 5133 | TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_CLIP_DET, 0x01), |
| 5134 | TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_IEC, 0x00), |
| 5135 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B1_CTL, 0xE4), |
| 5136 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B2_CTL, 0x00), |
| 5137 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B3_CTL, 0x00), |
| 5138 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_BUCK_NCP_VARS, 0x00), |
| 5139 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_HD_EAR, 0x00), |
| 5140 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_HD_HPH, 0x00), |
| 5141 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_MIN_EAR, 0x00), |
| 5142 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_MIN_HPH, 0x00), |
| 5143 | }; |
| 5144 | |
| 5145 | static const struct tapan_reg_mask_val tapan_1_0_reg_defaults[] = { |
| 5146 | /* Close leakage on the spkdrv */ |
| 5147 | TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_DBG_PWRSTG, 0x24), |
| 5148 | TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_DBG_DAC, 0xE5), |
| 5149 | |
| 5150 | }; |
| 5151 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5152 | static void tapan_update_reg_defaults(struct snd_soc_codec *codec) |
| 5153 | { |
| 5154 | u32 i; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5155 | struct wcd9xxx *tapan_core = dev_get_drvdata(codec->dev->parent); |
| 5156 | |
| 5157 | if (!TAPAN_IS_1_0(tapan_core->version)) { |
| 5158 | for (i = 0; i < ARRAY_SIZE(tapan_2_x_reg_reset_values); i++) |
| 5159 | snd_soc_write(codec, tapan_2_x_reg_reset_values[i].reg, |
| 5160 | tapan_2_x_reg_reset_values[i].val); |
| 5161 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5162 | |
| 5163 | for (i = 0; i < ARRAY_SIZE(tapan_reg_defaults); i++) |
| 5164 | snd_soc_write(codec, tapan_reg_defaults[i].reg, |
| 5165 | tapan_reg_defaults[i].val); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5166 | |
| 5167 | if (TAPAN_IS_1_0(tapan_core->version)) { |
| 5168 | for (i = 0; i < ARRAY_SIZE(tapan_1_0_reg_defaults); i++) |
| 5169 | snd_soc_write(codec, tapan_1_0_reg_defaults[i].reg, |
| 5170 | tapan_1_0_reg_defaults[i].val); |
| 5171 | } |
| 5172 | |
| 5173 | if (!TAPAN_IS_1_0(tapan_core->version)) |
| 5174 | spkr_drv_wrnd = -1; |
| 5175 | else if (spkr_drv_wrnd == 1) |
| 5176 | snd_soc_write(codec, TAPAN_A_SPKR_DRV_EN, 0xEF); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5177 | } |
| 5178 | |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5179 | static void tapan_update_reg_mclk_rate(struct wcd9xxx *wcd9xxx) |
| 5180 | { |
| 5181 | struct snd_soc_codec *codec; |
| 5182 | |
| 5183 | codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv); |
| 5184 | dev_dbg(codec->dev, "%s: MCLK Rate = %x\n", |
| 5185 | __func__, wcd9xxx->mclk_rate); |
| 5186 | |
| 5187 | if (wcd9xxx->mclk_rate == TAPAN_MCLK_CLK_12P288MHZ) { |
| 5188 | snd_soc_update_bits(codec, TAPAN_A_CHIP_CTL, 0x06, 0x0); |
| 5189 | snd_soc_update_bits(codec, TAPAN_A_RX_COM_TIMER_DIV, 0x01, |
| 5190 | 0x01); |
| 5191 | } else if (wcd9xxx->mclk_rate == TAPAN_MCLK_CLK_9P6MHZ) { |
| 5192 | snd_soc_update_bits(codec, TAPAN_A_CHIP_CTL, 0x06, 0x2); |
| 5193 | } |
| 5194 | } |
| 5195 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5196 | static const struct tapan_reg_mask_val tapan_codec_reg_init_val[] = { |
Phani Kumar Uppalapati | eca9a10 | 2013-06-18 11:02:38 -0700 | [diff] [blame] | 5197 | /* Initialize current threshold to 365MA |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5198 | * number of wait and run cycles to 4096 |
| 5199 | */ |
Phani Kumar Uppalapati | eca9a10 | 2013-06-18 11:02:38 -0700 | [diff] [blame] | 5200 | {TAPAN_A_RX_HPH_OCP_CTL, 0xE9, 0x69}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5201 | {TAPAN_A_RX_COM_OCP_COUNT, 0xFF, 0xFF}, |
Phani Kumar Uppalapati | eca9a10 | 2013-06-18 11:02:38 -0700 | [diff] [blame] | 5202 | {TAPAN_A_RX_HPH_L_TEST, 0x01, 0x01}, |
| 5203 | {TAPAN_A_RX_HPH_R_TEST, 0x01, 0x01}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5204 | |
| 5205 | /* Initialize gain registers to use register gain */ |
| 5206 | {TAPAN_A_RX_HPH_L_GAIN, 0x20, 0x20}, |
| 5207 | {TAPAN_A_RX_HPH_R_GAIN, 0x20, 0x20}, |
| 5208 | {TAPAN_A_RX_LINE_1_GAIN, 0x20, 0x20}, |
| 5209 | {TAPAN_A_RX_LINE_2_GAIN, 0x20, 0x20}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5210 | {TAPAN_A_SPKR_DRV_GAIN, 0x04, 0x04}, |
| 5211 | |
| 5212 | /* Set RDAC5 MUX to take input from DEM3_INV. |
| 5213 | * This sets LO2 DAC to get input from DEM3_INV |
| 5214 | * for LO1 and LO2 to work as differential outputs. |
| 5215 | */ |
| 5216 | {TAPAN_A_CDC_CONN_MISC, 0x04, 0x04}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5217 | |
| 5218 | /* CLASS H config */ |
| 5219 | {TAPAN_A_CDC_CONN_CLSH_CTL, 0x3C, 0x14}, |
| 5220 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5221 | /* Use 16 bit sample size for TX1 to TX5 */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5222 | {TAPAN_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20}, |
| 5223 | {TAPAN_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20}, |
| 5224 | {TAPAN_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20}, |
| 5225 | {TAPAN_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20}, |
| 5226 | {TAPAN_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20}, |
| 5227 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5228 | /* Disable SPK SWITCH */ |
| 5229 | {TAPAN_A_SPKR_DRV_DAC_CTL, 0x04, 0x00}, |
| 5230 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5231 | /* Use 16 bit sample size for RX */ |
| 5232 | {TAPAN_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA}, |
| 5233 | {TAPAN_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0x2A}, |
| 5234 | |
| 5235 | /*enable HPF filter for TX paths */ |
| 5236 | {TAPAN_A_CDC_TX1_MUX_CTL, 0x8, 0x0}, |
| 5237 | {TAPAN_A_CDC_TX2_MUX_CTL, 0x8, 0x0}, |
| 5238 | {TAPAN_A_CDC_TX3_MUX_CTL, 0x8, 0x0}, |
| 5239 | {TAPAN_A_CDC_TX4_MUX_CTL, 0x8, 0x0}, |
| 5240 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5241 | /* Compander zone selection */ |
| 5242 | {TAPAN_A_CDC_COMP0_B4_CTL, 0x3F, 0x37}, |
| 5243 | {TAPAN_A_CDC_COMP1_B4_CTL, 0x3F, 0x37}, |
| 5244 | {TAPAN_A_CDC_COMP2_B4_CTL, 0x3F, 0x37}, |
| 5245 | {TAPAN_A_CDC_COMP0_B5_CTL, 0x7F, 0x7F}, |
| 5246 | {TAPAN_A_CDC_COMP1_B5_CTL, 0x7F, 0x7F}, |
| 5247 | {TAPAN_A_CDC_COMP2_B5_CTL, 0x7F, 0x7F}, |
Banajit Goswami | a729445 | 2013-06-03 12:42:35 -0700 | [diff] [blame] | 5248 | |
| 5249 | /* |
| 5250 | * Setup wavegen timer to 20msec and disable chopper |
| 5251 | * as default. This corresponds to Compander OFF |
| 5252 | */ |
| 5253 | {TAPAN_A_RX_HPH_CNP_WG_CTL, 0xFF, 0xDB}, |
| 5254 | {TAPAN_A_RX_HPH_CNP_WG_TIME, 0xFF, 0x58}, |
| 5255 | {TAPAN_A_RX_HPH_BIAS_WG_OCP, 0xFF, 0x1A}, |
| 5256 | {TAPAN_A_RX_HPH_CHOP_CTL, 0xFF, 0x24}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5257 | }; |
| 5258 | |
Damir Didjusto | d6aea99 | 2013-09-03 21:18:59 -0700 | [diff] [blame] | 5259 | void *tapan_get_afe_config(struct snd_soc_codec *codec, |
| 5260 | enum afe_config_type config_type) |
| 5261 | { |
| 5262 | struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec); |
| 5263 | |
| 5264 | switch (config_type) { |
| 5265 | case AFE_SLIMBUS_SLAVE_CONFIG: |
| 5266 | return &priv->slimbus_slave_cfg; |
| 5267 | case AFE_CDC_REGISTERS_CONFIG: |
| 5268 | return &tapan_audio_reg_cfg; |
| 5269 | case AFE_AANC_VERSION: |
| 5270 | return &tapan_cdc_aanc_version; |
| 5271 | default: |
| 5272 | pr_err("%s: Unknown config_type 0x%x\n", __func__, config_type); |
| 5273 | return NULL; |
| 5274 | } |
| 5275 | } |
| 5276 | |
| 5277 | static void tapan_init_slim_slave_cfg(struct snd_soc_codec *codec) |
| 5278 | { |
| 5279 | struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec); |
| 5280 | struct afe_param_cdc_slimbus_slave_cfg *cfg; |
| 5281 | struct wcd9xxx *wcd9xxx = codec->control_data; |
| 5282 | uint64_t eaddr = 0; |
| 5283 | |
| 5284 | pr_debug("%s\n", __func__); |
| 5285 | cfg = &priv->slimbus_slave_cfg; |
| 5286 | cfg->minor_version = 1; |
| 5287 | cfg->tx_slave_port_offset = 0; |
| 5288 | cfg->rx_slave_port_offset = 16; |
| 5289 | |
| 5290 | memcpy(&eaddr, &wcd9xxx->slim->e_addr, sizeof(wcd9xxx->slim->e_addr)); |
| 5291 | /* e-addr is 6-byte elemental address of the device */ |
| 5292 | WARN_ON(sizeof(wcd9xxx->slim->e_addr) != 6); |
| 5293 | cfg->device_enum_addr_lsw = eaddr & 0xFFFFFFFF; |
| 5294 | cfg->device_enum_addr_msw = eaddr >> 32; |
| 5295 | |
| 5296 | pr_debug("%s: slimbus logical address 0x%llx\n", __func__, eaddr); |
| 5297 | } |
| 5298 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5299 | static void tapan_codec_init_reg(struct snd_soc_codec *codec) |
| 5300 | { |
| 5301 | u32 i; |
| 5302 | |
| 5303 | for (i = 0; i < ARRAY_SIZE(tapan_codec_reg_init_val); i++) |
| 5304 | snd_soc_update_bits(codec, tapan_codec_reg_init_val[i].reg, |
| 5305 | tapan_codec_reg_init_val[i].mask, |
| 5306 | tapan_codec_reg_init_val[i].val); |
| 5307 | } |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5308 | static void tapan_slim_interface_init_reg(struct snd_soc_codec *codec) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5309 | { |
| 5310 | int i; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5311 | |
| 5312 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) |
| 5313 | wcd9xxx_interface_reg_write(codec->control_data, |
| 5314 | TAPAN_SLIM_PGD_PORT_INT_EN0 + i, |
| 5315 | 0xFF); |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5316 | } |
| 5317 | |
| 5318 | static int tapan_setup_irqs(struct tapan_priv *tapan) |
| 5319 | { |
| 5320 | int ret = 0; |
| 5321 | struct snd_soc_codec *codec = tapan->codec; |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5322 | struct wcd9xxx *wcd9xxx = codec->control_data; |
| 5323 | struct wcd9xxx_core_resource *core_res = &wcd9xxx->core_res; |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5324 | |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5325 | ret = wcd9xxx_request_irq(core_res, WCD9XXX_IRQ_SLIMBUS, |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5326 | tapan_slimbus_irq, "SLIMBUS Slave", tapan); |
| 5327 | if (ret) |
| 5328 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 5329 | WCD9XXX_IRQ_SLIMBUS); |
| 5330 | else |
| 5331 | tapan_slim_interface_init_reg(codec); |
| 5332 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5333 | return ret; |
| 5334 | } |
| 5335 | |
Ravishankar Sarawadi | 7b70036 | 2013-04-18 15:56:02 -0700 | [diff] [blame] | 5336 | static void tapan_cleanup_irqs(struct tapan_priv *tapan) |
| 5337 | { |
| 5338 | struct snd_soc_codec *codec = tapan->codec; |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5339 | struct wcd9xxx *wcd9xxx = codec->control_data; |
| 5340 | struct wcd9xxx_core_resource *core_res = &wcd9xxx->core_res; |
| 5341 | wcd9xxx_free_irq(core_res, WCD9XXX_IRQ_SLIMBUS, tapan); |
Ravishankar Sarawadi | 7b70036 | 2013-04-18 15:56:02 -0700 | [diff] [blame] | 5342 | } |
| 5343 | |
Simmi Pateriya | 95466b1 | 2013-05-09 20:08:46 +0530 | [diff] [blame] | 5344 | |
| 5345 | static void tapan_enable_mux_bias_block(struct snd_soc_codec *codec) |
| 5346 | { |
| 5347 | snd_soc_update_bits(codec, WCD9XXX_A_MBHC_SCALING_MUX_1, |
| 5348 | 0x80, 0x00); |
| 5349 | } |
| 5350 | |
| 5351 | static void tapan_put_cfilt_fast_mode(struct snd_soc_codec *codec, |
| 5352 | struct wcd9xxx_mbhc *mbhc) |
| 5353 | { |
| 5354 | snd_soc_update_bits(codec, mbhc->mbhc_bias_regs.cfilt_ctl, |
| 5355 | 0x30, 0x30); |
| 5356 | } |
| 5357 | |
| 5358 | static void tapan_codec_specific_cal_setup(struct snd_soc_codec *codec, |
| 5359 | struct wcd9xxx_mbhc *mbhc) |
| 5360 | { |
| 5361 | snd_soc_update_bits(codec, WCD9XXX_A_CDC_MBHC_B1_CTL, |
Phani Kumar Uppalapati | 1075440 | 2013-07-12 22:48:45 -0700 | [diff] [blame] | 5362 | 0x04, 0x04); |
Simmi Pateriya | 95466b1 | 2013-05-09 20:08:46 +0530 | [diff] [blame] | 5363 | snd_soc_update_bits(codec, WCD9XXX_A_TX_7_MBHC_EN, 0xE0, 0xE0); |
| 5364 | } |
| 5365 | |
Simmi Pateriya | 95466b1 | 2013-05-09 20:08:46 +0530 | [diff] [blame] | 5366 | static struct wcd9xxx_cfilt_mode tapan_codec_switch_cfilt_mode( |
| 5367 | struct wcd9xxx_mbhc *mbhc, |
| 5368 | bool fast) |
| 5369 | { |
| 5370 | struct snd_soc_codec *codec = mbhc->codec; |
| 5371 | struct wcd9xxx_cfilt_mode cfilt_mode; |
| 5372 | |
| 5373 | if (fast) |
| 5374 | cfilt_mode.reg_mode_val = WCD9XXX_CFILT_EXT_PRCHG_EN; |
| 5375 | else |
| 5376 | cfilt_mode.reg_mode_val = WCD9XXX_CFILT_EXT_PRCHG_DSBL; |
| 5377 | |
| 5378 | cfilt_mode.cur_mode_val = |
| 5379 | snd_soc_read(codec, mbhc->mbhc_bias_regs.cfilt_ctl) & 0x30; |
Bhalchandra Gajare | 8e5fe25 | 2013-07-15 19:42:21 -0700 | [diff] [blame] | 5380 | cfilt_mode.reg_mask = 0x30; |
| 5381 | |
Simmi Pateriya | 95466b1 | 2013-05-09 20:08:46 +0530 | [diff] [blame] | 5382 | return cfilt_mode; |
| 5383 | } |
| 5384 | |
| 5385 | static void tapan_select_cfilt(struct snd_soc_codec *codec, |
| 5386 | struct wcd9xxx_mbhc *mbhc) |
| 5387 | { |
| 5388 | snd_soc_update_bits(codec, mbhc->mbhc_bias_regs.ctl_reg, 0x60, 0x00); |
| 5389 | } |
| 5390 | |
Bhalchandra Gajare | 8e5fe25 | 2013-07-15 19:42:21 -0700 | [diff] [blame] | 5391 | enum wcd9xxx_cdc_type tapan_get_cdc_type(void) |
| 5392 | { |
| 5393 | return WCD9XXX_CDC_TYPE_TAPAN; |
Simmi Pateriya | 95466b1 | 2013-05-09 20:08:46 +0530 | [diff] [blame] | 5394 | } |
| 5395 | |
Phani Kumar Uppalapati | 01a77e1 | 2013-08-08 15:31:35 -0700 | [diff] [blame] | 5396 | static void wcd9xxx_prepare_hph_pa(struct wcd9xxx_mbhc *mbhc, |
| 5397 | struct list_head *lh) |
| 5398 | { |
| 5399 | int i; |
| 5400 | struct snd_soc_codec *codec = mbhc->codec; |
| 5401 | u32 delay; |
| 5402 | |
| 5403 | const struct wcd9xxx_reg_mask_val reg_set_paon[] = { |
| 5404 | {WCD9XXX_A_CDC_CLSH_B1_CTL, 0x0F, 0x00}, |
| 5405 | {WCD9XXX_A_RX_HPH_CHOP_CTL, 0xFF, 0xA4}, |
| 5406 | {WCD9XXX_A_RX_HPH_OCP_CTL, 0xFF, 0x67}, |
| 5407 | {WCD9XXX_A_RX_HPH_L_TEST, 0x1, 0x0}, |
| 5408 | {WCD9XXX_A_RX_HPH_R_TEST, 0x1, 0x0}, |
| 5409 | {WCD9XXX_A_RX_HPH_BIAS_WG_OCP, 0xFF, 0x1A}, |
| 5410 | {WCD9XXX_A_RX_HPH_CNP_WG_CTL, 0xFF, 0xDB}, |
| 5411 | {WCD9XXX_A_RX_HPH_CNP_WG_TIME, 0xFF, 0x2A}, |
| 5412 | {TAPAN_A_CDC_CONN_RX2_B2_CTL, 0xFF, 0x10}, |
| 5413 | {WCD9XXX_A_CDC_CLK_OTHR_CTL, 0xFF, 0x05}, |
| 5414 | {WCD9XXX_A_CDC_RX1_B6_CTL, 0xFF, 0x81}, |
| 5415 | {WCD9XXX_A_CDC_CLK_RX_B1_CTL, 0x03, 0x03}, |
| 5416 | {WCD9XXX_A_RX_HPH_L_GAIN, 0xFF, 0x2C}, |
| 5417 | {WCD9XXX_A_CDC_RX2_B6_CTL, 0xFF, 0x81}, |
| 5418 | {WCD9XXX_A_RX_HPH_R_GAIN, 0xFF, 0x2C}, |
| 5419 | {WCD9XXX_A_BUCK_CTRL_CCL_4, 0xFF, 0x50}, |
| 5420 | {WCD9XXX_A_BUCK_CTRL_VCL_1, 0xFF, 0x08}, |
| 5421 | {WCD9XXX_A_BUCK_CTRL_CCL_1, 0xFF, 0x5B}, |
| 5422 | {WCD9XXX_A_NCP_CLK, 0xFF, 0x9C}, |
| 5423 | {WCD9XXX_A_NCP_CLK, 0xFF, 0xFC}, |
| 5424 | {WCD9XXX_A_BUCK_MODE_3, 0xFF, 0xCE}, |
| 5425 | {WCD9XXX_A_BUCK_CTRL_CCL_3, 0xFF, 0x6B}, |
| 5426 | {WCD9XXX_A_BUCK_CTRL_CCL_3, 0xFF, 0x6F}, |
| 5427 | {TAPAN_A_RX_BUCK_BIAS1, 0xFF, 0x62}, |
| 5428 | {TAPAN_A_RX_HPH_BIAS_PA, 0xFF, 0x7A}, |
| 5429 | {TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, 0xFF, 0x02}, |
| 5430 | {TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, 0xFF, 0x06}, |
| 5431 | {WCD9XXX_A_RX_COM_BIAS, 0xFF, 0x80}, |
| 5432 | {WCD9XXX_A_BUCK_MODE_3, 0xFF, 0xC6}, |
| 5433 | {WCD9XXX_A_BUCK_MODE_4, 0xFF, 0xE6}, |
| 5434 | {WCD9XXX_A_BUCK_MODE_5, 0xFF, 0x02}, |
| 5435 | {WCD9XXX_A_BUCK_MODE_1, 0xFF, 0xA1}, |
| 5436 | /* Delay 1ms */ |
| 5437 | {WCD9XXX_A_NCP_EN, 0xFF, 0xFF}, |
| 5438 | /* Delay 1ms */ |
| 5439 | {WCD9XXX_A_BUCK_MODE_5, 0xFF, 0x03}, |
| 5440 | {WCD9XXX_A_BUCK_MODE_5, 0xFF, 0x7B}, |
| 5441 | {WCD9XXX_A_CDC_CLSH_B1_CTL, 0xFF, 0xE6}, |
| 5442 | {WCD9XXX_A_RX_HPH_L_DAC_CTL, 0xFF, 0x40}, |
| 5443 | {WCD9XXX_A_RX_HPH_L_DAC_CTL, 0xFF, 0xC0}, |
| 5444 | {WCD9XXX_A_RX_HPH_R_DAC_CTL, 0xFF, 0x40}, |
| 5445 | {WCD9XXX_A_RX_HPH_R_DAC_CTL, 0xFF, 0xC0}, |
| 5446 | {WCD9XXX_A_NCP_STATIC, 0xFF, 0x08}, |
| 5447 | {WCD9XXX_A_RX_HPH_L_DAC_CTL, 0x03, 0x01}, |
| 5448 | {WCD9XXX_A_RX_HPH_R_DAC_CTL, 0x03, 0x01}, |
| 5449 | }; |
| 5450 | |
| 5451 | /* |
| 5452 | * Configure PA in class-AB, -18dB gain, |
| 5453 | * companding off, OCP off, Chopping ON |
| 5454 | */ |
| 5455 | for (i = 0; i < ARRAY_SIZE(reg_set_paon); i++) { |
| 5456 | /* |
| 5457 | * Some of the codec registers like BUCK_MODE_1 |
| 5458 | * and NCP_EN requires 1ms wait time for them |
| 5459 | * to take effect. Other register writes for |
| 5460 | * PA configuration do not require any wait time. |
| 5461 | */ |
| 5462 | if (reg_set_paon[i].reg == WCD9XXX_A_BUCK_MODE_1 || |
| 5463 | reg_set_paon[i].reg == WCD9XXX_A_NCP_EN) |
| 5464 | delay = 1000; |
| 5465 | else |
| 5466 | delay = 0; |
| 5467 | wcd9xxx_soc_update_bits_push(codec, lh, |
| 5468 | reg_set_paon[i].reg, |
| 5469 | reg_set_paon[i].mask, |
| 5470 | reg_set_paon[i].val, delay); |
| 5471 | } |
| 5472 | pr_debug("%s: PAs are prepared\n", __func__); |
| 5473 | return; |
| 5474 | } |
| 5475 | |
| 5476 | static int wcd9xxx_enable_static_pa(struct wcd9xxx_mbhc *mbhc, bool enable) |
| 5477 | { |
| 5478 | struct snd_soc_codec *codec = mbhc->codec; |
| 5479 | int wg_time = snd_soc_read(codec, WCD9XXX_A_RX_HPH_CNP_WG_TIME) * |
| 5480 | TAPAN_WG_TIME_FACTOR_US; |
| 5481 | /* |
| 5482 | * Tapan requires additional time to enable PA. |
| 5483 | * It is observed during experiments that we need |
| 5484 | * an additional wait time about 0.35 times of |
| 5485 | * the WG_TIME |
| 5486 | */ |
| 5487 | wg_time += (int) (wg_time * 35) / 100; |
| 5488 | |
| 5489 | snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_CNP_EN, 0x30, |
| 5490 | enable ? 0x30 : 0x0); |
| 5491 | /* Wait for wave gen time to avoid pop noise */ |
| 5492 | usleep_range(wg_time, wg_time + WCD9XXX_USLEEP_RANGE_MARGIN_US); |
| 5493 | pr_debug("%s: PAs are %s as static mode (wg_time %d)\n", __func__, |
| 5494 | enable ? "enabled" : "disabled", wg_time); |
| 5495 | return 0; |
| 5496 | } |
| 5497 | |
| 5498 | static int tapan_setup_zdet(struct wcd9xxx_mbhc *mbhc, |
| 5499 | enum mbhc_impedance_detect_stages stage) |
| 5500 | { |
| 5501 | |
| 5502 | int ret = 0; |
| 5503 | struct snd_soc_codec *codec = mbhc->codec; |
| 5504 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 5505 | const int mux_wait_us = 25; |
| 5506 | |
| 5507 | switch (stage) { |
| 5508 | |
| 5509 | case PRE_MEAS: |
| 5510 | INIT_LIST_HEAD(&tapan->reg_save_restore); |
| 5511 | /* Configure PA */ |
| 5512 | wcd9xxx_prepare_hph_pa(mbhc, &tapan->reg_save_restore); |
| 5513 | |
| 5514 | #define __wr(reg, mask, value) \ |
| 5515 | do { \ |
| 5516 | ret = wcd9xxx_soc_update_bits_push(codec, \ |
| 5517 | &tapan->reg_save_restore, \ |
| 5518 | reg, mask, value, 0); \ |
| 5519 | if (ret < 0) \ |
| 5520 | return ret; \ |
| 5521 | } while (0) |
| 5522 | |
| 5523 | /* Setup MBHC */ |
| 5524 | __wr(WCD9XXX_A_MBHC_SCALING_MUX_1, 0x7F, 0x40); |
| 5525 | __wr(WCD9XXX_A_MBHC_SCALING_MUX_2, 0xFF, 0xF0); |
| 5526 | __wr(WCD9XXX_A_TX_7_MBHC_TEST_CTL, 0xFF, 0x78); |
| 5527 | __wr(WCD9XXX_A_TX_7_MBHC_EN, 0xFF, 0xEC); |
| 5528 | __wr(WCD9XXX_A_CDC_MBHC_TIMER_B4_CTL, 0xFF, 0x45); |
| 5529 | __wr(WCD9XXX_A_CDC_MBHC_TIMER_B5_CTL, 0xFF, 0x80); |
| 5530 | |
| 5531 | __wr(WCD9XXX_A_CDC_MBHC_CLK_CTL, 0xFF, 0x0A); |
| 5532 | snd_soc_write(codec, WCD9XXX_A_CDC_MBHC_EN_CTL, 0x2); |
| 5533 | __wr(WCD9XXX_A_CDC_MBHC_CLK_CTL, 0xFF, 0x02); |
| 5534 | |
| 5535 | /* Enable Impedance Detection */ |
| 5536 | __wr(WCD9XXX_A_MBHC_HPH, 0xFF, 0xC8); |
| 5537 | |
| 5538 | /* |
| 5539 | * CnP setup for 0mV |
| 5540 | * Route static data as input to noise shaper |
| 5541 | */ |
| 5542 | __wr(TAPAN_A_CDC_RX1_B3_CTL, 0xFF, 0x02); |
| 5543 | __wr(TAPAN_A_CDC_RX2_B3_CTL, 0xFF, 0x02); |
| 5544 | |
| 5545 | snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_L_TEST, |
| 5546 | 0x02, 0x00); |
| 5547 | snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_R_TEST, |
| 5548 | 0x02, 0x00); |
| 5549 | |
| 5550 | /* Reset the HPHL static data pointer */ |
| 5551 | __wr(TAPAN_A_CDC_RX1_B2_CTL, 0xFF, 0x00); |
| 5552 | /* Four consecutive writes to set 0V as static data input */ |
| 5553 | snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00); |
| 5554 | snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00); |
| 5555 | snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00); |
| 5556 | snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00); |
| 5557 | |
| 5558 | /* Reset the HPHR static data pointer */ |
| 5559 | __wr(TAPAN_A_CDC_RX2_B2_CTL, 0xFF, 0x00); |
| 5560 | /* Four consecutive writes to set 0V as static data input */ |
| 5561 | snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00); |
| 5562 | snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00); |
| 5563 | snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00); |
| 5564 | snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00); |
| 5565 | |
| 5566 | /* Enable the HPHL and HPHR PA */ |
| 5567 | wcd9xxx_enable_static_pa(mbhc, true); |
| 5568 | break; |
| 5569 | case POST_MEAS: |
| 5570 | /* Turn off ICAL */ |
| 5571 | snd_soc_write(codec, WCD9XXX_A_MBHC_SCALING_MUX_2, 0xF0); |
| 5572 | |
| 5573 | wcd9xxx_enable_static_pa(mbhc, false); |
| 5574 | |
| 5575 | /* |
| 5576 | * Setup CnP wavegen to ramp to the desired |
| 5577 | * output using a 40ms ramp |
| 5578 | */ |
| 5579 | |
| 5580 | /* CnP wavegen current to 0.5uA */ |
| 5581 | snd_soc_write(codec, WCD9XXX_A_RX_HPH_BIAS_WG_OCP, 0x1A); |
| 5582 | /* Set the current division ratio to 2000 */ |
| 5583 | snd_soc_write(codec, WCD9XXX_A_RX_HPH_CNP_WG_CTL, 0xDF); |
| 5584 | /* Set the wavegen timer to max (60msec) */ |
| 5585 | snd_soc_write(codec, WCD9XXX_A_RX_HPH_CNP_WG_TIME, 0xA0); |
| 5586 | /* Set the CnP reference current to sc_bias */ |
| 5587 | snd_soc_write(codec, WCD9XXX_A_RX_HPH_OCP_CTL, 0x6D); |
| 5588 | |
| 5589 | snd_soc_write(codec, TAPAN_A_CDC_RX1_B2_CTL, 0x00); |
| 5590 | /* Four consecutive writes to set -10mV as static data input */ |
| 5591 | snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00); |
| 5592 | snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x1F); |
| 5593 | snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x19); |
| 5594 | snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0xAA); |
| 5595 | |
| 5596 | snd_soc_write(codec, TAPAN_A_CDC_RX2_B2_CTL, 0x00); |
| 5597 | /* Four consecutive writes to set -10mV as static data input */ |
| 5598 | snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00); |
| 5599 | snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x1F); |
| 5600 | snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x19); |
| 5601 | snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0xAA); |
| 5602 | |
| 5603 | snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_L_TEST, |
| 5604 | 0x02, 0x02); |
| 5605 | snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_R_TEST, |
| 5606 | 0x02, 0x02); |
| 5607 | /* Enable the HPHL and HPHR PA and wait for 60mS */ |
| 5608 | wcd9xxx_enable_static_pa(mbhc, true); |
| 5609 | |
| 5610 | snd_soc_update_bits(codec, WCD9XXX_A_MBHC_SCALING_MUX_1, |
| 5611 | 0x7F, 0x40); |
| 5612 | usleep_range(mux_wait_us, |
| 5613 | mux_wait_us + WCD9XXX_USLEEP_RANGE_MARGIN_US); |
| 5614 | break; |
| 5615 | case PA_DISABLE: |
Sudheer Papothi | 3fb420b | 2013-12-05 05:30:15 +0530 | [diff] [blame] | 5616 | if (!mbhc->hph_pa_dac_state) |
| 5617 | wcd9xxx_enable_static_pa(mbhc, false); |
Phani Kumar Uppalapati | 01a77e1 | 2013-08-08 15:31:35 -0700 | [diff] [blame] | 5618 | wcd9xxx_restore_registers(codec, &tapan->reg_save_restore); |
| 5619 | break; |
| 5620 | } |
| 5621 | #undef __wr |
| 5622 | |
| 5623 | return ret; |
| 5624 | } |
| 5625 | |
| 5626 | static void tapan_compute_impedance(s16 *l, s16 *r, uint32_t *zl, uint32_t *zr) |
| 5627 | { |
| 5628 | int zln, zld; |
| 5629 | int zrn, zrd; |
| 5630 | int rl = 0, rr = 0; |
| 5631 | |
| 5632 | zln = (l[1] - l[0]) * TAPAN_ZDET_MUL_FACTOR; |
| 5633 | zld = (l[2] - l[0]); |
| 5634 | if (zld) |
| 5635 | rl = zln / zld; |
| 5636 | |
| 5637 | zrn = (r[1] - r[0]) * TAPAN_ZDET_MUL_FACTOR; |
| 5638 | zrd = (r[2] - r[0]); |
| 5639 | if (zrd) |
| 5640 | rr = zrn / zrd; |
| 5641 | |
| 5642 | *zl = rl; |
| 5643 | *zr = rr; |
| 5644 | } |
| 5645 | |
Simmi Pateriya | 95466b1 | 2013-05-09 20:08:46 +0530 | [diff] [blame] | 5646 | static const struct wcd9xxx_mbhc_cb mbhc_cb = { |
| 5647 | .enable_mux_bias_block = tapan_enable_mux_bias_block, |
| 5648 | .cfilt_fast_mode = tapan_put_cfilt_fast_mode, |
| 5649 | .codec_specific_cal = tapan_codec_specific_cal_setup, |
Simmi Pateriya | 95466b1 | 2013-05-09 20:08:46 +0530 | [diff] [blame] | 5650 | .switch_cfilt_mode = tapan_codec_switch_cfilt_mode, |
| 5651 | .select_cfilt = tapan_select_cfilt, |
Bhalchandra Gajare | 8e5fe25 | 2013-07-15 19:42:21 -0700 | [diff] [blame] | 5652 | .get_cdc_type = tapan_get_cdc_type, |
Phani Kumar Uppalapati | 01a77e1 | 2013-08-08 15:31:35 -0700 | [diff] [blame] | 5653 | .setup_zdet = tapan_setup_zdet, |
| 5654 | .compute_impedance = tapan_compute_impedance, |
Simmi Pateriya | 95466b1 | 2013-05-09 20:08:46 +0530 | [diff] [blame] | 5655 | }; |
| 5656 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5657 | int tapan_hs_detect(struct snd_soc_codec *codec, |
| 5658 | struct wcd9xxx_mbhc_config *mbhc_cfg) |
| 5659 | { |
| 5660 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 5661 | return wcd9xxx_mbhc_start(&tapan->mbhc, mbhc_cfg); |
| 5662 | } |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5663 | EXPORT_SYMBOL(tapan_hs_detect); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5664 | |
Joonwoo Park | e7d724e | 2013-08-19 15:51:01 -0700 | [diff] [blame] | 5665 | void tapan_hs_detect_exit(struct snd_soc_codec *codec) |
| 5666 | { |
| 5667 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 5668 | wcd9xxx_mbhc_stop(&tapan->mbhc); |
| 5669 | } |
| 5670 | EXPORT_SYMBOL(tapan_hs_detect_exit); |
| 5671 | |
Damir Didjusto | d6aea99 | 2013-09-03 21:18:59 -0700 | [diff] [blame] | 5672 | void tapan_event_register( |
| 5673 | int (*machine_event_cb)(struct snd_soc_codec *codec, |
| 5674 | enum wcd9xxx_codec_event), |
| 5675 | struct snd_soc_codec *codec) |
| 5676 | { |
| 5677 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 5678 | tapan->machine_codec_event_cb = machine_event_cb; |
| 5679 | } |
| 5680 | EXPORT_SYMBOL(tapan_event_register); |
| 5681 | |
Joonwoo Park | 8ffa281 | 2013-08-07 19:01:30 -0700 | [diff] [blame] | 5682 | static int tapan_device_down(struct wcd9xxx *wcd9xxx) |
| 5683 | { |
| 5684 | struct snd_soc_codec *codec; |
| 5685 | |
| 5686 | codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv); |
| 5687 | snd_soc_card_change_online_state(codec->card, 0); |
| 5688 | |
| 5689 | return 0; |
| 5690 | } |
| 5691 | |
Bhalchandra Gajare | 1674893 | 2013-10-01 18:16:05 -0700 | [diff] [blame] | 5692 | static const struct wcd9xxx_mbhc_intr cdc_intr_ids = { |
| 5693 | .poll_plug_rem = WCD9XXX_IRQ_MBHC_REMOVAL, |
| 5694 | .shortavg_complete = WCD9XXX_IRQ_MBHC_SHORT_TERM, |
| 5695 | .potential_button_press = WCD9XXX_IRQ_MBHC_PRESS, |
| 5696 | .button_release = WCD9XXX_IRQ_MBHC_RELEASE, |
| 5697 | .dce_est_complete = WCD9XXX_IRQ_MBHC_POTENTIAL, |
| 5698 | .insertion = WCD9XXX_IRQ_MBHC_INSERTION, |
| 5699 | .hph_left_ocp = WCD9306_IRQ_HPH_PA_OCPL_FAULT, |
| 5700 | .hph_right_ocp = WCD9306_IRQ_HPH_PA_OCPR_FAULT, |
| 5701 | .hs_jack_switch = WCD9306_IRQ_MBHC_JACK_SWITCH, |
| 5702 | }; |
| 5703 | |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5704 | static int tapan_post_reset_cb(struct wcd9xxx *wcd9xxx) |
| 5705 | { |
| 5706 | int ret = 0; |
| 5707 | int rco_clk_rate; |
| 5708 | struct snd_soc_codec *codec; |
| 5709 | struct tapan_priv *tapan; |
| 5710 | |
| 5711 | codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv); |
| 5712 | tapan = snd_soc_codec_get_drvdata(codec); |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5713 | |
Joonwoo Park | 8ffa281 | 2013-08-07 19:01:30 -0700 | [diff] [blame] | 5714 | snd_soc_card_change_online_state(codec->card, 1); |
| 5715 | |
| 5716 | mutex_lock(&codec->mutex); |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5717 | if (codec->reg_def_copy) { |
| 5718 | pr_debug("%s: Update ASOC cache", __func__); |
| 5719 | kfree(codec->reg_cache); |
| 5720 | codec->reg_cache = kmemdup(codec->reg_def_copy, |
| 5721 | codec->reg_size, GFP_KERNEL); |
| 5722 | if (!codec->reg_cache) { |
| 5723 | pr_err("%s: Cache update failed!\n", __func__); |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5724 | mutex_unlock(&codec->mutex); |
| 5725 | return -ENOMEM; |
| 5726 | } |
| 5727 | } |
| 5728 | |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5729 | if (spkr_drv_wrnd == 1) |
| 5730 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80); |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5731 | |
| 5732 | tapan_update_reg_defaults(codec); |
| 5733 | tapan_update_reg_mclk_rate(wcd9xxx); |
| 5734 | tapan_codec_init_reg(codec); |
| 5735 | ret = tapan_handle_pdata(tapan); |
| 5736 | if (IS_ERR_VALUE(ret)) |
| 5737 | pr_err("%s: bad pdata\n", __func__); |
| 5738 | |
| 5739 | tapan_slim_interface_init_reg(codec); |
| 5740 | |
Joonwoo Park | 865bcf0 | 2013-07-15 14:05:32 -0700 | [diff] [blame] | 5741 | wcd9xxx_resmgr_post_ssr(&tapan->resmgr); |
| 5742 | |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5743 | wcd9xxx_mbhc_deinit(&tapan->mbhc); |
| 5744 | |
| 5745 | if (TAPAN_IS_1_0(wcd9xxx->version)) |
| 5746 | rco_clk_rate = TAPAN_MCLK_CLK_12P288MHZ; |
| 5747 | else |
| 5748 | rco_clk_rate = TAPAN_MCLK_CLK_9P6MHZ; |
| 5749 | |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 5750 | ret = wcd9xxx_mbhc_init(&tapan->mbhc, &tapan->resmgr, codec, |
| 5751 | tapan_enable_mbhc_micbias, |
Bhalchandra Gajare | 1674893 | 2013-10-01 18:16:05 -0700 | [diff] [blame] | 5752 | &mbhc_cb, &cdc_intr_ids, rco_clk_rate, |
Phani Kumar Uppalapati | 01a77e1 | 2013-08-08 15:31:35 -0700 | [diff] [blame] | 5753 | TAPAN_CDC_ZDET_SUPPORTED); |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5754 | if (ret) |
| 5755 | pr_err("%s: mbhc init failed %d\n", __func__, ret); |
| 5756 | else |
| 5757 | wcd9xxx_mbhc_start(&tapan->mbhc, tapan->mbhc.mbhc_cfg); |
Joonwoo Park | c98049a | 2013-07-30 16:43:34 -0700 | [diff] [blame] | 5758 | |
| 5759 | tapan_cleanup_irqs(tapan); |
| 5760 | ret = tapan_setup_irqs(tapan); |
| 5761 | if (ret) |
| 5762 | pr_err("%s: Failed to setup irq: %d\n", __func__, ret); |
| 5763 | |
Damir Didjusto | d6aea99 | 2013-09-03 21:18:59 -0700 | [diff] [blame] | 5764 | tapan->machine_codec_event_cb(codec, WCD9XXX_CODEC_EVENT_CODEC_UP); |
| 5765 | |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5766 | mutex_unlock(&codec->mutex); |
| 5767 | return ret; |
| 5768 | } |
| 5769 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5770 | static struct wcd9xxx_reg_address tapan_reg_address = { |
| 5771 | }; |
| 5772 | |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5773 | static int wcd9xxx_ssr_register(struct wcd9xxx *control, |
Joonwoo Park | 8ffa281 | 2013-08-07 19:01:30 -0700 | [diff] [blame] | 5774 | int (*device_down_cb)(struct wcd9xxx *wcd9xxx), |
| 5775 | int (*device_up_cb)(struct wcd9xxx *wcd9xxx), |
| 5776 | void *priv) |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5777 | { |
Joonwoo Park | 8ffa281 | 2013-08-07 19:01:30 -0700 | [diff] [blame] | 5778 | control->dev_down = device_down_cb; |
| 5779 | control->post_reset = device_up_cb; |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5780 | control->ssr_priv = priv; |
| 5781 | return 0; |
| 5782 | } |
| 5783 | |
Bhalchandra Gajare | 5b4199c | 2013-07-03 14:35:43 -0700 | [diff] [blame] | 5784 | static struct regulator *tapan_codec_find_regulator( |
| 5785 | struct snd_soc_codec *codec, |
| 5786 | const char *name) |
| 5787 | { |
| 5788 | int i; |
| 5789 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 5790 | |
| 5791 | for (i = 0; i < core->num_of_supplies; i++) { |
| 5792 | if (core->supplies[i].supply && |
| 5793 | !strcmp(core->supplies[i].supply, name)) |
| 5794 | return core->supplies[i].consumer; |
| 5795 | } |
| 5796 | return NULL; |
| 5797 | } |
| 5798 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 5799 | static void tapan_enable_config_rco(struct wcd9xxx *core, bool enable) |
| 5800 | { |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5801 | struct wcd9xxx_core_resource *core_res = &core->core_res; |
| 5802 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 5803 | if (enable) { |
Phani Kumar Uppalapati | cc3ec0c | 2013-09-06 18:04:03 -0700 | [diff] [blame] | 5804 | wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL, |
| 5805 | 0x80, 0x80); |
| 5806 | wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL, |
| 5807 | 0x04, 0x04); |
| 5808 | wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL, |
| 5809 | 0x01, 0x01); |
| 5810 | usleep_range(1000, 1000); |
| 5811 | wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL, |
| 5812 | 0x80, 0x00); |
| 5813 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 5814 | /* Enable RC Oscillator */ |
| 5815 | wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_FREQ, 0x10, 0x00); |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5816 | wcd9xxx_reg_write(core_res, WCD9XXX_A_BIAS_OSC_BG_CTL, 0x17); |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 5817 | usleep_range(5, 5); |
| 5818 | wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_FREQ, 0x80, 0x80); |
| 5819 | wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_TEST, 0x80, 0x80); |
| 5820 | usleep_range(10, 10); |
| 5821 | wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_TEST, 0x80, 0x00); |
| 5822 | usleep_range(20, 20); |
| 5823 | wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN1, 0x08, 0x08); |
| 5824 | /* Enable MCLK and wait 1ms till it gets enabled */ |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5825 | wcd9xxx_reg_write(core_res, WCD9XXX_A_CLK_BUFF_EN2, 0x02); |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 5826 | usleep_range(1000, 1000); |
| 5827 | /* Enable CLK BUFF and wait for 1.2ms */ |
| 5828 | wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN1, 0x01, 0x01); |
| 5829 | usleep_range(1000, 1200); |
| 5830 | |
| 5831 | wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x02, 0x00); |
| 5832 | wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x04, 0x04); |
| 5833 | wcd9xxx_reg_update(core, WCD9XXX_A_CDC_CLK_MCLK_CTL, |
| 5834 | 0x01, 0x01); |
| 5835 | usleep_range(50, 50); |
| 5836 | } else { |
| 5837 | wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x04, 0x00); |
| 5838 | usleep_range(50, 50); |
| 5839 | wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x02, 0x02); |
| 5840 | wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN1, 0x05, 0x00); |
| 5841 | usleep_range(50, 50); |
Phani Kumar Uppalapati | cc3ec0c | 2013-09-06 18:04:03 -0700 | [diff] [blame] | 5842 | |
| 5843 | wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_FREQ, 0x80, 0x00); |
| 5844 | usleep_range(10, 10); |
| 5845 | wcd9xxx_reg_write(core_res, WCD9XXX_A_BIAS_OSC_BG_CTL, 0x16); |
| 5846 | wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL, |
| 5847 | 0x03, 0x00); |
| 5848 | usleep_range(100, 100); |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 5849 | } |
| 5850 | |
| 5851 | } |
| 5852 | |
| 5853 | static bool tapan_check_wcd9306(struct device *cdc_dev, bool sensed) |
| 5854 | { |
| 5855 | struct wcd9xxx *core = dev_get_drvdata(cdc_dev->parent); |
| 5856 | u8 reg_val; |
| 5857 | bool ret = true; |
| 5858 | unsigned long timeout; |
| 5859 | bool timedout; |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5860 | struct wcd9xxx_core_resource *core_res = &core->core_res; |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 5861 | |
| 5862 | if (!core) { |
| 5863 | dev_err(cdc_dev, "%s: core not initialized\n", __func__); |
| 5864 | return -EINVAL; |
| 5865 | } |
| 5866 | |
| 5867 | tapan_enable_config_rco(core, 1); |
| 5868 | |
| 5869 | if (sensed == false) { |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5870 | reg_val = wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_CTL); |
| 5871 | wcd9xxx_reg_write(core_res, TAPAN_A_QFUSE_CTL, |
| 5872 | (reg_val | 0x03)); |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 5873 | } |
| 5874 | |
| 5875 | timeout = jiffies + HZ; |
| 5876 | do { |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5877 | if ((wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_STATUS))) |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 5878 | break; |
| 5879 | } while (!(timedout = time_after(jiffies, timeout))); |
| 5880 | |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5881 | if (wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_DATA_OUT1) || |
| 5882 | wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_DATA_OUT2)) { |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 5883 | dev_info(cdc_dev, "%s: wcd9302 detected\n", __func__); |
| 5884 | ret = false; |
| 5885 | } else |
| 5886 | dev_info(cdc_dev, "%s: wcd9306 detected\n", __func__); |
| 5887 | |
| 5888 | tapan_enable_config_rco(core, 0); |
| 5889 | return ret; |
| 5890 | }; |
| 5891 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5892 | static int tapan_codec_probe(struct snd_soc_codec *codec) |
| 5893 | { |
| 5894 | struct wcd9xxx *control; |
| 5895 | struct tapan_priv *tapan; |
| 5896 | struct wcd9xxx_pdata *pdata; |
| 5897 | struct wcd9xxx *wcd9xxx; |
| 5898 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 5899 | int ret = 0; |
Phani Kumar Uppalapati | 43bc415 | 2013-05-24 00:44:20 -0700 | [diff] [blame] | 5900 | int i, rco_clk_rate; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5901 | void *ptr = NULL; |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5902 | struct wcd9xxx_core_resource *core_res; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5903 | |
| 5904 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 5905 | control = codec->control_data; |
| 5906 | |
Joonwoo Park | 8ffa281 | 2013-08-07 19:01:30 -0700 | [diff] [blame] | 5907 | wcd9xxx_ssr_register(control, tapan_device_down, |
| 5908 | tapan_post_reset_cb, (void *)codec); |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5909 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5910 | dev_info(codec->dev, "%s()\n", __func__); |
| 5911 | |
| 5912 | tapan = kzalloc(sizeof(struct tapan_priv), GFP_KERNEL); |
| 5913 | if (!tapan) { |
| 5914 | dev_err(codec->dev, "Failed to allocate private data\n"); |
| 5915 | return -ENOMEM; |
| 5916 | } |
| 5917 | for (i = 0 ; i < NUM_DECIMATORS; i++) { |
| 5918 | tx_hpf_work[i].tapan = tapan; |
| 5919 | tx_hpf_work[i].decimator = i + 1; |
| 5920 | INIT_DELAYED_WORK(&tx_hpf_work[i].dwork, |
| 5921 | tx_hpf_corner_freq_callback); |
| 5922 | } |
| 5923 | |
| 5924 | snd_soc_codec_set_drvdata(codec, tapan); |
| 5925 | |
| 5926 | /* codec resmgr module init */ |
| 5927 | wcd9xxx = codec->control_data; |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5928 | core_res = &wcd9xxx->core_res; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5929 | pdata = dev_get_platdata(codec->dev->parent); |
Bhalchandra Gajare | 9b4eb3b | 2013-04-30 12:00:41 -0700 | [diff] [blame] | 5930 | ret = wcd9xxx_resmgr_init(&tapan->resmgr, codec, core_res, pdata, |
Bhalchandra Gajare | 9943aa6 | 2013-10-09 18:40:11 -0700 | [diff] [blame] | 5931 | &pdata->micbias, &tapan_reg_address, |
| 5932 | WCD9XXX_CDC_TYPE_TAPAN); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5933 | if (ret) { |
| 5934 | pr_err("%s: wcd9xxx init failed %d\n", __func__, ret); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5935 | return ret; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5936 | } |
| 5937 | |
Bhalchandra Gajare | 5b4199c | 2013-07-03 14:35:43 -0700 | [diff] [blame] | 5938 | tapan->cp_regulators[CP_REG_BUCK] = tapan_codec_find_regulator(codec, |
| 5939 | WCD9XXX_SUPPLY_BUCK_NAME); |
| 5940 | tapan->cp_regulators[CP_REG_BHELPER] = tapan_codec_find_regulator(codec, |
| 5941 | "cdc-vdd-buckhelper"); |
| 5942 | |
Bhalchandra Gajare | 7c73952 | 2013-06-20 15:31:02 -0700 | [diff] [blame] | 5943 | tapan->clsh_d.buck_mv = tapan_codec_get_buck_mv(codec); |
| 5944 | /* |
| 5945 | * If 1.8 volts is requested on the vdd_cp line, then |
| 5946 | * assume that S4 is in a dynamically switchable state |
| 5947 | * and can switch between 1.8 volts and 2.15 volts |
| 5948 | */ |
| 5949 | if (tapan->clsh_d.buck_mv == WCD9XXX_CDC_BUCK_MV_1P8) |
| 5950 | tapan->clsh_d.is_dynamic_vdd_cp = true; |
| 5951 | wcd9xxx_clsh_init(&tapan->clsh_d, &tapan->resmgr); |
| 5952 | |
Phani Kumar Uppalapati | 43bc415 | 2013-05-24 00:44:20 -0700 | [diff] [blame] | 5953 | if (TAPAN_IS_1_0(control->version)) |
| 5954 | rco_clk_rate = TAPAN_MCLK_CLK_12P288MHZ; |
| 5955 | else |
| 5956 | rco_clk_rate = TAPAN_MCLK_CLK_9P6MHZ; |
| 5957 | |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 5958 | ret = wcd9xxx_mbhc_init(&tapan->mbhc, &tapan->resmgr, codec, |
| 5959 | tapan_enable_mbhc_micbias, |
Bhalchandra Gajare | 1674893 | 2013-10-01 18:16:05 -0700 | [diff] [blame] | 5960 | &mbhc_cb, &cdc_intr_ids, rco_clk_rate, |
Phani Kumar Uppalapati | 01a77e1 | 2013-08-08 15:31:35 -0700 | [diff] [blame] | 5961 | TAPAN_CDC_ZDET_SUPPORTED); |
Simmi Pateriya | 95466b1 | 2013-05-09 20:08:46 +0530 | [diff] [blame] | 5962 | |
Simmi Pateriya | 0a44d84 | 2013-04-03 01:12:42 +0530 | [diff] [blame] | 5963 | if (ret) { |
| 5964 | pr_err("%s: mbhc init failed %d\n", __func__, ret); |
| 5965 | return ret; |
| 5966 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5967 | |
| 5968 | tapan->codec = codec; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5969 | for (i = 0; i < COMPANDER_MAX; i++) { |
| 5970 | tapan->comp_enabled[i] = 0; |
| 5971 | tapan->comp_fs[i] = COMPANDER_FS_48KHZ; |
| 5972 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5973 | tapan->intf_type = wcd9xxx_get_intf_type(); |
| 5974 | tapan->aux_pga_cnt = 0; |
| 5975 | tapan->aux_l_gain = 0x1F; |
| 5976 | tapan->aux_r_gain = 0x1F; |
Phani Kumar Uppalapati | 07420de | 2013-08-28 21:35:00 -0700 | [diff] [blame] | 5977 | tapan->ldo_h_users = 0; |
| 5978 | tapan->micb_2_users = 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5979 | tapan_update_reg_defaults(codec); |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 5980 | tapan_update_reg_mclk_rate(wcd9xxx); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5981 | tapan_codec_init_reg(codec); |
| 5982 | ret = tapan_handle_pdata(tapan); |
| 5983 | if (IS_ERR_VALUE(ret)) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5984 | dev_err(codec->dev, "%s: bad pdata\n", __func__); |
| 5985 | goto err_pdata; |
| 5986 | } |
| 5987 | |
| 5988 | if (spkr_drv_wrnd > 0) { |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 5989 | WCD9XXX_BG_CLK_LOCK(&tapan->resmgr); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 5990 | wcd9xxx_resmgr_get_bandgap(&tapan->resmgr, |
| 5991 | WCD9XXX_BANDGAP_AUDIO_MODE); |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 5992 | WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 5993 | } |
| 5994 | |
| 5995 | ptr = kmalloc((sizeof(tapan_rx_chs) + |
| 5996 | sizeof(tapan_tx_chs)), GFP_KERNEL); |
| 5997 | if (!ptr) { |
| 5998 | pr_err("%s: no mem for slim chan ctl data\n", __func__); |
| 5999 | ret = -ENOMEM; |
| 6000 | goto err_nomem_slimch; |
| 6001 | } |
| 6002 | |
| 6003 | if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 6004 | snd_soc_dapm_new_controls(dapm, tapan_dapm_i2s_widgets, |
| 6005 | ARRAY_SIZE(tapan_dapm_i2s_widgets)); |
| 6006 | snd_soc_dapm_add_routes(dapm, audio_i2s_map, |
| 6007 | ARRAY_SIZE(audio_i2s_map)); |
| 6008 | for (i = 0; i < ARRAY_SIZE(tapan_i2s_dai); i++) |
| 6009 | INIT_LIST_HEAD(&tapan->dai[i].wcd9xxx_ch_list); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 6010 | } else if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 6011 | for (i = 0; i < NUM_CODEC_DAIS; i++) { |
| 6012 | INIT_LIST_HEAD(&tapan->dai[i].wcd9xxx_ch_list); |
| 6013 | init_waitqueue_head(&tapan->dai[i].dai_wait); |
| 6014 | } |
Damir Didjusto | d6aea99 | 2013-09-03 21:18:59 -0700 | [diff] [blame] | 6015 | tapan_init_slim_slave_cfg(codec); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 6016 | } |
| 6017 | |
Phani Kumar Uppalapati | cc3ec0c | 2013-09-06 18:04:03 -0700 | [diff] [blame] | 6018 | if (codec_ver == WCD9306) { |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 6019 | snd_soc_add_codec_controls(codec, tapan_9306_snd_controls, |
| 6020 | ARRAY_SIZE(tapan_9306_snd_controls)); |
| 6021 | snd_soc_dapm_new_controls(dapm, tapan_9306_dapm_widgets, |
| 6022 | ARRAY_SIZE(tapan_9306_dapm_widgets)); |
| 6023 | snd_soc_dapm_add_routes(dapm, wcd9306_map, |
| 6024 | ARRAY_SIZE(wcd9306_map)); |
| 6025 | } else { |
| 6026 | snd_soc_dapm_add_routes(dapm, wcd9302_map, |
| 6027 | ARRAY_SIZE(wcd9302_map)); |
| 6028 | } |
| 6029 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 6030 | control->num_rx_port = TAPAN_RX_MAX; |
| 6031 | control->rx_chs = ptr; |
| 6032 | memcpy(control->rx_chs, tapan_rx_chs, sizeof(tapan_rx_chs)); |
| 6033 | control->num_tx_port = TAPAN_TX_MAX; |
| 6034 | control->tx_chs = ptr + sizeof(tapan_rx_chs); |
| 6035 | memcpy(control->tx_chs, tapan_tx_chs, sizeof(tapan_tx_chs)); |
| 6036 | |
| 6037 | snd_soc_dapm_sync(dapm); |
| 6038 | |
| 6039 | (void) tapan_setup_irqs(tapan); |
| 6040 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 6041 | atomic_set(&kp_tapan_priv, (unsigned long)tapan); |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 6042 | mutex_lock(&dapm->codec->mutex); |
Phani Kumar Uppalapati | cc3ec0c | 2013-09-06 18:04:03 -0700 | [diff] [blame] | 6043 | if (codec_ver == WCD9306) { |
| 6044 | snd_soc_dapm_disable_pin(dapm, "ANC HPHL"); |
| 6045 | snd_soc_dapm_disable_pin(dapm, "ANC HPHR"); |
| 6046 | snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE"); |
| 6047 | snd_soc_dapm_disable_pin(dapm, "ANC EAR PA"); |
| 6048 | snd_soc_dapm_disable_pin(dapm, "ANC EAR"); |
| 6049 | } |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 6050 | snd_soc_dapm_sync(dapm); |
| 6051 | mutex_unlock(&dapm->codec->mutex); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 6052 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 6053 | codec->ignore_pmdown_time = 1; |
Ravishankar Sarawadi | 7b70036 | 2013-04-18 15:56:02 -0700 | [diff] [blame] | 6054 | |
| 6055 | if (ret) |
| 6056 | tapan_cleanup_irqs(tapan); |
| 6057 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 6058 | return ret; |
| 6059 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 6060 | err_pdata: |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 6061 | kfree(ptr); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 6062 | err_nomem_slimch: |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 6063 | kfree(tapan); |
| 6064 | return ret; |
| 6065 | } |
| 6066 | |
| 6067 | static int tapan_codec_remove(struct snd_soc_codec *codec) |
| 6068 | { |
| 6069 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 5b4199c | 2013-07-03 14:35:43 -0700 | [diff] [blame] | 6070 | int index = 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 6071 | |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 6072 | WCD9XXX_BG_CLK_LOCK(&tapan->resmgr); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 6073 | atomic_set(&kp_tapan_priv, 0); |
| 6074 | |
| 6075 | if (spkr_drv_wrnd > 0) |
| 6076 | wcd9xxx_resmgr_put_bandgap(&tapan->resmgr, |
| 6077 | WCD9XXX_BANDGAP_AUDIO_MODE); |
Joonwoo Park | 533b368 | 2013-06-13 11:41:21 -0700 | [diff] [blame] | 6078 | WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr); |
Ravishankar Sarawadi | 7b70036 | 2013-04-18 15:56:02 -0700 | [diff] [blame] | 6079 | |
| 6080 | tapan_cleanup_irqs(tapan); |
| 6081 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 6082 | /* cleanup MBHC */ |
| 6083 | wcd9xxx_mbhc_deinit(&tapan->mbhc); |
| 6084 | /* cleanup resmgr */ |
| 6085 | wcd9xxx_resmgr_deinit(&tapan->resmgr); |
| 6086 | |
Bhalchandra Gajare | 5b4199c | 2013-07-03 14:35:43 -0700 | [diff] [blame] | 6087 | for (index = 0; index < CP_REG_MAX; index++) |
| 6088 | tapan->cp_regulators[index] = NULL; |
| 6089 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 6090 | kfree(tapan); |
| 6091 | return 0; |
| 6092 | } |
| 6093 | |
| 6094 | static struct snd_soc_codec_driver soc_codec_dev_tapan = { |
| 6095 | .probe = tapan_codec_probe, |
| 6096 | .remove = tapan_codec_remove, |
| 6097 | |
| 6098 | .read = tapan_read, |
| 6099 | .write = tapan_write, |
| 6100 | |
| 6101 | .readable_register = tapan_readable, |
| 6102 | .volatile_register = tapan_volatile, |
| 6103 | |
| 6104 | .reg_cache_size = TAPAN_CACHE_SIZE, |
| 6105 | .reg_cache_default = tapan_reset_reg_defaults, |
| 6106 | .reg_word_size = 1, |
| 6107 | |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 6108 | .controls = tapan_common_snd_controls, |
| 6109 | .num_controls = ARRAY_SIZE(tapan_common_snd_controls), |
| 6110 | .dapm_widgets = tapan_common_dapm_widgets, |
| 6111 | .num_dapm_widgets = ARRAY_SIZE(tapan_common_dapm_widgets), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 6112 | .dapm_routes = audio_map, |
| 6113 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
| 6114 | }; |
| 6115 | |
| 6116 | #ifdef CONFIG_PM |
| 6117 | static int tapan_suspend(struct device *dev) |
| 6118 | { |
| 6119 | dev_dbg(dev, "%s: system suspend\n", __func__); |
| 6120 | return 0; |
| 6121 | } |
| 6122 | |
| 6123 | static int tapan_resume(struct device *dev) |
| 6124 | { |
| 6125 | struct platform_device *pdev = to_platform_device(dev); |
| 6126 | struct tapan_priv *tapan = platform_get_drvdata(pdev); |
| 6127 | dev_dbg(dev, "%s: system resume\n", __func__); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 6128 | /* Notify */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 6129 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, WCD9XXX_EVENT_POST_RESUME); |
| 6130 | return 0; |
| 6131 | } |
| 6132 | |
| 6133 | static const struct dev_pm_ops tapan_pm_ops = { |
| 6134 | .suspend = tapan_suspend, |
| 6135 | .resume = tapan_resume, |
| 6136 | }; |
| 6137 | #endif |
| 6138 | |
| 6139 | static int __devinit tapan_probe(struct platform_device *pdev) |
| 6140 | { |
| 6141 | int ret = 0; |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 6142 | bool is_wcd9306; |
| 6143 | |
| 6144 | is_wcd9306 = tapan_check_wcd9306(&pdev->dev, false); |
| 6145 | if (is_wcd9306 < 0) { |
| 6146 | dev_info(&pdev->dev, "%s: cannot find codec type, default to 9306\n", |
| 6147 | __func__); |
| 6148 | is_wcd9306 = true; |
| 6149 | } |
Phani Kumar Uppalapati | cc3ec0c | 2013-09-06 18:04:03 -0700 | [diff] [blame] | 6150 | codec_ver = is_wcd9306 ? WCD9306 : WCD9302; |
Phani Kumar Uppalapati | 71ba888 | 2013-04-12 19:57:52 -0700 | [diff] [blame] | 6151 | |
| 6152 | if (!is_wcd9306) { |
| 6153 | if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 6154 | ret = snd_soc_register_codec(&pdev->dev, |
| 6155 | &soc_codec_dev_tapan, |
| 6156 | tapan9302_dai, ARRAY_SIZE(tapan9302_dai)); |
| 6157 | else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C) |
| 6158 | ret = snd_soc_register_codec(&pdev->dev, |
| 6159 | &soc_codec_dev_tapan, |
| 6160 | tapan_i2s_dai, ARRAY_SIZE(tapan_i2s_dai)); |
| 6161 | } else { |
| 6162 | if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 6163 | ret = snd_soc_register_codec(&pdev->dev, |
| 6164 | &soc_codec_dev_tapan, |
| 6165 | tapan_dai, ARRAY_SIZE(tapan_dai)); |
| 6166 | else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C) |
| 6167 | ret = snd_soc_register_codec(&pdev->dev, |
| 6168 | &soc_codec_dev_tapan, |
| 6169 | tapan_i2s_dai, ARRAY_SIZE(tapan_i2s_dai)); |
| 6170 | } |
| 6171 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 6172 | return ret; |
| 6173 | } |
| 6174 | static int __devexit tapan_remove(struct platform_device *pdev) |
| 6175 | { |
| 6176 | snd_soc_unregister_codec(&pdev->dev); |
| 6177 | return 0; |
| 6178 | } |
| 6179 | static struct platform_driver tapan_codec_driver = { |
| 6180 | .probe = tapan_probe, |
| 6181 | .remove = tapan_remove, |
| 6182 | .driver = { |
| 6183 | .name = "tapan_codec", |
| 6184 | .owner = THIS_MODULE, |
| 6185 | #ifdef CONFIG_PM |
| 6186 | .pm = &tapan_pm_ops, |
| 6187 | #endif |
| 6188 | }, |
| 6189 | }; |
| 6190 | |
| 6191 | static int __init tapan_codec_init(void) |
| 6192 | { |
| 6193 | return platform_driver_register(&tapan_codec_driver); |
| 6194 | } |
| 6195 | |
| 6196 | static void __exit tapan_codec_exit(void) |
| 6197 | { |
| 6198 | platform_driver_unregister(&tapan_codec_driver); |
| 6199 | } |
| 6200 | |
| 6201 | module_init(tapan_codec_init); |
| 6202 | module_exit(tapan_codec_exit); |
| 6203 | |
| 6204 | MODULE_DESCRIPTION("Tapan codec driver"); |
| 6205 | MODULE_LICENSE("GPL v2"); |