Banajit Goswami | eb1fa16 | 2013-02-05 15:11:27 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, 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> |
| 27 | #include <sound/pcm.h> |
| 28 | #include <sound/pcm_params.h> |
| 29 | #include <sound/soc.h> |
| 30 | #include <sound/soc-dapm.h> |
| 31 | #include <sound/tlv.h> |
| 32 | #include <linux/bitops.h> |
| 33 | #include <linux/delay.h> |
| 34 | #include <linux/pm_runtime.h> |
| 35 | #include <linux/kernel.h> |
| 36 | #include <linux/gpio.h> |
| 37 | #include "wcd9306.h" |
| 38 | #include "wcd9xxx-resmgr.h" |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 39 | #include "wcd9xxx-common.h" |
| 40 | |
| 41 | static atomic_t kp_tapan_priv; |
| 42 | static int spkr_drv_wrnd_param_set(const char *val, |
| 43 | const struct kernel_param *kp); |
| 44 | static int spkr_drv_wrnd = 1; |
| 45 | |
| 46 | static struct kernel_param_ops spkr_drv_wrnd_param_ops = { |
| 47 | .set = spkr_drv_wrnd_param_set, |
| 48 | .get = param_get_int, |
| 49 | }; |
| 50 | module_param_cb(spkr_drv_wrnd, &spkr_drv_wrnd_param_ops, &spkr_drv_wrnd, 0644); |
| 51 | MODULE_PARM_DESC(spkr_drv_wrnd, |
| 52 | "Run software workaround to avoid leakage on the speaker drive"); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 53 | |
| 54 | #define WCD9306_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ |
| 55 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\ |
| 56 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000) |
| 57 | |
| 58 | #define NUM_DECIMATORS 4 |
| 59 | #define NUM_INTERPOLATORS 4 |
| 60 | #define BITS_PER_REG 8 |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 61 | /* This actual number of TX ports supported in slimbus slave */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 62 | #define TAPAN_TX_PORT_NUMBER 16 |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 63 | #define TAPAN_RX_PORT_START_NUMBER 16 |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 64 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 65 | /* Nummer of TX ports actually connected from Slimbus slave to codec Digital */ |
| 66 | #define TAPAN_SLIM_CODEC_TX_PORTS 5 |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 67 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 68 | #define TAPAN_I2S_MASTER_MODE_MASK 0x08 |
| 69 | #define TAPAN_MCLK_CLK_12P288MHZ 12288000 |
Phani Kumar Uppalapati | 43bc415 | 2013-05-24 00:44:20 -0700 | [diff] [blame] | 70 | #define TAPAN_MCLK_CLK_9P6MHZ 9600000 |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 71 | |
| 72 | #define TAPAN_SLIM_CLOSE_TIMEOUT 1000 |
| 73 | #define TAPAN_SLIM_IRQ_OVERFLOW (1 << 0) |
| 74 | #define TAPAN_SLIM_IRQ_UNDERFLOW (1 << 1) |
| 75 | #define TAPAN_SLIM_IRQ_PORT_CLOSED (1 << 2) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 76 | enum { |
| 77 | AIF1_PB = 0, |
| 78 | AIF1_CAP, |
| 79 | AIF2_PB, |
| 80 | AIF2_CAP, |
| 81 | AIF3_PB, |
| 82 | AIF3_CAP, |
| 83 | NUM_CODEC_DAIS, |
| 84 | }; |
| 85 | |
| 86 | enum { |
| 87 | RX_MIX1_INP_SEL_ZERO = 0, |
| 88 | RX_MIX1_INP_SEL_SRC1, |
| 89 | RX_MIX1_INP_SEL_SRC2, |
| 90 | RX_MIX1_INP_SEL_IIR1, |
| 91 | RX_MIX1_INP_SEL_IIR2, |
| 92 | RX_MIX1_INP_SEL_RX1, |
| 93 | RX_MIX1_INP_SEL_RX2, |
| 94 | RX_MIX1_INP_SEL_RX3, |
| 95 | RX_MIX1_INP_SEL_RX4, |
| 96 | RX_MIX1_INP_SEL_RX5, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 97 | RX_MIX1_INP_SEL_AUXRX, |
| 98 | }; |
| 99 | |
| 100 | #define TAPAN_COMP_DIGITAL_GAIN_OFFSET 3 |
| 101 | |
| 102 | static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0); |
| 103 | static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1); |
| 104 | static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1); |
| 105 | static struct snd_soc_dai_driver tapan_dai[]; |
| 106 | static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0); |
| 107 | |
| 108 | /* Codec supports 2 IIR filters */ |
| 109 | enum { |
| 110 | IIR1 = 0, |
| 111 | IIR2, |
| 112 | IIR_MAX, |
| 113 | }; |
| 114 | /* Codec supports 5 bands */ |
| 115 | enum { |
| 116 | BAND1 = 0, |
| 117 | BAND2, |
| 118 | BAND3, |
| 119 | BAND4, |
| 120 | BAND5, |
| 121 | BAND_MAX, |
| 122 | }; |
| 123 | |
| 124 | enum { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 125 | COMPANDER_0, |
| 126 | COMPANDER_1, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 127 | COMPANDER_2, |
| 128 | COMPANDER_MAX, |
| 129 | }; |
| 130 | |
| 131 | enum { |
| 132 | COMPANDER_FS_8KHZ = 0, |
| 133 | COMPANDER_FS_16KHZ, |
| 134 | COMPANDER_FS_32KHZ, |
| 135 | COMPANDER_FS_48KHZ, |
| 136 | COMPANDER_FS_96KHZ, |
| 137 | COMPANDER_FS_192KHZ, |
| 138 | COMPANDER_FS_MAX, |
| 139 | }; |
| 140 | |
| 141 | struct comp_sample_dependent_params { |
| 142 | u32 peak_det_timeout; |
| 143 | u32 rms_meter_div_fact; |
| 144 | u32 rms_meter_resamp_fact; |
| 145 | }; |
| 146 | |
| 147 | struct hpf_work { |
| 148 | struct tapan_priv *tapan; |
| 149 | u32 decimator; |
| 150 | u8 tx_hpf_cut_of_freq; |
| 151 | struct delayed_work dwork; |
| 152 | }; |
| 153 | |
| 154 | static struct hpf_work tx_hpf_work[NUM_DECIMATORS]; |
| 155 | |
| 156 | static const struct wcd9xxx_ch tapan_rx_chs[TAPAN_RX_MAX] = { |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 157 | WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER, 0), |
| 158 | WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 1, 1), |
| 159 | WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 2, 2), |
| 160 | WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 3, 3), |
| 161 | WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 4, 4), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | static const struct wcd9xxx_ch tapan_tx_chs[TAPAN_TX_MAX] = { |
| 165 | WCD9XXX_CH(0, 0), |
| 166 | WCD9XXX_CH(1, 1), |
| 167 | WCD9XXX_CH(2, 2), |
| 168 | WCD9XXX_CH(3, 3), |
| 169 | WCD9XXX_CH(4, 4), |
| 170 | }; |
| 171 | |
| 172 | static const u32 vport_check_table[NUM_CODEC_DAIS] = { |
| 173 | 0, /* AIF1_PB */ |
| 174 | (1 << AIF2_CAP) | (1 << AIF3_CAP), /* AIF1_CAP */ |
| 175 | 0, /* AIF2_PB */ |
| 176 | (1 << AIF1_CAP) | (1 << AIF3_CAP), /* AIF2_CAP */ |
| 177 | 0, /* AIF2_PB */ |
| 178 | (1 << AIF1_CAP) | (1 << AIF2_CAP), /* AIF2_CAP */ |
| 179 | }; |
| 180 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 181 | static const u32 vport_i2s_check_table[NUM_CODEC_DAIS] = { |
| 182 | 0, /* AIF1_PB */ |
| 183 | 0, /* AIF1_CAP */ |
| 184 | }; |
| 185 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 186 | struct tapan_priv { |
| 187 | struct snd_soc_codec *codec; |
| 188 | u32 adc_count; |
| 189 | u32 rx_bias_count; |
| 190 | s32 dmic_1_2_clk_cnt; |
| 191 | s32 dmic_3_4_clk_cnt; |
| 192 | s32 dmic_5_6_clk_cnt; |
| 193 | |
| 194 | u32 anc_slot; |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 195 | bool anc_func; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 196 | |
| 197 | /*track tapan interface type*/ |
| 198 | u8 intf_type; |
| 199 | |
| 200 | /* num of slim ports required */ |
| 201 | struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS]; |
| 202 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 203 | /*compander*/ |
| 204 | int comp_enabled[COMPANDER_MAX]; |
| 205 | u32 comp_fs[COMPANDER_MAX]; |
| 206 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 207 | /* Maintain the status of AUX PGA */ |
| 208 | int aux_pga_cnt; |
| 209 | u8 aux_l_gain; |
| 210 | u8 aux_r_gain; |
| 211 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 212 | bool spkr_pa_widget_on; |
| 213 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 214 | /* resmgr module */ |
| 215 | struct wcd9xxx_resmgr resmgr; |
| 216 | /* mbhc module */ |
| 217 | struct wcd9xxx_mbhc mbhc; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 218 | |
| 219 | /* class h specific data */ |
| 220 | struct wcd9xxx_clsh_cdc_data clsh_d; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | static const u32 comp_shift[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 224 | 4, /* Compander 0's clock source is on interpolator 7 */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 225 | 0, |
| 226 | 2, |
| 227 | }; |
| 228 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 229 | static const int comp_rx_path[] = { |
| 230 | COMPANDER_1, |
| 231 | COMPANDER_1, |
| 232 | COMPANDER_2, |
| 233 | COMPANDER_2, |
| 234 | COMPANDER_2, |
| 235 | COMPANDER_2, |
| 236 | COMPANDER_0, |
| 237 | COMPANDER_MAX, |
| 238 | }; |
| 239 | |
| 240 | static const struct comp_sample_dependent_params comp_samp_params[] = { |
| 241 | { |
| 242 | /* 8 Khz */ |
| 243 | .peak_det_timeout = 0x02, |
| 244 | .rms_meter_div_fact = 0x09, |
| 245 | .rms_meter_resamp_fact = 0x06, |
| 246 | }, |
| 247 | { |
| 248 | /* 16 Khz */ |
| 249 | .peak_det_timeout = 0x03, |
| 250 | .rms_meter_div_fact = 0x0A, |
| 251 | .rms_meter_resamp_fact = 0x0C, |
| 252 | }, |
| 253 | { |
| 254 | /* 32 Khz */ |
| 255 | .peak_det_timeout = 0x05, |
| 256 | .rms_meter_div_fact = 0x0B, |
| 257 | .rms_meter_resamp_fact = 0x1E, |
| 258 | }, |
| 259 | { |
| 260 | /* 48 Khz */ |
| 261 | .peak_det_timeout = 0x05, |
| 262 | .rms_meter_div_fact = 0x0B, |
| 263 | .rms_meter_resamp_fact = 0x28, |
| 264 | }, |
| 265 | { |
| 266 | /* 96 Khz */ |
| 267 | .peak_det_timeout = 0x06, |
| 268 | .rms_meter_div_fact = 0x0C, |
| 269 | .rms_meter_resamp_fact = 0x50, |
| 270 | }, |
| 271 | { |
| 272 | /* 192 Khz */ |
| 273 | .peak_det_timeout = 0x07, |
| 274 | .rms_meter_div_fact = 0xD, |
| 275 | .rms_meter_resamp_fact = 0xA0, |
| 276 | }, |
| 277 | }; |
| 278 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 279 | static unsigned short rx_digital_gain_reg[] = { |
| 280 | TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 281 | TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 282 | TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 283 | TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 284 | }; |
| 285 | |
| 286 | static unsigned short tx_digital_gain_reg[] = { |
| 287 | TAPAN_A_CDC_TX1_VOL_CTL_GAIN, |
| 288 | TAPAN_A_CDC_TX2_VOL_CTL_GAIN, |
| 289 | TAPAN_A_CDC_TX3_VOL_CTL_GAIN, |
| 290 | TAPAN_A_CDC_TX4_VOL_CTL_GAIN, |
| 291 | }; |
| 292 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 293 | static int spkr_drv_wrnd_param_set(const char *val, |
| 294 | const struct kernel_param *kp) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 295 | { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 296 | struct snd_soc_codec *codec; |
| 297 | int ret, old; |
| 298 | struct tapan_priv *priv; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 299 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 300 | priv = (struct tapan_priv *)atomic_read(&kp_tapan_priv); |
| 301 | if (!priv) { |
| 302 | pr_debug("%s: codec isn't yet registered\n", __func__); |
| 303 | return 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 304 | } |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 305 | |
| 306 | WCD9XXX_BCL_LOCK(&priv->resmgr); |
| 307 | old = spkr_drv_wrnd; |
| 308 | ret = param_set_int(val, kp); |
| 309 | if (ret) { |
| 310 | WCD9XXX_BCL_UNLOCK(&priv->resmgr); |
| 311 | return ret; |
| 312 | } |
| 313 | |
| 314 | codec = priv->codec; |
| 315 | dev_dbg(codec->dev, "%s: spkr_drv_wrnd %d -> %d\n", |
| 316 | __func__, old, spkr_drv_wrnd); |
| 317 | if (old == 0 && spkr_drv_wrnd == 1) { |
| 318 | wcd9xxx_resmgr_get_bandgap(&priv->resmgr, |
| 319 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 320 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80); |
| 321 | } else if (old == 1 && spkr_drv_wrnd == 0) { |
| 322 | wcd9xxx_resmgr_put_bandgap(&priv->resmgr, |
| 323 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 324 | if (!priv->spkr_pa_widget_on) |
| 325 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, |
| 326 | 0x00); |
| 327 | } |
| 328 | |
| 329 | WCD9XXX_BCL_UNLOCK(&priv->resmgr); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 330 | return 0; |
| 331 | } |
| 332 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 333 | static int tapan_get_anc_slot(struct snd_kcontrol *kcontrol, |
| 334 | struct snd_ctl_elem_value *ucontrol) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 335 | { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 336 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 337 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 338 | ucontrol->value.integer.value[0] = tapan->anc_slot; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 339 | return 0; |
| 340 | } |
| 341 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 342 | static int tapan_put_anc_slot(struct snd_kcontrol *kcontrol, |
| 343 | struct snd_ctl_elem_value *ucontrol) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 344 | { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 345 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 346 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 347 | tapan->anc_slot = ucontrol->value.integer.value[0]; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 348 | return 0; |
| 349 | } |
| 350 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 351 | static int tapan_get_anc_func(struct snd_kcontrol *kcontrol, |
| 352 | struct snd_ctl_elem_value *ucontrol) |
| 353 | { |
| 354 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 355 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 356 | |
| 357 | ucontrol->value.integer.value[0] = (tapan->anc_func == true ? 1 : 0); |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | static int tapan_put_anc_func(struct snd_kcontrol *kcontrol, |
| 362 | struct snd_ctl_elem_value *ucontrol) |
| 363 | { |
| 364 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 365 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 366 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 367 | |
| 368 | mutex_lock(&dapm->codec->mutex); |
| 369 | tapan->anc_func = (!ucontrol->value.integer.value[0] ? false : true); |
| 370 | |
| 371 | dev_err(codec->dev, "%s: anc_func %x", __func__, tapan->anc_func); |
| 372 | |
| 373 | if (tapan->anc_func == true) { |
| 374 | pr_info("enable anc virtual widgets"); |
| 375 | snd_soc_dapm_enable_pin(dapm, "ANC HPHR"); |
| 376 | snd_soc_dapm_enable_pin(dapm, "ANC HPHL"); |
| 377 | snd_soc_dapm_enable_pin(dapm, "ANC HEADPHONE"); |
| 378 | snd_soc_dapm_enable_pin(dapm, "ANC EAR PA"); |
| 379 | snd_soc_dapm_enable_pin(dapm, "ANC EAR"); |
| 380 | snd_soc_dapm_disable_pin(dapm, "HPHR"); |
| 381 | snd_soc_dapm_disable_pin(dapm, "HPHL"); |
| 382 | snd_soc_dapm_disable_pin(dapm, "HEADPHONE"); |
| 383 | snd_soc_dapm_disable_pin(dapm, "EAR PA"); |
| 384 | snd_soc_dapm_disable_pin(dapm, "EAR"); |
| 385 | } else { |
| 386 | pr_info("disable anc virtual widgets"); |
| 387 | snd_soc_dapm_disable_pin(dapm, "ANC HPHR"); |
| 388 | snd_soc_dapm_disable_pin(dapm, "ANC HPHL"); |
| 389 | snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE"); |
| 390 | snd_soc_dapm_disable_pin(dapm, "ANC EAR PA"); |
| 391 | snd_soc_dapm_disable_pin(dapm, "ANC EAR"); |
| 392 | snd_soc_dapm_enable_pin(dapm, "HPHR"); |
| 393 | snd_soc_dapm_enable_pin(dapm, "HPHL"); |
| 394 | snd_soc_dapm_enable_pin(dapm, "HEADPHONE"); |
| 395 | snd_soc_dapm_enable_pin(dapm, "EAR PA"); |
| 396 | snd_soc_dapm_enable_pin(dapm, "EAR"); |
| 397 | } |
| 398 | snd_soc_dapm_sync(dapm); |
| 399 | mutex_unlock(&dapm->codec->mutex); |
| 400 | return 0; |
| 401 | } |
| 402 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 403 | static int tapan_pa_gain_get(struct snd_kcontrol *kcontrol, |
| 404 | struct snd_ctl_elem_value *ucontrol) |
| 405 | { |
| 406 | u8 ear_pa_gain; |
| 407 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 408 | |
| 409 | ear_pa_gain = snd_soc_read(codec, TAPAN_A_RX_EAR_GAIN); |
| 410 | |
| 411 | ear_pa_gain = ear_pa_gain >> 5; |
| 412 | |
| 413 | if (ear_pa_gain == 0x00) { |
| 414 | ucontrol->value.integer.value[0] = 0; |
| 415 | } else if (ear_pa_gain == 0x04) { |
| 416 | ucontrol->value.integer.value[0] = 1; |
| 417 | } else { |
| 418 | pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n", |
| 419 | __func__, ear_pa_gain); |
| 420 | return -EINVAL; |
| 421 | } |
| 422 | |
| 423 | dev_dbg(codec->dev, "%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain); |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | static int tapan_pa_gain_put(struct snd_kcontrol *kcontrol, |
| 429 | struct snd_ctl_elem_value *ucontrol) |
| 430 | { |
| 431 | u8 ear_pa_gain; |
| 432 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 433 | |
| 434 | dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n", |
| 435 | __func__, ucontrol->value.integer.value[0]); |
| 436 | |
| 437 | switch (ucontrol->value.integer.value[0]) { |
| 438 | case 0: |
| 439 | ear_pa_gain = 0x00; |
| 440 | break; |
| 441 | case 1: |
| 442 | ear_pa_gain = 0x80; |
| 443 | break; |
| 444 | default: |
| 445 | return -EINVAL; |
| 446 | } |
| 447 | |
| 448 | snd_soc_update_bits(codec, TAPAN_A_RX_EAR_GAIN, 0xE0, ear_pa_gain); |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | static int tapan_get_iir_enable_audio_mixer( |
| 453 | struct snd_kcontrol *kcontrol, |
| 454 | struct snd_ctl_elem_value *ucontrol) |
| 455 | { |
| 456 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 457 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 458 | kcontrol->private_value)->reg; |
| 459 | int band_idx = ((struct soc_multi_mixer_control *) |
| 460 | kcontrol->private_value)->shift; |
| 461 | |
| 462 | ucontrol->value.integer.value[0] = |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 463 | (snd_soc_read(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx)) & |
| 464 | (1 << band_idx)) != 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 465 | |
| 466 | dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__, |
| 467 | iir_idx, band_idx, |
| 468 | (uint32_t)ucontrol->value.integer.value[0]); |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | static int tapan_put_iir_enable_audio_mixer( |
| 473 | struct snd_kcontrol *kcontrol, |
| 474 | struct snd_ctl_elem_value *ucontrol) |
| 475 | { |
| 476 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 477 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 478 | kcontrol->private_value)->reg; |
| 479 | int band_idx = ((struct soc_multi_mixer_control *) |
| 480 | kcontrol->private_value)->shift; |
| 481 | int value = ucontrol->value.integer.value[0]; |
| 482 | |
| 483 | /* Mask first 5 bits, 6-8 are reserved */ |
| 484 | snd_soc_update_bits(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx), |
| 485 | (1 << band_idx), (value << band_idx)); |
| 486 | |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 487 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
| 488 | iir_idx, band_idx, |
| 489 | ((snd_soc_read(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx)) & |
| 490 | (1 << band_idx)) != 0)); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 491 | return 0; |
| 492 | } |
| 493 | static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec, |
| 494 | int iir_idx, int band_idx, |
| 495 | int coeff_idx) |
| 496 | { |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 497 | uint32_t value = 0; |
| 498 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 499 | /* Address does not automatically update if reading */ |
| 500 | snd_soc_write(codec, |
| 501 | (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 502 | ((band_idx * BAND_MAX + coeff_idx) |
| 503 | * sizeof(uint32_t)) & 0x7F); |
| 504 | |
| 505 | value |= snd_soc_read(codec, |
| 506 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)); |
| 507 | |
| 508 | snd_soc_write(codec, |
| 509 | (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
| 510 | ((band_idx * BAND_MAX + coeff_idx) |
| 511 | * sizeof(uint32_t) + 1) & 0x7F); |
| 512 | |
| 513 | value |= (snd_soc_read(codec, |
| 514 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 8); |
| 515 | |
| 516 | snd_soc_write(codec, |
| 517 | (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
| 518 | ((band_idx * BAND_MAX + coeff_idx) |
| 519 | * sizeof(uint32_t) + 2) & 0x7F); |
| 520 | |
| 521 | value |= (snd_soc_read(codec, |
| 522 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 16); |
| 523 | |
| 524 | snd_soc_write(codec, |
| 525 | (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
| 526 | ((band_idx * BAND_MAX + coeff_idx) |
| 527 | * sizeof(uint32_t) + 3) & 0x7F); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 528 | |
| 529 | /* Mask bits top 2 bits since they are reserved */ |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 530 | value |= ((snd_soc_read(codec, |
| 531 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) & 0x3F) << 24); |
| 532 | |
| 533 | return value; |
| 534 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | static int tapan_get_iir_band_audio_mixer( |
| 538 | struct snd_kcontrol *kcontrol, |
| 539 | struct snd_ctl_elem_value *ucontrol) |
| 540 | { |
| 541 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 542 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 543 | kcontrol->private_value)->reg; |
| 544 | int band_idx = ((struct soc_multi_mixer_control *) |
| 545 | kcontrol->private_value)->shift; |
| 546 | |
| 547 | ucontrol->value.integer.value[0] = |
| 548 | get_iir_band_coeff(codec, iir_idx, band_idx, 0); |
| 549 | ucontrol->value.integer.value[1] = |
| 550 | get_iir_band_coeff(codec, iir_idx, band_idx, 1); |
| 551 | ucontrol->value.integer.value[2] = |
| 552 | get_iir_band_coeff(codec, iir_idx, band_idx, 2); |
| 553 | ucontrol->value.integer.value[3] = |
| 554 | get_iir_band_coeff(codec, iir_idx, band_idx, 3); |
| 555 | ucontrol->value.integer.value[4] = |
| 556 | get_iir_band_coeff(codec, iir_idx, band_idx, 4); |
| 557 | |
| 558 | dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n" |
| 559 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 560 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 561 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 562 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 563 | __func__, iir_idx, band_idx, |
| 564 | (uint32_t)ucontrol->value.integer.value[0], |
| 565 | __func__, iir_idx, band_idx, |
| 566 | (uint32_t)ucontrol->value.integer.value[1], |
| 567 | __func__, iir_idx, band_idx, |
| 568 | (uint32_t)ucontrol->value.integer.value[2], |
| 569 | __func__, iir_idx, band_idx, |
| 570 | (uint32_t)ucontrol->value.integer.value[3], |
| 571 | __func__, iir_idx, band_idx, |
| 572 | (uint32_t)ucontrol->value.integer.value[4]); |
| 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | static void set_iir_band_coeff(struct snd_soc_codec *codec, |
| 577 | int iir_idx, int band_idx, |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 578 | uint32_t value) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 579 | { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 580 | snd_soc_write(codec, |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 581 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
| 582 | (value & 0xFF)); |
| 583 | |
| 584 | snd_soc_write(codec, |
| 585 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
| 586 | (value >> 8) & 0xFF); |
| 587 | |
| 588 | snd_soc_write(codec, |
| 589 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
| 590 | (value >> 16) & 0xFF); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 591 | |
| 592 | /* Mask top 2 bits, 7-8 are reserved */ |
| 593 | snd_soc_write(codec, |
| 594 | (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
| 595 | (value >> 24) & 0x3F); |
| 596 | |
| 597 | } |
| 598 | |
| 599 | static int tapan_put_iir_band_audio_mixer( |
| 600 | struct snd_kcontrol *kcontrol, |
| 601 | struct snd_ctl_elem_value *ucontrol) |
| 602 | { |
| 603 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 604 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 605 | kcontrol->private_value)->reg; |
| 606 | int band_idx = ((struct soc_multi_mixer_control *) |
| 607 | kcontrol->private_value)->shift; |
| 608 | |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 609 | /* Mask top bit it is reserved */ |
| 610 | /* Updates addr automatically for each B2 write */ |
| 611 | snd_soc_write(codec, |
| 612 | (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
| 613 | (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F); |
| 614 | |
| 615 | set_iir_band_coeff(codec, iir_idx, band_idx, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 616 | ucontrol->value.integer.value[0]); |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 617 | set_iir_band_coeff(codec, iir_idx, band_idx, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 618 | ucontrol->value.integer.value[1]); |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 619 | set_iir_band_coeff(codec, iir_idx, band_idx, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 620 | ucontrol->value.integer.value[2]); |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 621 | set_iir_band_coeff(codec, iir_idx, band_idx, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 622 | ucontrol->value.integer.value[3]); |
Phani Kumar Uppalapati | 4a7b76f | 2013-04-26 13:47:24 -0700 | [diff] [blame] | 623 | set_iir_band_coeff(codec, iir_idx, band_idx, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 624 | ucontrol->value.integer.value[4]); |
| 625 | |
| 626 | dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n" |
| 627 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 628 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 629 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 630 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 631 | __func__, iir_idx, band_idx, |
| 632 | get_iir_band_coeff(codec, iir_idx, band_idx, 0), |
| 633 | __func__, iir_idx, band_idx, |
| 634 | get_iir_band_coeff(codec, iir_idx, band_idx, 1), |
| 635 | __func__, iir_idx, band_idx, |
| 636 | get_iir_band_coeff(codec, iir_idx, band_idx, 2), |
| 637 | __func__, iir_idx, band_idx, |
| 638 | get_iir_band_coeff(codec, iir_idx, band_idx, 3), |
| 639 | __func__, iir_idx, band_idx, |
| 640 | get_iir_band_coeff(codec, iir_idx, band_idx, 4)); |
| 641 | return 0; |
| 642 | } |
| 643 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 644 | static int tapan_get_compander(struct snd_kcontrol *kcontrol, |
| 645 | struct snd_ctl_elem_value *ucontrol) |
| 646 | { |
| 647 | |
| 648 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 649 | int comp = ((struct soc_multi_mixer_control *) |
| 650 | kcontrol->private_value)->shift; |
| 651 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 652 | |
| 653 | ucontrol->value.integer.value[0] = tapan->comp_enabled[comp]; |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | static int tapan_set_compander(struct snd_kcontrol *kcontrol, |
| 658 | struct snd_ctl_elem_value *ucontrol) |
| 659 | { |
| 660 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 661 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 662 | int comp = ((struct soc_multi_mixer_control *) |
| 663 | kcontrol->private_value)->shift; |
| 664 | int value = ucontrol->value.integer.value[0]; |
| 665 | |
| 666 | dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n", |
| 667 | __func__, comp, tapan->comp_enabled[comp], value); |
| 668 | tapan->comp_enabled[comp] = value; |
| 669 | return 0; |
| 670 | } |
| 671 | |
| 672 | static int tapan_config_gain_compander(struct snd_soc_codec *codec, |
| 673 | int comp, bool enable) |
| 674 | { |
| 675 | int ret = 0; |
| 676 | |
| 677 | switch (comp) { |
| 678 | case COMPANDER_0: |
| 679 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_GAIN, |
| 680 | 1 << 2, !enable << 2); |
| 681 | break; |
| 682 | case COMPANDER_1: |
| 683 | snd_soc_update_bits(codec, TAPAN_A_RX_HPH_L_GAIN, |
| 684 | 1 << 5, !enable << 5); |
| 685 | snd_soc_update_bits(codec, TAPAN_A_RX_HPH_R_GAIN, |
| 686 | 1 << 5, !enable << 5); |
| 687 | break; |
| 688 | case COMPANDER_2: |
| 689 | snd_soc_update_bits(codec, TAPAN_A_RX_LINE_1_GAIN, |
| 690 | 1 << 5, !enable << 5); |
| 691 | snd_soc_update_bits(codec, TAPAN_A_RX_LINE_2_GAIN, |
| 692 | 1 << 5, !enable << 5); |
| 693 | break; |
| 694 | default: |
| 695 | WARN_ON(1); |
| 696 | ret = -EINVAL; |
| 697 | } |
| 698 | |
| 699 | return ret; |
| 700 | } |
| 701 | |
| 702 | static void tapan_discharge_comp(struct snd_soc_codec *codec, int comp) |
| 703 | { |
| 704 | /* Update RSM to 1, DIVF to 5 */ |
| 705 | snd_soc_write(codec, TAPAN_A_CDC_COMP0_B3_CTL + (comp * 8), 1); |
| 706 | snd_soc_update_bits(codec, TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8), 0xF0, |
| 707 | 1 << 5); |
| 708 | /* Wait for 1ms */ |
| 709 | usleep_range(1000, 1000); |
| 710 | } |
| 711 | |
| 712 | static int tapan_config_compander(struct snd_soc_dapm_widget *w, |
| 713 | struct snd_kcontrol *kcontrol, int event) |
| 714 | { |
| 715 | int mask, emask; |
| 716 | bool timedout; |
| 717 | unsigned long timeout; |
| 718 | struct snd_soc_codec *codec = w->codec; |
| 719 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 720 | const int comp = w->shift; |
| 721 | const u32 rate = tapan->comp_fs[comp]; |
| 722 | const struct comp_sample_dependent_params *comp_params = |
| 723 | &comp_samp_params[rate]; |
| 724 | |
| 725 | dev_dbg(codec->dev, "%s: %s event %d compander %d, enabled %d", |
| 726 | __func__, w->name, event, comp, tapan->comp_enabled[comp]); |
| 727 | |
| 728 | if (!tapan->comp_enabled[comp]) |
| 729 | return 0; |
| 730 | |
| 731 | /* Compander 0 has single channel */ |
| 732 | mask = (comp == COMPANDER_0 ? 0x01 : 0x03); |
| 733 | emask = (comp == COMPANDER_0 ? 0x02 : 0x03); |
| 734 | |
| 735 | switch (event) { |
| 736 | case SND_SOC_DAPM_PRE_PMU: |
| 737 | /* Set gain source to compander */ |
| 738 | tapan_config_gain_compander(codec, comp, true); |
| 739 | /* Enable RX interpolation path clocks */ |
| 740 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_B2_CTL, |
| 741 | mask << comp_shift[comp], |
| 742 | mask << comp_shift[comp]); |
| 743 | |
| 744 | tapan_discharge_comp(codec, comp); |
| 745 | |
| 746 | /* Clear compander halt */ |
| 747 | snd_soc_update_bits(codec, TAPAN_A_CDC_COMP0_B1_CTL + |
| 748 | (comp * 8), |
| 749 | 1 << 2, 0); |
| 750 | /* Toggle compander reset bits */ |
| 751 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL, |
| 752 | mask << comp_shift[comp], |
| 753 | mask << comp_shift[comp]); |
| 754 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL, |
| 755 | mask << comp_shift[comp], 0); |
| 756 | break; |
| 757 | case SND_SOC_DAPM_POST_PMU: |
| 758 | /* Set sample rate dependent paramater */ |
| 759 | snd_soc_update_bits(codec, |
| 760 | TAPAN_A_CDC_COMP0_FS_CFG + (comp * 8), |
| 761 | 0x07, rate); |
| 762 | snd_soc_write(codec, TAPAN_A_CDC_COMP0_B3_CTL + (comp * 8), |
| 763 | comp_params->rms_meter_resamp_fact); |
| 764 | snd_soc_update_bits(codec, |
| 765 | TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8), |
| 766 | 0x0F, comp_params->peak_det_timeout); |
| 767 | snd_soc_update_bits(codec, |
| 768 | TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8), |
| 769 | 0xF0, comp_params->rms_meter_div_fact << 4); |
| 770 | /* Compander enable */ |
| 771 | snd_soc_update_bits(codec, TAPAN_A_CDC_COMP0_B1_CTL + |
| 772 | (comp * 8), emask, emask); |
| 773 | break; |
| 774 | case SND_SOC_DAPM_PRE_PMD: |
| 775 | /* Halt compander */ |
| 776 | snd_soc_update_bits(codec, |
| 777 | TAPAN_A_CDC_COMP0_B1_CTL + (comp * 8), |
| 778 | 1 << 2, 1 << 2); |
| 779 | /* Wait up to a second for shutdown complete */ |
| 780 | timeout = jiffies + HZ; |
| 781 | do { |
| 782 | if ((snd_soc_read(codec, |
| 783 | TAPAN_A_CDC_COMP0_SHUT_DOWN_STATUS + |
| 784 | (comp * 8)) & mask) == mask) |
| 785 | break; |
| 786 | } while (!(timedout = time_after(jiffies, timeout))); |
| 787 | dev_dbg(codec->dev, "%s: Compander %d shutdown %s in %dms\n", |
| 788 | __func__, comp, timedout ? "timedout" : "completed", |
| 789 | jiffies_to_msecs(timeout - HZ - jiffies)); |
| 790 | break; |
| 791 | case SND_SOC_DAPM_POST_PMD: |
| 792 | /* Disable compander */ |
| 793 | snd_soc_update_bits(codec, |
| 794 | TAPAN_A_CDC_COMP0_B1_CTL + (comp * 8), |
| 795 | emask, 0x00); |
| 796 | /* Turn off the clock for compander in pair */ |
| 797 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_B2_CTL, |
| 798 | mask << comp_shift[comp], 0); |
| 799 | /* Set gain source to register */ |
| 800 | tapan_config_gain_compander(codec, comp, false); |
| 801 | break; |
| 802 | } |
| 803 | return 0; |
| 804 | } |
| 805 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 806 | static const char * const tapan_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"}; |
| 807 | static const struct soc_enum tapan_ear_pa_gain_enum[] = { |
| 808 | SOC_ENUM_SINGLE_EXT(2, tapan_ear_pa_gain_text), |
| 809 | }; |
| 810 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 811 | static const char *const tapan_anc_func_text[] = {"OFF", "ON"}; |
| 812 | static const struct soc_enum tapan_anc_func_enum = |
| 813 | SOC_ENUM_SINGLE_EXT(2, tapan_anc_func_text); |
| 814 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 815 | /*cut of frequency for high pass filter*/ |
| 816 | static const char * const cf_text[] = { |
| 817 | "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz" |
| 818 | }; |
| 819 | |
| 820 | static const struct soc_enum cf_dec1_enum = |
| 821 | SOC_ENUM_SINGLE(TAPAN_A_CDC_TX1_MUX_CTL, 4, 3, cf_text); |
| 822 | |
| 823 | static const struct soc_enum cf_dec2_enum = |
| 824 | SOC_ENUM_SINGLE(TAPAN_A_CDC_TX2_MUX_CTL, 4, 3, cf_text); |
| 825 | |
| 826 | static const struct soc_enum cf_dec3_enum = |
| 827 | SOC_ENUM_SINGLE(TAPAN_A_CDC_TX3_MUX_CTL, 4, 3, cf_text); |
| 828 | |
| 829 | static const struct soc_enum cf_dec4_enum = |
| 830 | SOC_ENUM_SINGLE(TAPAN_A_CDC_TX4_MUX_CTL, 4, 3, cf_text); |
| 831 | |
| 832 | static const struct soc_enum cf_rxmix1_enum = |
Joonwoo Park | 2000a98 | 2013-03-01 14:50:31 -0800 | [diff] [blame] | 833 | 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] | 834 | |
| 835 | static const struct soc_enum cf_rxmix2_enum = |
Joonwoo Park | 2000a98 | 2013-03-01 14:50:31 -0800 | [diff] [blame] | 836 | 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] | 837 | |
| 838 | static const struct soc_enum cf_rxmix3_enum = |
Joonwoo Park | 2000a98 | 2013-03-01 14:50:31 -0800 | [diff] [blame] | 839 | 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] | 840 | |
| 841 | static const struct soc_enum cf_rxmix4_enum = |
Joonwoo Park | 2000a98 | 2013-03-01 14:50:31 -0800 | [diff] [blame] | 842 | 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] | 843 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 844 | static const char * const class_h_dsm_text[] = { |
| 845 | "ZERO", "RX_HPHL", "RX_SPKR" |
| 846 | }; |
| 847 | |
| 848 | static const struct soc_enum class_h_dsm_enum = |
| 849 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_CLSH_CTL, 2, 3, class_h_dsm_text); |
| 850 | |
| 851 | static const struct snd_kcontrol_new class_h_dsm_mux = |
| 852 | SOC_DAPM_ENUM("CLASS_H_DSM MUX Mux", class_h_dsm_enum); |
| 853 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 854 | static const struct snd_kcontrol_new tapan_snd_controls[] = { |
| 855 | |
| 856 | SOC_ENUM_EXT("EAR PA Gain", tapan_ear_pa_gain_enum[0], |
| 857 | tapan_pa_gain_get, tapan_pa_gain_put), |
| 858 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 859 | SOC_SINGLE_TLV("HPHL Volume", TAPAN_A_RX_HPH_L_GAIN, 0, 14, 1, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 860 | line_gain), |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 861 | SOC_SINGLE_TLV("HPHR Volume", TAPAN_A_RX_HPH_R_GAIN, 0, 14, 1, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 862 | line_gain), |
| 863 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 864 | SOC_SINGLE_TLV("LINEOUT1 Volume", TAPAN_A_RX_LINE_1_GAIN, 0, 14, 1, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 865 | line_gain), |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 866 | SOC_SINGLE_TLV("LINEOUT2 Volume", TAPAN_A_RX_LINE_2_GAIN, 0, 14, 1, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 867 | line_gain), |
| 868 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 869 | SOC_SINGLE_TLV("SPK DRV Volume", TAPAN_A_SPKR_DRV_GAIN, 3, 7, 1, |
| 870 | line_gain), |
| 871 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 872 | SOC_SINGLE_TLV("ADC1 Volume", TAPAN_A_TX_1_EN, 2, 19, 0, analog_gain), |
| 873 | SOC_SINGLE_TLV("ADC2 Volume", TAPAN_A_TX_2_EN, 2, 19, 0, analog_gain), |
| 874 | SOC_SINGLE_TLV("ADC3 Volume", TAPAN_A_TX_3_EN, 2, 19, 0, analog_gain), |
| 875 | SOC_SINGLE_TLV("ADC4 Volume", TAPAN_A_TX_4_EN, 2, 19, 0, analog_gain), |
| 876 | SOC_SINGLE_TLV("ADC5 Volume", TAPAN_A_TX_5_EN, 2, 19, 0, analog_gain), |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 877 | |
Jay Chokshi | 83b4f613 | 2013-02-14 16:20:56 -0800 | [diff] [blame] | 878 | SOC_SINGLE_S8_TLV("RX1 Digital Volume", TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 879 | -84, 40, digital_gain), |
| 880 | SOC_SINGLE_S8_TLV("RX2 Digital Volume", TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 881 | -84, 40, digital_gain), |
| 882 | SOC_SINGLE_S8_TLV("RX3 Digital Volume", TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 883 | -84, 40, digital_gain), |
| 884 | SOC_SINGLE_S8_TLV("RX4 Digital Volume", TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 885 | -84, 40, digital_gain), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 886 | |
Jay Chokshi | 83b4f613 | 2013-02-14 16:20:56 -0800 | [diff] [blame] | 887 | SOC_SINGLE_S8_TLV("DEC1 Volume", TAPAN_A_CDC_TX1_VOL_CTL_GAIN, -84, 40, |
| 888 | digital_gain), |
| 889 | SOC_SINGLE_S8_TLV("DEC2 Volume", TAPAN_A_CDC_TX2_VOL_CTL_GAIN, -84, 40, |
| 890 | digital_gain), |
| 891 | SOC_SINGLE_S8_TLV("DEC3 Volume", TAPAN_A_CDC_TX3_VOL_CTL_GAIN, -84, 40, |
| 892 | digital_gain), |
| 893 | SOC_SINGLE_S8_TLV("DEC4 Volume", TAPAN_A_CDC_TX4_VOL_CTL_GAIN, -84, 40, |
| 894 | digital_gain), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 895 | |
Jay Chokshi | 83b4f613 | 2013-02-14 16:20:56 -0800 | [diff] [blame] | 896 | SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TAPAN_A_CDC_IIR1_GAIN_B1_CTL, -84, |
| 897 | 40, digital_gain), |
| 898 | SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TAPAN_A_CDC_IIR1_GAIN_B2_CTL, -84, |
| 899 | 40, digital_gain), |
| 900 | SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TAPAN_A_CDC_IIR1_GAIN_B3_CTL, -84, |
| 901 | 40, digital_gain), |
| 902 | SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TAPAN_A_CDC_IIR1_GAIN_B4_CTL, -84, |
| 903 | 40, digital_gain), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 904 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 905 | SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 100, 0, tapan_get_anc_slot, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 906 | tapan_put_anc_slot), |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 907 | SOC_ENUM_EXT("ANC Function", tapan_anc_func_enum, tapan_get_anc_func, |
| 908 | tapan_put_anc_func), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 909 | SOC_ENUM("TX1 HPF cut off", cf_dec1_enum), |
| 910 | SOC_ENUM("TX2 HPF cut off", cf_dec2_enum), |
| 911 | SOC_ENUM("TX3 HPF cut off", cf_dec3_enum), |
| 912 | SOC_ENUM("TX4 HPF cut off", cf_dec4_enum), |
| 913 | |
| 914 | SOC_SINGLE("TX1 HPF Switch", TAPAN_A_CDC_TX1_MUX_CTL, 3, 1, 0), |
| 915 | SOC_SINGLE("TX2 HPF Switch", TAPAN_A_CDC_TX2_MUX_CTL, 3, 1, 0), |
| 916 | SOC_SINGLE("TX3 HPF Switch", TAPAN_A_CDC_TX3_MUX_CTL, 3, 1, 0), |
| 917 | SOC_SINGLE("TX4 HPF Switch", TAPAN_A_CDC_TX4_MUX_CTL, 3, 1, 0), |
| 918 | |
| 919 | SOC_SINGLE("RX1 HPF Switch", TAPAN_A_CDC_RX1_B5_CTL, 2, 1, 0), |
| 920 | SOC_SINGLE("RX2 HPF Switch", TAPAN_A_CDC_RX2_B5_CTL, 2, 1, 0), |
| 921 | SOC_SINGLE("RX3 HPF Switch", TAPAN_A_CDC_RX3_B5_CTL, 2, 1, 0), |
| 922 | SOC_SINGLE("RX4 HPF Switch", TAPAN_A_CDC_RX4_B5_CTL, 2, 1, 0), |
| 923 | |
| 924 | SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum), |
| 925 | SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum), |
| 926 | SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum), |
| 927 | SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum), |
| 928 | |
| 929 | SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0, |
| 930 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 931 | SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0, |
| 932 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 933 | SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0, |
| 934 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 935 | SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0, |
| 936 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 937 | SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0, |
| 938 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 939 | SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0, |
| 940 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 941 | SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0, |
| 942 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 943 | SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0, |
| 944 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 945 | SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0, |
| 946 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 947 | SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0, |
| 948 | tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer), |
| 949 | |
| 950 | SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5, |
| 951 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 952 | SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5, |
| 953 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 954 | SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5, |
| 955 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 956 | SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5, |
| 957 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 958 | SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5, |
| 959 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 960 | SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5, |
| 961 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 962 | SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5, |
| 963 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 964 | SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5, |
| 965 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 966 | SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5, |
| 967 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 968 | SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5, |
| 969 | tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer), |
| 970 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 971 | SOC_SINGLE_EXT("COMP0 Switch", SND_SOC_NOPM, COMPANDER_0, 1, 0, |
| 972 | tapan_get_compander, tapan_set_compander), |
| 973 | SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, COMPANDER_1, 1, 0, |
| 974 | tapan_get_compander, tapan_set_compander), |
| 975 | SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, COMPANDER_2, 1, 0, |
| 976 | tapan_get_compander, tapan_set_compander), |
| 977 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 978 | }; |
| 979 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 980 | static const char * const rx_1_2_mix1_text[] = { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 981 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4", |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 982 | "RX5", "AUXRX", "AUXTX1" |
| 983 | }; |
| 984 | |
| 985 | static const char * const rx_3_4_mix1_text[] = { |
| 986 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4", |
| 987 | "RX5", "AUXRX", "AUXTX1", "AUXTX2" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 988 | }; |
| 989 | |
| 990 | static const char * const rx_mix2_text[] = { |
| 991 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2" |
| 992 | }; |
| 993 | |
| 994 | static const char * const rx_rdac5_text[] = { |
| 995 | "DEM4", "DEM3_INV" |
| 996 | }; |
| 997 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 998 | static const char * const sb_tx_1_2_mux_text[] = { |
| 999 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", |
| 1000 | "RSVD", "RSVD", "RSVD", |
| 1001 | "DEC1", "DEC2", "DEC3", "DEC4" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1002 | }; |
| 1003 | |
| 1004 | static const char * const sb_tx3_mux_text[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1005 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", |
| 1006 | "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", |
| 1007 | "DEC3" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1008 | }; |
| 1009 | |
| 1010 | static const char * const sb_tx4_mux_text[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1011 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", |
| 1012 | "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", |
| 1013 | "DEC4" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1014 | }; |
| 1015 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1016 | static const char * const sb_tx5_mux_text[] = { |
| 1017 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", |
| 1018 | "RSVD", "RSVD", "RSVD", |
| 1019 | "DEC1" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1020 | }; |
| 1021 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1022 | static const char * const dec_1_2_mux_text[] = { |
| 1023 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADCMB", |
| 1024 | "DMIC1", "DMIC2", "DMIC3", "DMIC4" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1025 | }; |
| 1026 | |
| 1027 | static const char * const dec3_mux_text[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1028 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADCMB", |
| 1029 | "DMIC1", "DMIC2", "DMIC3", "DMIC4", |
| 1030 | "ANCFBTUNE1" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1031 | }; |
| 1032 | |
| 1033 | static const char * const dec4_mux_text[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1034 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADCMB", |
| 1035 | "DMIC1", "DMIC2", "DMIC3", "DMIC4", |
| 1036 | "ANCFBTUNE2" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1037 | }; |
| 1038 | |
| 1039 | static const char * const anc_mux_text[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1040 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", |
| 1041 | "RSVD", "RSVD", "RSVD", |
| 1042 | "DMIC1", "DMIC2", "DMIC3", "DMIC4", |
| 1043 | "RSVD", "RSVD" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1044 | }; |
| 1045 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1046 | static const char * const anc1_fb_mux_text[] = { |
| 1047 | "ZERO", "EAR_HPH_L", "EAR_LINE_1", |
| 1048 | }; |
| 1049 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1050 | static const char * const iir1_inp1_text[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1051 | "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", |
| 1052 | "RX1", "RX2", "RX3", "RX4", "RX5" |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1053 | }; |
| 1054 | |
| 1055 | static const struct soc_enum rx_mix1_inp1_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1056 | 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] | 1057 | |
| 1058 | static const struct soc_enum rx_mix1_inp2_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1059 | 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] | 1060 | |
| 1061 | static const struct soc_enum rx_mix1_inp3_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1062 | 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] | 1063 | |
| 1064 | static const struct soc_enum rx2_mix1_inp1_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1065 | 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] | 1066 | |
| 1067 | static const struct soc_enum rx2_mix1_inp2_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1068 | 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] | 1069 | |
| 1070 | static const struct soc_enum rx3_mix1_inp1_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1071 | 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] | 1072 | |
| 1073 | static const struct soc_enum rx3_mix1_inp2_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1074 | 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] | 1075 | |
| 1076 | static const struct soc_enum rx4_mix1_inp1_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1077 | 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] | 1078 | |
| 1079 | static const struct soc_enum rx4_mix1_inp2_chain_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1080 | 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] | 1081 | |
| 1082 | static const struct soc_enum rx1_mix2_inp1_chain_enum = |
| 1083 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text); |
| 1084 | |
| 1085 | static const struct soc_enum rx1_mix2_inp2_chain_enum = |
| 1086 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text); |
| 1087 | |
| 1088 | static const struct soc_enum rx2_mix2_inp1_chain_enum = |
| 1089 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text); |
| 1090 | |
| 1091 | static const struct soc_enum rx2_mix2_inp2_chain_enum = |
| 1092 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text); |
| 1093 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1094 | static const struct soc_enum rx4_mix2_inp1_chain_enum = |
| 1095 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B3_CTL, 0, 5, rx_mix2_text); |
| 1096 | |
| 1097 | static const struct soc_enum rx4_mix2_inp2_chain_enum = |
| 1098 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B3_CTL, 3, 5, rx_mix2_text); |
| 1099 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1100 | static const struct soc_enum rx_rdac5_enum = |
| 1101 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_MISC, 2, 2, rx_rdac5_text); |
| 1102 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1103 | static const struct soc_enum sb_tx1_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1104 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B1_CTL, 0, 12, |
| 1105 | sb_tx_1_2_mux_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1106 | |
| 1107 | static const struct soc_enum sb_tx2_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1108 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B2_CTL, 0, 12, |
| 1109 | sb_tx_1_2_mux_text); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1110 | |
| 1111 | static const struct soc_enum sb_tx3_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1112 | 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] | 1113 | |
| 1114 | static const struct soc_enum sb_tx4_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1115 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B4_CTL, 0, 12, sb_tx4_mux_text); |
| 1116 | |
| 1117 | static const struct soc_enum sb_tx5_mux_enum = |
| 1118 | 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] | 1119 | |
| 1120 | static const struct soc_enum dec1_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1121 | 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] | 1122 | |
| 1123 | static const struct soc_enum dec2_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1124 | 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] | 1125 | |
| 1126 | static const struct soc_enum dec3_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1127 | 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] | 1128 | |
| 1129 | static const struct soc_enum dec4_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1130 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B2_CTL, 4, 12, dec4_mux_text); |
| 1131 | |
| 1132 | static const struct soc_enum anc1_mux_enum = |
| 1133 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B1_CTL, 0, 15, anc_mux_text); |
| 1134 | |
| 1135 | static const struct soc_enum anc2_mux_enum = |
| 1136 | 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] | 1137 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1138 | static const struct soc_enum anc1_fb_mux_enum = |
| 1139 | SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text); |
| 1140 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1141 | static const struct soc_enum iir1_inp1_mux_enum = |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1142 | 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] | 1143 | |
| 1144 | static const struct snd_kcontrol_new rx_mix1_inp1_mux = |
| 1145 | SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum); |
| 1146 | |
| 1147 | static const struct snd_kcontrol_new rx_mix1_inp2_mux = |
| 1148 | SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum); |
| 1149 | |
| 1150 | static const struct snd_kcontrol_new rx_mix1_inp3_mux = |
| 1151 | SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum); |
| 1152 | |
| 1153 | static const struct snd_kcontrol_new rx2_mix1_inp1_mux = |
| 1154 | SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum); |
| 1155 | |
| 1156 | static const struct snd_kcontrol_new rx2_mix1_inp2_mux = |
| 1157 | SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum); |
| 1158 | |
| 1159 | static const struct snd_kcontrol_new rx3_mix1_inp1_mux = |
| 1160 | SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum); |
| 1161 | |
| 1162 | static const struct snd_kcontrol_new rx3_mix1_inp2_mux = |
| 1163 | SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum); |
| 1164 | |
| 1165 | static const struct snd_kcontrol_new rx4_mix1_inp1_mux = |
| 1166 | SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum); |
| 1167 | |
| 1168 | static const struct snd_kcontrol_new rx4_mix1_inp2_mux = |
| 1169 | SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum); |
| 1170 | |
| 1171 | static const struct snd_kcontrol_new rx1_mix2_inp1_mux = |
| 1172 | SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum); |
| 1173 | |
| 1174 | static const struct snd_kcontrol_new rx1_mix2_inp2_mux = |
| 1175 | SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum); |
| 1176 | |
| 1177 | static const struct snd_kcontrol_new rx2_mix2_inp1_mux = |
| 1178 | SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum); |
| 1179 | |
| 1180 | static const struct snd_kcontrol_new rx2_mix2_inp2_mux = |
| 1181 | SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum); |
| 1182 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1183 | static const struct snd_kcontrol_new rx4_mix2_inp1_mux = |
| 1184 | SOC_DAPM_ENUM("RX4 MIX2 INP1 Mux", rx4_mix2_inp1_chain_enum); |
| 1185 | |
| 1186 | static const struct snd_kcontrol_new rx4_mix2_inp2_mux = |
| 1187 | SOC_DAPM_ENUM("RX4 MIX2 INP2 Mux", rx4_mix2_inp2_chain_enum); |
| 1188 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1189 | static const struct snd_kcontrol_new rx_dac5_mux = |
| 1190 | SOC_DAPM_ENUM("RDAC5 MUX Mux", rx_rdac5_enum); |
| 1191 | |
| 1192 | static const struct snd_kcontrol_new sb_tx1_mux = |
| 1193 | SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum); |
| 1194 | |
| 1195 | static const struct snd_kcontrol_new sb_tx2_mux = |
| 1196 | SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum); |
| 1197 | |
| 1198 | static const struct snd_kcontrol_new sb_tx3_mux = |
| 1199 | SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum); |
| 1200 | |
| 1201 | static const struct snd_kcontrol_new sb_tx4_mux = |
| 1202 | SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum); |
| 1203 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1204 | static const struct snd_kcontrol_new sb_tx5_mux = |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1205 | SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1206 | |
| 1207 | static int wcd9306_put_dec_enum(struct snd_kcontrol *kcontrol, |
| 1208 | struct snd_ctl_elem_value *ucontrol) |
| 1209 | { |
| 1210 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1211 | struct snd_soc_dapm_widget *w = wlist->widgets[0]; |
| 1212 | struct snd_soc_codec *codec = w->codec; |
| 1213 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1214 | unsigned int dec_mux, decimator; |
| 1215 | char *dec_name = NULL; |
| 1216 | char *widget_name = NULL; |
| 1217 | char *temp; |
| 1218 | u16 tx_mux_ctl_reg; |
| 1219 | u8 adc_dmic_sel = 0x0; |
| 1220 | int ret = 0; |
| 1221 | |
| 1222 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 1223 | return -EINVAL; |
| 1224 | |
| 1225 | dec_mux = ucontrol->value.enumerated.item[0]; |
| 1226 | |
| 1227 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 1228 | if (!widget_name) |
| 1229 | return -ENOMEM; |
| 1230 | temp = widget_name; |
| 1231 | |
| 1232 | dec_name = strsep(&widget_name, " "); |
| 1233 | widget_name = temp; |
| 1234 | if (!dec_name) { |
| 1235 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 1236 | ret = -EINVAL; |
| 1237 | goto out; |
| 1238 | } |
| 1239 | |
| 1240 | ret = kstrtouint(strpbrk(dec_name, "1234"), 10, &decimator); |
| 1241 | if (ret < 0) { |
| 1242 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 1243 | ret = -EINVAL; |
| 1244 | goto out; |
| 1245 | } |
| 1246 | |
| 1247 | dev_dbg(w->dapm->dev, "%s(): widget = %s decimator = %u dec_mux = %u\n" |
| 1248 | , __func__, w->name, decimator, dec_mux); |
| 1249 | |
| 1250 | switch (decimator) { |
| 1251 | case 1: |
| 1252 | case 2: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1253 | if ((dec_mux >= 1) && (dec_mux <= 5)) |
| 1254 | adc_dmic_sel = 0x0; |
| 1255 | else if ((dec_mux >= 6) && (dec_mux <= 9)) |
| 1256 | adc_dmic_sel = 0x1; |
| 1257 | break; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1258 | case 3: |
| 1259 | case 4: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1260 | if ((dec_mux >= 1) && (dec_mux <= 6)) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1261 | adc_dmic_sel = 0x0; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1262 | else if ((dec_mux >= 7) && (dec_mux <= 10)) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1263 | adc_dmic_sel = 0x1; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1264 | break; |
| 1265 | default: |
| 1266 | pr_err("%s: Invalid Decimator = %u\n", __func__, decimator); |
| 1267 | ret = -EINVAL; |
| 1268 | goto out; |
| 1269 | } |
| 1270 | |
| 1271 | tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 1272 | |
| 1273 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel); |
| 1274 | |
| 1275 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 1276 | |
| 1277 | out: |
| 1278 | kfree(widget_name); |
| 1279 | return ret; |
| 1280 | } |
| 1281 | |
| 1282 | #define WCD9306_DEC_ENUM(xname, xenum) \ |
| 1283 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 1284 | .info = snd_soc_info_enum_double, \ |
| 1285 | .get = snd_soc_dapm_get_enum_double, \ |
| 1286 | .put = wcd9306_put_dec_enum, \ |
| 1287 | .private_value = (unsigned long)&xenum } |
| 1288 | |
| 1289 | static const struct snd_kcontrol_new dec1_mux = |
| 1290 | WCD9306_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum); |
| 1291 | |
| 1292 | static const struct snd_kcontrol_new dec2_mux = |
| 1293 | WCD9306_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum); |
| 1294 | |
| 1295 | static const struct snd_kcontrol_new dec3_mux = |
| 1296 | WCD9306_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum); |
| 1297 | |
| 1298 | static const struct snd_kcontrol_new dec4_mux = |
| 1299 | WCD9306_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum); |
| 1300 | |
| 1301 | static const struct snd_kcontrol_new iir1_inp1_mux = |
| 1302 | SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum); |
| 1303 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1304 | static const struct snd_kcontrol_new anc1_mux = |
| 1305 | SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum); |
| 1306 | |
| 1307 | static const struct snd_kcontrol_new anc2_mux = |
| 1308 | SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum); |
| 1309 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1310 | static const struct snd_kcontrol_new anc1_fb_mux = |
| 1311 | SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum); |
| 1312 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1313 | static const struct snd_kcontrol_new dac1_switch[] = { |
| 1314 | SOC_DAPM_SINGLE("Switch", TAPAN_A_RX_EAR_EN, 5, 1, 0) |
| 1315 | }; |
| 1316 | static const struct snd_kcontrol_new hphl_switch[] = { |
| 1317 | SOC_DAPM_SINGLE("Switch", TAPAN_A_RX_HPH_L_DAC_CTL, 6, 1, 0) |
| 1318 | }; |
| 1319 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1320 | static const struct snd_kcontrol_new spk_dac_switch[] = { |
| 1321 | SOC_DAPM_SINGLE("Switch", TAPAN_A_SPKR_DRV_DAC_CTL, 2, 1, 0) |
| 1322 | }; |
| 1323 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1324 | static const struct snd_kcontrol_new hphl_pa_mix[] = { |
| 1325 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN, |
| 1326 | 7, 1, 0), |
| 1327 | }; |
| 1328 | |
| 1329 | static const struct snd_kcontrol_new hphr_pa_mix[] = { |
| 1330 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TAPAN_A_RX_PA_AUX_IN_CONN, |
| 1331 | 6, 1, 0), |
| 1332 | }; |
| 1333 | |
| 1334 | static const struct snd_kcontrol_new ear_pa_mix[] = { |
| 1335 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN, |
| 1336 | 5, 1, 0), |
| 1337 | }; |
| 1338 | static const struct snd_kcontrol_new lineout1_pa_mix[] = { |
| 1339 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN, |
| 1340 | 4, 1, 0), |
| 1341 | }; |
| 1342 | |
| 1343 | static const struct snd_kcontrol_new lineout2_pa_mix[] = { |
| 1344 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TAPAN_A_RX_PA_AUX_IN_CONN, |
| 1345 | 3, 1, 0), |
| 1346 | }; |
| 1347 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1348 | |
| 1349 | /* virtual port entries */ |
| 1350 | static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol, |
| 1351 | struct snd_ctl_elem_value *ucontrol) |
| 1352 | { |
| 1353 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1354 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1355 | |
| 1356 | ucontrol->value.integer.value[0] = widget->value; |
| 1357 | return 0; |
| 1358 | } |
| 1359 | |
| 1360 | static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol, |
| 1361 | struct snd_ctl_elem_value *ucontrol) |
| 1362 | { |
| 1363 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1364 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1365 | struct snd_soc_codec *codec = widget->codec; |
| 1366 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
| 1367 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 1368 | struct soc_multi_mixer_control *mixer = |
| 1369 | ((struct soc_multi_mixer_control *)kcontrol->private_value); |
| 1370 | u32 dai_id = widget->shift; |
| 1371 | u32 port_id = mixer->shift; |
| 1372 | u32 enable = ucontrol->value.integer.value[0]; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1373 | u32 vtable = vport_check_table[dai_id]; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1374 | |
| 1375 | dev_dbg(codec->dev, "%s: wname %s cname %s\n", |
| 1376 | __func__, widget->name, ucontrol->id.name); |
| 1377 | dev_dbg(codec->dev, "%s: value %u shift %d item %ld\n", |
| 1378 | __func__, widget->value, widget->shift, |
| 1379 | ucontrol->value.integer.value[0]); |
| 1380 | |
| 1381 | mutex_lock(&codec->mutex); |
| 1382 | |
| 1383 | if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 1384 | if (dai_id != AIF1_CAP) { |
| 1385 | dev_err(codec->dev, "%s: invalid AIF for I2C mode\n", |
| 1386 | __func__); |
| 1387 | mutex_unlock(&codec->mutex); |
| 1388 | return -EINVAL; |
| 1389 | } |
| 1390 | } |
| 1391 | switch (dai_id) { |
| 1392 | case AIF1_CAP: |
| 1393 | case AIF2_CAP: |
| 1394 | case AIF3_CAP: |
| 1395 | /* only add to the list if value not set |
| 1396 | */ |
| 1397 | if (enable && !(widget->value & 1 << port_id)) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1398 | if (tapan_p->intf_type == |
| 1399 | WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 1400 | vtable = vport_check_table[dai_id]; |
| 1401 | if (tapan_p->intf_type == |
| 1402 | WCD9XXX_INTERFACE_TYPE_I2C) |
| 1403 | vtable = vport_i2s_check_table[dai_id]; |
| 1404 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1405 | if (wcd9xxx_tx_vport_validation( |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1406 | vtable, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1407 | port_id, |
| 1408 | tapan_p->dai)) { |
| 1409 | dev_dbg(codec->dev, "%s: TX%u is used by other virtual port\n", |
| 1410 | __func__, port_id + 1); |
| 1411 | mutex_unlock(&codec->mutex); |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 1412 | return 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1413 | } |
| 1414 | widget->value |= 1 << port_id; |
| 1415 | list_add_tail(&core->tx_chs[port_id].list, |
| 1416 | &tapan_p->dai[dai_id].wcd9xxx_ch_list |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1417 | ); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1418 | } else if (!enable && (widget->value & 1 << port_id)) { |
| 1419 | widget->value &= ~(1 << port_id); |
| 1420 | list_del_init(&core->tx_chs[port_id].list); |
| 1421 | } else { |
| 1422 | if (enable) |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1423 | dev_dbg(codec->dev, "%s: TX%u port is used by\n" |
| 1424 | "this virtual port\n", |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1425 | __func__, port_id + 1); |
| 1426 | else |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1427 | dev_dbg(codec->dev, "%s: TX%u port is not used by\n" |
| 1428 | "this virtual port\n", |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1429 | __func__, port_id + 1); |
| 1430 | /* avoid update power function */ |
| 1431 | mutex_unlock(&codec->mutex); |
| 1432 | return 0; |
| 1433 | } |
| 1434 | break; |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1435 | default: |
| 1436 | dev_err(codec->dev, "Unknown AIF %d\n", dai_id); |
| 1437 | mutex_unlock(&codec->mutex); |
| 1438 | return -EINVAL; |
| 1439 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1440 | dev_dbg(codec->dev, "%s: name %s sname %s updated value %u shift %d\n", |
| 1441 | __func__, widget->name, widget->sname, |
| 1442 | widget->value, widget->shift); |
| 1443 | |
| 1444 | snd_soc_dapm_mixer_update_power(widget, kcontrol, enable); |
| 1445 | |
| 1446 | mutex_unlock(&codec->mutex); |
| 1447 | return 0; |
| 1448 | } |
| 1449 | |
| 1450 | static int slim_rx_mux_get(struct snd_kcontrol *kcontrol, |
| 1451 | struct snd_ctl_elem_value *ucontrol) |
| 1452 | { |
| 1453 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1454 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1455 | |
| 1456 | ucontrol->value.enumerated.item[0] = widget->value; |
| 1457 | return 0; |
| 1458 | } |
| 1459 | |
| 1460 | static const char *const slim_rx_mux_text[] = { |
| 1461 | "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB" |
| 1462 | }; |
| 1463 | |
| 1464 | static int slim_rx_mux_put(struct snd_kcontrol *kcontrol, |
| 1465 | struct snd_ctl_elem_value *ucontrol) |
| 1466 | { |
| 1467 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1468 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1469 | struct snd_soc_codec *codec = widget->codec; |
| 1470 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
| 1471 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 1472 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1473 | u32 port_id = widget->shift; |
| 1474 | |
| 1475 | dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n", |
| 1476 | __func__, widget->name, ucontrol->id.name, widget->value, |
| 1477 | widget->shift, ucontrol->value.integer.value[0]); |
| 1478 | |
| 1479 | widget->value = ucontrol->value.enumerated.item[0]; |
| 1480 | |
| 1481 | mutex_lock(&codec->mutex); |
| 1482 | |
| 1483 | if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 1484 | if (widget->value > 1) { |
| 1485 | dev_err(codec->dev, "%s: invalid AIF for I2C mode\n", |
| 1486 | __func__); |
| 1487 | goto err; |
| 1488 | } |
| 1489 | } |
| 1490 | /* value need to match the Virtual port and AIF number |
| 1491 | */ |
| 1492 | switch (widget->value) { |
| 1493 | case 0: |
| 1494 | list_del_init(&core->rx_chs[port_id].list); |
| 1495 | break; |
| 1496 | case 1: |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 1497 | if (wcd9xxx_rx_vport_validation(port_id + |
| 1498 | TAPAN_RX_PORT_START_NUMBER, |
| 1499 | &tapan_p->dai[AIF1_PB].wcd9xxx_ch_list)) { |
| 1500 | dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n", |
| 1501 | __func__, port_id + 1); |
| 1502 | goto rtn; |
| 1503 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1504 | list_add_tail(&core->rx_chs[port_id].list, |
| 1505 | &tapan_p->dai[AIF1_PB].wcd9xxx_ch_list); |
| 1506 | break; |
| 1507 | case 2: |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 1508 | if (wcd9xxx_rx_vport_validation(port_id + |
| 1509 | TAPAN_RX_PORT_START_NUMBER, |
| 1510 | &tapan_p->dai[AIF2_PB].wcd9xxx_ch_list)) { |
| 1511 | dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n", |
| 1512 | __func__, port_id + 1); |
| 1513 | goto rtn; |
| 1514 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1515 | list_add_tail(&core->rx_chs[port_id].list, |
| 1516 | &tapan_p->dai[AIF2_PB].wcd9xxx_ch_list); |
| 1517 | break; |
| 1518 | case 3: |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 1519 | if (wcd9xxx_rx_vport_validation(port_id + |
| 1520 | TAPAN_RX_PORT_START_NUMBER, |
| 1521 | &tapan_p->dai[AIF3_PB].wcd9xxx_ch_list)) { |
| 1522 | dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n", |
| 1523 | __func__, port_id + 1); |
| 1524 | goto rtn; |
| 1525 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1526 | list_add_tail(&core->rx_chs[port_id].list, |
| 1527 | &tapan_p->dai[AIF3_PB].wcd9xxx_ch_list); |
| 1528 | break; |
| 1529 | default: |
| 1530 | pr_err("Unknown AIF %d\n", widget->value); |
| 1531 | goto err; |
| 1532 | } |
| 1533 | |
Kuirong Wang | 80aca0d | 2013-05-09 14:51:09 -0700 | [diff] [blame] | 1534 | rtn: |
Jay Chokshi | 83b4f613 | 2013-02-14 16:20:56 -0800 | [diff] [blame] | 1535 | snd_soc_dapm_mux_update_power(widget, kcontrol, 1, widget->value, e); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1536 | mutex_unlock(&codec->mutex); |
| 1537 | return 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1538 | err: |
| 1539 | mutex_unlock(&codec->mutex); |
| 1540 | return -EINVAL; |
| 1541 | } |
| 1542 | |
| 1543 | static const struct soc_enum slim_rx_mux_enum = |
| 1544 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text), slim_rx_mux_text); |
| 1545 | |
| 1546 | static const struct snd_kcontrol_new slim_rx_mux[TAPAN_RX_MAX] = { |
| 1547 | SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum, |
| 1548 | slim_rx_mux_get, slim_rx_mux_put), |
| 1549 | SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum, |
| 1550 | slim_rx_mux_get, slim_rx_mux_put), |
| 1551 | SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum, |
| 1552 | slim_rx_mux_get, slim_rx_mux_put), |
| 1553 | SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum, |
| 1554 | slim_rx_mux_get, slim_rx_mux_put), |
| 1555 | SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum, |
| 1556 | slim_rx_mux_get, slim_rx_mux_put), |
| 1557 | }; |
| 1558 | |
| 1559 | static const struct snd_kcontrol_new aif_cap_mixer[] = { |
| 1560 | SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, TAPAN_TX1, 1, 0, |
| 1561 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1562 | SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, TAPAN_TX2, 1, 0, |
| 1563 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1564 | SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, TAPAN_TX3, 1, 0, |
| 1565 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1566 | SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, TAPAN_TX4, 1, 0, |
| 1567 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1568 | SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, TAPAN_TX5, 1, 0, |
| 1569 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1570 | }; |
| 1571 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1572 | static int tapan_codec_enable_adc(struct snd_soc_dapm_widget *w, |
| 1573 | struct snd_kcontrol *kcontrol, int event) |
| 1574 | { |
| 1575 | struct snd_soc_codec *codec = w->codec; |
| 1576 | u16 adc_reg; |
| 1577 | u8 init_bit_shift; |
| 1578 | |
| 1579 | dev_dbg(codec->dev, "%s(): %s %d\n", __func__, w->name, event); |
| 1580 | |
| 1581 | if (w->reg == TAPAN_A_TX_1_EN) { |
| 1582 | init_bit_shift = 7; |
| 1583 | adc_reg = TAPAN_A_TX_1_2_TEST_CTL; |
| 1584 | } else if (w->reg == TAPAN_A_TX_2_EN) { |
| 1585 | init_bit_shift = 6; |
| 1586 | adc_reg = TAPAN_A_TX_1_2_TEST_CTL; |
| 1587 | } else if (w->reg == TAPAN_A_TX_3_EN) { |
| 1588 | init_bit_shift = 6; |
| 1589 | adc_reg = TAPAN_A_TX_1_2_TEST_CTL; |
| 1590 | } else if (w->reg == TAPAN_A_TX_4_EN) { |
| 1591 | init_bit_shift = 7; |
| 1592 | adc_reg = TAPAN_A_TX_4_5_TEST_CTL; |
| 1593 | } else if (w->reg == TAPAN_A_TX_5_EN) { |
| 1594 | init_bit_shift = 6; |
| 1595 | adc_reg = TAPAN_A_TX_4_5_TEST_CTL; |
| 1596 | } else { |
| 1597 | pr_err("%s: Error, invalid adc register\n", __func__); |
| 1598 | return -EINVAL; |
| 1599 | } |
| 1600 | |
| 1601 | switch (event) { |
| 1602 | case SND_SOC_DAPM_PRE_PMU: |
| 1603 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, |
| 1604 | 1 << init_bit_shift); |
| 1605 | break; |
| 1606 | case SND_SOC_DAPM_POST_PMU: |
| 1607 | |
| 1608 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00); |
| 1609 | |
| 1610 | break; |
| 1611 | } |
| 1612 | return 0; |
| 1613 | } |
| 1614 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1615 | static int tapan_codec_enable_aux_pga(struct snd_soc_dapm_widget *w, |
| 1616 | struct snd_kcontrol *kcontrol, int event) |
| 1617 | { |
| 1618 | struct snd_soc_codec *codec = w->codec; |
| 1619 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 1620 | |
| 1621 | dev_dbg(codec->dev, "%s: %d\n", __func__, event); |
| 1622 | |
| 1623 | switch (event) { |
| 1624 | case SND_SOC_DAPM_PRE_PMU: |
| 1625 | WCD9XXX_BCL_LOCK(&tapan->resmgr); |
| 1626 | wcd9xxx_resmgr_get_bandgap(&tapan->resmgr, |
| 1627 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 1628 | /* AUX PGA requires RCO or MCLK */ |
| 1629 | wcd9xxx_resmgr_get_clk_block(&tapan->resmgr, WCD9XXX_CLK_RCO); |
| 1630 | wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 1); |
| 1631 | WCD9XXX_BCL_UNLOCK(&tapan->resmgr); |
| 1632 | break; |
| 1633 | |
| 1634 | case SND_SOC_DAPM_POST_PMD: |
| 1635 | WCD9XXX_BCL_LOCK(&tapan->resmgr); |
| 1636 | wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 0); |
| 1637 | wcd9xxx_resmgr_put_bandgap(&tapan->resmgr, |
| 1638 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 1639 | wcd9xxx_resmgr_put_clk_block(&tapan->resmgr, WCD9XXX_CLK_RCO); |
| 1640 | WCD9XXX_BCL_UNLOCK(&tapan->resmgr); |
| 1641 | break; |
| 1642 | } |
| 1643 | return 0; |
| 1644 | } |
| 1645 | |
| 1646 | static int tapan_codec_enable_lineout(struct snd_soc_dapm_widget *w, |
| 1647 | struct snd_kcontrol *kcontrol, int event) |
| 1648 | { |
| 1649 | struct snd_soc_codec *codec = w->codec; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1650 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1651 | u16 lineout_gain_reg; |
| 1652 | |
| 1653 | dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name); |
| 1654 | |
| 1655 | switch (w->shift) { |
| 1656 | case 0: |
| 1657 | lineout_gain_reg = TAPAN_A_RX_LINE_1_GAIN; |
| 1658 | break; |
| 1659 | case 1: |
| 1660 | lineout_gain_reg = TAPAN_A_RX_LINE_2_GAIN; |
| 1661 | break; |
| 1662 | default: |
| 1663 | pr_err("%s: Error, incorrect lineout register value\n", |
| 1664 | __func__); |
| 1665 | return -EINVAL; |
| 1666 | } |
| 1667 | |
| 1668 | switch (event) { |
| 1669 | case SND_SOC_DAPM_PRE_PMU: |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1670 | break; |
| 1671 | case SND_SOC_DAPM_POST_PMU: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1672 | wcd9xxx_clsh_fsm(codec, &tapan->clsh_d, |
| 1673 | WCD9XXX_CLSH_STATE_LO, |
| 1674 | WCD9XXX_CLSH_REQ_ENABLE, |
| 1675 | WCD9XXX_CLSH_EVENT_POST_PA); |
| 1676 | 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] | 1677 | __func__, w->name); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1678 | usleep_range(3000, 3010); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1679 | break; |
| 1680 | case SND_SOC_DAPM_POST_PMD: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1681 | wcd9xxx_clsh_fsm(codec, &tapan->clsh_d, |
| 1682 | WCD9XXX_CLSH_STATE_LO, |
| 1683 | WCD9XXX_CLSH_REQ_DISABLE, |
| 1684 | WCD9XXX_CLSH_EVENT_POST_PA); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1685 | break; |
| 1686 | } |
| 1687 | return 0; |
| 1688 | } |
| 1689 | |
| 1690 | static int tapan_codec_enable_spk_pa(struct snd_soc_dapm_widget *w, |
| 1691 | struct snd_kcontrol *kcontrol, int event) |
| 1692 | { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1693 | struct snd_soc_codec *codec = w->codec; |
| 1694 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 1695 | |
| 1696 | dev_dbg(codec->dev, "%s: %s %d\n", __func__, w->name, event); |
| 1697 | WCD9XXX_BCL_LOCK(&tapan->resmgr); |
| 1698 | switch (event) { |
| 1699 | case SND_SOC_DAPM_PRE_PMU: |
| 1700 | tapan->spkr_pa_widget_on = true; |
| 1701 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80); |
| 1702 | break; |
| 1703 | case SND_SOC_DAPM_POST_PMD: |
| 1704 | tapan->spkr_pa_widget_on = false; |
| 1705 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x00); |
| 1706 | break; |
| 1707 | } |
| 1708 | WCD9XXX_BCL_UNLOCK(&tapan->resmgr); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1709 | return 0; |
| 1710 | } |
| 1711 | |
| 1712 | static int tapan_codec_enable_dmic(struct snd_soc_dapm_widget *w, |
| 1713 | struct snd_kcontrol *kcontrol, int event) |
| 1714 | { |
| 1715 | struct snd_soc_codec *codec = w->codec; |
| 1716 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 1717 | u8 dmic_clk_en; |
| 1718 | u16 dmic_clk_reg; |
| 1719 | s32 *dmic_clk_cnt; |
| 1720 | unsigned int dmic; |
| 1721 | int ret; |
| 1722 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 1723 | ret = kstrtouint(strpbrk(w->name, "1234"), 10, &dmic); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1724 | if (ret < 0) { |
| 1725 | pr_err("%s: Invalid DMIC line on the codec\n", __func__); |
| 1726 | return -EINVAL; |
| 1727 | } |
| 1728 | |
| 1729 | switch (dmic) { |
| 1730 | case 1: |
| 1731 | case 2: |
| 1732 | dmic_clk_en = 0x01; |
| 1733 | dmic_clk_cnt = &(tapan->dmic_1_2_clk_cnt); |
| 1734 | dmic_clk_reg = TAPAN_A_CDC_CLK_DMIC_B1_CTL; |
| 1735 | dev_dbg(codec->dev, "%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n", |
| 1736 | __func__, event, dmic, *dmic_clk_cnt); |
| 1737 | |
| 1738 | break; |
| 1739 | |
| 1740 | case 3: |
| 1741 | case 4: |
| 1742 | dmic_clk_en = 0x10; |
| 1743 | dmic_clk_cnt = &(tapan->dmic_3_4_clk_cnt); |
| 1744 | dmic_clk_reg = TAPAN_A_CDC_CLK_DMIC_B1_CTL; |
| 1745 | |
| 1746 | dev_dbg(codec->dev, "%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n", |
| 1747 | __func__, event, dmic, *dmic_clk_cnt); |
| 1748 | break; |
| 1749 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1750 | default: |
| 1751 | pr_err("%s: Invalid DMIC Selection\n", __func__); |
| 1752 | return -EINVAL; |
| 1753 | } |
| 1754 | |
| 1755 | switch (event) { |
| 1756 | case SND_SOC_DAPM_PRE_PMU: |
| 1757 | |
| 1758 | (*dmic_clk_cnt)++; |
| 1759 | if (*dmic_clk_cnt == 1) |
| 1760 | snd_soc_update_bits(codec, dmic_clk_reg, |
| 1761 | dmic_clk_en, dmic_clk_en); |
| 1762 | |
| 1763 | break; |
| 1764 | case SND_SOC_DAPM_POST_PMD: |
| 1765 | |
| 1766 | (*dmic_clk_cnt)--; |
| 1767 | if (*dmic_clk_cnt == 0) |
| 1768 | snd_soc_update_bits(codec, dmic_clk_reg, |
| 1769 | dmic_clk_en, 0); |
| 1770 | break; |
| 1771 | } |
| 1772 | return 0; |
| 1773 | } |
| 1774 | |
| 1775 | static int tapan_codec_enable_anc(struct snd_soc_dapm_widget *w, |
| 1776 | struct snd_kcontrol *kcontrol, int event) |
| 1777 | { |
| 1778 | struct snd_soc_codec *codec = w->codec; |
| 1779 | const char *filename; |
| 1780 | const struct firmware *fw; |
| 1781 | int i; |
| 1782 | int ret; |
| 1783 | int num_anc_slots; |
Simmi Pateriya | df675e9 | 2013-04-05 01:15:54 +0530 | [diff] [blame] | 1784 | struct wcd9xxx_anc_header *anc_head; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1785 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 1786 | u32 anc_writes_size = 0; |
| 1787 | int anc_size_remaining; |
| 1788 | u32 *anc_ptr; |
| 1789 | u16 reg; |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1790 | u8 mask, val, old_val; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1791 | |
| 1792 | dev_dbg(codec->dev, "%s %d\n", __func__, event); |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1793 | if (tapan->anc_func == 0) |
| 1794 | return 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1795 | switch (event) { |
| 1796 | case SND_SOC_DAPM_PRE_PMU: |
| 1797 | |
| 1798 | filename = "wcd9306/wcd9306_anc.bin"; |
| 1799 | |
| 1800 | ret = request_firmware(&fw, filename, codec->dev); |
| 1801 | if (ret != 0) { |
| 1802 | dev_err(codec->dev, "Failed to acquire ANC data: %d\n", |
| 1803 | ret); |
| 1804 | return -ENODEV; |
| 1805 | } |
| 1806 | |
Simmi Pateriya | df675e9 | 2013-04-05 01:15:54 +0530 | [diff] [blame] | 1807 | if (fw->size < sizeof(struct wcd9xxx_anc_header)) { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1808 | dev_err(codec->dev, "Not enough data\n"); |
| 1809 | release_firmware(fw); |
| 1810 | return -ENOMEM; |
| 1811 | } |
| 1812 | |
| 1813 | /* First number is the number of register writes */ |
Simmi Pateriya | df675e9 | 2013-04-05 01:15:54 +0530 | [diff] [blame] | 1814 | anc_head = (struct wcd9xxx_anc_header *)(fw->data); |
| 1815 | anc_ptr = (u32 *)((u32)fw->data + |
| 1816 | sizeof(struct wcd9xxx_anc_header)); |
| 1817 | anc_size_remaining = fw->size - |
| 1818 | sizeof(struct wcd9xxx_anc_header); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1819 | num_anc_slots = anc_head->num_anc_slots; |
| 1820 | |
| 1821 | if (tapan->anc_slot >= num_anc_slots) { |
| 1822 | dev_err(codec->dev, "Invalid ANC slot selected\n"); |
| 1823 | release_firmware(fw); |
| 1824 | return -EINVAL; |
| 1825 | } |
| 1826 | |
| 1827 | for (i = 0; i < num_anc_slots; i++) { |
| 1828 | |
| 1829 | if (anc_size_remaining < TAPAN_PACKED_REG_SIZE) { |
| 1830 | dev_err(codec->dev, "Invalid register format\n"); |
| 1831 | release_firmware(fw); |
| 1832 | return -EINVAL; |
| 1833 | } |
| 1834 | anc_writes_size = (u32)(*anc_ptr); |
| 1835 | anc_size_remaining -= sizeof(u32); |
| 1836 | anc_ptr += 1; |
| 1837 | |
| 1838 | if (anc_writes_size * TAPAN_PACKED_REG_SIZE |
| 1839 | > anc_size_remaining) { |
| 1840 | dev_err(codec->dev, "Invalid register format\n"); |
| 1841 | release_firmware(fw); |
| 1842 | return -ENOMEM; |
| 1843 | } |
| 1844 | |
| 1845 | if (tapan->anc_slot == i) |
| 1846 | break; |
| 1847 | |
| 1848 | anc_size_remaining -= (anc_writes_size * |
| 1849 | TAPAN_PACKED_REG_SIZE); |
| 1850 | anc_ptr += anc_writes_size; |
| 1851 | } |
| 1852 | if (i == num_anc_slots) { |
| 1853 | dev_err(codec->dev, "Selected ANC slot not present\n"); |
| 1854 | release_firmware(fw); |
| 1855 | return -ENOMEM; |
| 1856 | } |
| 1857 | |
| 1858 | for (i = 0; i < anc_writes_size; i++) { |
| 1859 | TAPAN_CODEC_UNPACK_ENTRY(anc_ptr[i], reg, |
| 1860 | mask, val); |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1861 | old_val = snd_soc_read(codec, reg); |
| 1862 | snd_soc_write(codec, reg, (old_val & ~mask) | |
| 1863 | (val & mask)); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1864 | } |
| 1865 | release_firmware(fw); |
| 1866 | |
| 1867 | break; |
Damir Didjusto | 1ede84a | 2013-05-23 16:38:11 -0700 | [diff] [blame] | 1868 | case SND_SOC_DAPM_PRE_PMD: |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 1869 | msleep(40); |
| 1870 | snd_soc_update_bits(codec, TAPAN_A_CDC_ANC1_B1_CTL, 0x01, 0x00); |
| 1871 | snd_soc_update_bits(codec, TAPAN_A_CDC_ANC2_B1_CTL, 0x02, 0x00); |
| 1872 | msleep(20); |
| 1873 | snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_RESET_CTL, 0x0F); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1874 | 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] | 1875 | snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_RESET_CTL, 0xFF); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 1876 | break; |
| 1877 | } |
| 1878 | return 0; |
| 1879 | } |
| 1880 | |
| 1881 | static int tapan_codec_enable_micbias(struct snd_soc_dapm_widget *w, |
| 1882 | struct snd_kcontrol *kcontrol, int event) |
| 1883 | { |
| 1884 | struct snd_soc_codec *codec = w->codec; |
| 1885 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 1886 | u16 micb_int_reg; |
| 1887 | u8 cfilt_sel_val = 0; |
| 1888 | char *internal1_text = "Internal1"; |
| 1889 | char *internal2_text = "Internal2"; |
| 1890 | char *internal3_text = "Internal3"; |
| 1891 | enum wcd9xxx_notify_event e_post_off, e_pre_on, e_post_on; |
| 1892 | |
| 1893 | dev_dbg(codec->dev, "%s %d\n", __func__, event); |
| 1894 | switch (w->reg) { |
| 1895 | case TAPAN_A_MICB_1_CTL: |
| 1896 | micb_int_reg = TAPAN_A_MICB_1_INT_RBIAS; |
| 1897 | cfilt_sel_val = tapan->resmgr.pdata->micbias.bias1_cfilt_sel; |
| 1898 | e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_1_ON; |
| 1899 | e_post_on = WCD9XXX_EVENT_POST_MICBIAS_1_ON; |
| 1900 | e_post_off = WCD9XXX_EVENT_POST_MICBIAS_1_OFF; |
| 1901 | break; |
| 1902 | case TAPAN_A_MICB_2_CTL: |
| 1903 | micb_int_reg = TAPAN_A_MICB_2_INT_RBIAS; |
| 1904 | cfilt_sel_val = tapan->resmgr.pdata->micbias.bias2_cfilt_sel; |
| 1905 | e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_2_ON; |
| 1906 | e_post_on = WCD9XXX_EVENT_POST_MICBIAS_2_ON; |
| 1907 | e_post_off = WCD9XXX_EVENT_POST_MICBIAS_2_OFF; |
| 1908 | break; |
| 1909 | case TAPAN_A_MICB_3_CTL: |
| 1910 | micb_int_reg = TAPAN_A_MICB_3_INT_RBIAS; |
| 1911 | cfilt_sel_val = tapan->resmgr.pdata->micbias.bias3_cfilt_sel; |
| 1912 | e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_3_ON; |
| 1913 | e_post_on = WCD9XXX_EVENT_POST_MICBIAS_3_ON; |
| 1914 | e_post_off = WCD9XXX_EVENT_POST_MICBIAS_3_OFF; |
| 1915 | break; |
| 1916 | default: |
| 1917 | pr_err("%s: Error, invalid micbias register\n", __func__); |
| 1918 | return -EINVAL; |
| 1919 | } |
| 1920 | |
| 1921 | switch (event) { |
| 1922 | case SND_SOC_DAPM_PRE_PMU: |
| 1923 | /* Let MBHC module know so micbias switch to be off */ |
| 1924 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_pre_on); |
| 1925 | |
| 1926 | /* Get cfilt */ |
| 1927 | wcd9xxx_resmgr_cfilt_get(&tapan->resmgr, cfilt_sel_val); |
| 1928 | |
| 1929 | if (strnstr(w->name, internal1_text, 30)) |
| 1930 | snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0); |
| 1931 | else if (strnstr(w->name, internal2_text, 30)) |
| 1932 | snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C); |
| 1933 | else if (strnstr(w->name, internal3_text, 30)) |
| 1934 | snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3); |
| 1935 | |
| 1936 | break; |
| 1937 | case SND_SOC_DAPM_POST_PMU: |
| 1938 | usleep_range(20000, 20000); |
| 1939 | /* Let MBHC module know so micbias is on */ |
| 1940 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_on); |
| 1941 | break; |
| 1942 | case SND_SOC_DAPM_POST_PMD: |
| 1943 | /* Let MBHC module know so micbias switch to be off */ |
| 1944 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_off); |
| 1945 | |
| 1946 | if (strnstr(w->name, internal1_text, 30)) |
| 1947 | snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00); |
| 1948 | else if (strnstr(w->name, internal2_text, 30)) |
| 1949 | snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00); |
| 1950 | else if (strnstr(w->name, internal3_text, 30)) |
| 1951 | snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0); |
| 1952 | |
| 1953 | /* Put cfilt */ |
| 1954 | wcd9xxx_resmgr_cfilt_put(&tapan->resmgr, cfilt_sel_val); |
| 1955 | break; |
| 1956 | } |
| 1957 | |
| 1958 | return 0; |
| 1959 | } |
| 1960 | |
| 1961 | static void tx_hpf_corner_freq_callback(struct work_struct *work) |
| 1962 | { |
| 1963 | struct delayed_work *hpf_delayed_work; |
| 1964 | struct hpf_work *hpf_work; |
| 1965 | struct tapan_priv *tapan; |
| 1966 | struct snd_soc_codec *codec; |
| 1967 | u16 tx_mux_ctl_reg; |
| 1968 | u8 hpf_cut_of_freq; |
| 1969 | |
| 1970 | hpf_delayed_work = to_delayed_work(work); |
| 1971 | hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork); |
| 1972 | tapan = hpf_work->tapan; |
| 1973 | codec = hpf_work->tapan->codec; |
| 1974 | hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq; |
| 1975 | |
| 1976 | tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL + |
| 1977 | (hpf_work->decimator - 1) * 8; |
| 1978 | |
| 1979 | dev_dbg(codec->dev, "%s(): decimator %u hpf_cut_of_freq 0x%x\n", |
| 1980 | __func__, hpf_work->decimator, (unsigned int)hpf_cut_of_freq); |
| 1981 | |
| 1982 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4); |
| 1983 | } |
| 1984 | |
| 1985 | #define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30 |
| 1986 | #define CF_MIN_3DB_4HZ 0x0 |
| 1987 | #define CF_MIN_3DB_75HZ 0x1 |
| 1988 | #define CF_MIN_3DB_150HZ 0x2 |
| 1989 | |
| 1990 | static int tapan_codec_enable_dec(struct snd_soc_dapm_widget *w, |
| 1991 | struct snd_kcontrol *kcontrol, int event) |
| 1992 | { |
| 1993 | struct snd_soc_codec *codec = w->codec; |
| 1994 | unsigned int decimator; |
| 1995 | char *dec_name = NULL; |
| 1996 | char *widget_name = NULL; |
| 1997 | char *temp; |
| 1998 | int ret = 0; |
| 1999 | u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg; |
| 2000 | u8 dec_hpf_cut_of_freq; |
| 2001 | int offset; |
| 2002 | |
| 2003 | dev_dbg(codec->dev, "%s %d\n", __func__, event); |
| 2004 | |
| 2005 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 2006 | if (!widget_name) |
| 2007 | return -ENOMEM; |
| 2008 | temp = widget_name; |
| 2009 | |
| 2010 | dec_name = strsep(&widget_name, " "); |
| 2011 | widget_name = temp; |
| 2012 | if (!dec_name) { |
| 2013 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 2014 | ret = -EINVAL; |
| 2015 | goto out; |
| 2016 | } |
| 2017 | |
| 2018 | ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator); |
| 2019 | if (ret < 0) { |
| 2020 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 2021 | ret = -EINVAL; |
| 2022 | goto out; |
| 2023 | } |
| 2024 | |
| 2025 | dev_dbg(codec->dev, "%s(): widget = %s dec_name = %s decimator = %u\n", |
| 2026 | __func__, w->name, dec_name, decimator); |
| 2027 | |
| 2028 | if (w->reg == TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL) { |
| 2029 | dec_reset_reg = TAPAN_A_CDC_CLK_TX_RESET_B1_CTL; |
| 2030 | offset = 0; |
| 2031 | } else if (w->reg == TAPAN_A_CDC_CLK_TX_CLK_EN_B2_CTL) { |
| 2032 | dec_reset_reg = TAPAN_A_CDC_CLK_TX_RESET_B2_CTL; |
| 2033 | offset = 8; |
| 2034 | } else { |
| 2035 | pr_err("%s: Error, incorrect dec\n", __func__); |
| 2036 | ret = -EINVAL; |
| 2037 | goto out; |
| 2038 | } |
| 2039 | |
| 2040 | tx_vol_ctl_reg = TAPAN_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator - 1); |
| 2041 | tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 2042 | |
| 2043 | switch (event) { |
| 2044 | case SND_SOC_DAPM_PRE_PMU: |
| 2045 | |
| 2046 | /* Enableable TX digital mute */ |
| 2047 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 2048 | |
| 2049 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, |
| 2050 | 1 << w->shift); |
| 2051 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0); |
| 2052 | |
| 2053 | dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg); |
| 2054 | |
| 2055 | dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4; |
| 2056 | |
| 2057 | tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq = |
| 2058 | dec_hpf_cut_of_freq; |
| 2059 | |
| 2060 | if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) { |
| 2061 | |
| 2062 | /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */ |
| 2063 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 2064 | CF_MIN_3DB_150HZ << 4); |
| 2065 | } |
| 2066 | |
| 2067 | /* enable HPF */ |
| 2068 | snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00); |
| 2069 | |
| 2070 | break; |
| 2071 | |
| 2072 | case SND_SOC_DAPM_POST_PMU: |
| 2073 | |
| 2074 | /* Disable TX digital mute */ |
| 2075 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00); |
| 2076 | |
| 2077 | if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq != |
| 2078 | CF_MIN_3DB_150HZ) { |
| 2079 | |
| 2080 | schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork, |
| 2081 | msecs_to_jiffies(300)); |
| 2082 | } |
| 2083 | /* apply the digital gain after the decimator is enabled*/ |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2084 | if ((w->shift + offset) < ARRAY_SIZE(tx_digital_gain_reg)) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2085 | snd_soc_write(codec, |
| 2086 | tx_digital_gain_reg[w->shift + offset], |
| 2087 | snd_soc_read(codec, |
| 2088 | tx_digital_gain_reg[w->shift + offset]) |
| 2089 | ); |
| 2090 | |
| 2091 | break; |
| 2092 | |
| 2093 | case SND_SOC_DAPM_PRE_PMD: |
| 2094 | |
| 2095 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 2096 | cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork); |
| 2097 | break; |
| 2098 | |
| 2099 | case SND_SOC_DAPM_POST_PMD: |
| 2100 | |
| 2101 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08); |
| 2102 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 2103 | (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4); |
| 2104 | |
| 2105 | break; |
| 2106 | } |
| 2107 | out: |
| 2108 | kfree(widget_name); |
| 2109 | return ret; |
| 2110 | } |
| 2111 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2112 | static int tapan_codec_enable_vdd_spkr(struct snd_soc_dapm_widget *w, |
| 2113 | struct snd_kcontrol *kcontrol, int event) |
| 2114 | { |
| 2115 | struct snd_soc_codec *codec = w->codec; |
| 2116 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 2117 | |
| 2118 | dev_dbg(codec->dev, "%s: %s %d\n", __func__, w->name, event); |
| 2119 | |
| 2120 | switch (event) { |
| 2121 | case SND_SOC_DAPM_PRE_PMU: |
| 2122 | |
| 2123 | if (spkr_drv_wrnd > 0) { |
| 2124 | WARN_ON(!(snd_soc_read(codec, TAPAN_A_SPKR_DRV_EN) & |
| 2125 | 0x80)); |
| 2126 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, |
| 2127 | 0x00); |
| 2128 | } |
| 2129 | if (TAPAN_IS_1_0(core->version)) |
| 2130 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_DBG_PWRSTG, |
| 2131 | 0x24, 0x00); |
| 2132 | break; |
| 2133 | case SND_SOC_DAPM_POST_PMD: |
| 2134 | if (TAPAN_IS_1_0(core->version)) |
| 2135 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_DBG_PWRSTG, |
| 2136 | 0x24, 0x24); |
| 2137 | if (spkr_drv_wrnd > 0) { |
| 2138 | WARN_ON(!!(snd_soc_read(codec, TAPAN_A_SPKR_DRV_EN) & |
| 2139 | 0x80)); |
| 2140 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, |
| 2141 | 0x80); |
| 2142 | } |
| 2143 | break; |
| 2144 | } |
| 2145 | return 0; |
| 2146 | } |
| 2147 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2148 | static int tapan_codec_enable_interpolator(struct snd_soc_dapm_widget *w, |
| 2149 | struct snd_kcontrol *kcontrol, int event) |
| 2150 | { |
| 2151 | struct snd_soc_codec *codec = w->codec; |
| 2152 | |
| 2153 | dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name); |
| 2154 | |
| 2155 | switch (event) { |
| 2156 | case SND_SOC_DAPM_PRE_PMU: |
| 2157 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_RESET_CTL, |
| 2158 | 1 << w->shift, 1 << w->shift); |
| 2159 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_RESET_CTL, |
| 2160 | 1 << w->shift, 0x0); |
| 2161 | break; |
| 2162 | case SND_SOC_DAPM_POST_PMU: |
| 2163 | /* apply the digital gain after the interpolator is enabled*/ |
| 2164 | if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg)) |
| 2165 | snd_soc_write(codec, |
| 2166 | rx_digital_gain_reg[w->shift], |
| 2167 | snd_soc_read(codec, |
| 2168 | rx_digital_gain_reg[w->shift]) |
| 2169 | ); |
| 2170 | break; |
| 2171 | } |
| 2172 | return 0; |
| 2173 | } |
| 2174 | |
| 2175 | static int tapan_codec_enable_ldo_h(struct snd_soc_dapm_widget *w, |
| 2176 | struct snd_kcontrol *kcontrol, int event) |
| 2177 | { |
| 2178 | switch (event) { |
| 2179 | case SND_SOC_DAPM_POST_PMU: |
| 2180 | case SND_SOC_DAPM_POST_PMD: |
| 2181 | usleep_range(1000, 1000); |
| 2182 | break; |
| 2183 | } |
| 2184 | return 0; |
| 2185 | } |
| 2186 | |
| 2187 | static int tapan_codec_enable_rx_bias(struct snd_soc_dapm_widget *w, |
| 2188 | struct snd_kcontrol *kcontrol, int event) |
| 2189 | { |
| 2190 | struct snd_soc_codec *codec = w->codec; |
| 2191 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 2192 | |
| 2193 | dev_dbg(codec->dev, "%s %d\n", __func__, event); |
| 2194 | |
| 2195 | switch (event) { |
| 2196 | case SND_SOC_DAPM_PRE_PMU: |
| 2197 | wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 1); |
| 2198 | break; |
| 2199 | case SND_SOC_DAPM_POST_PMD: |
| 2200 | wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 0); |
| 2201 | break; |
| 2202 | } |
| 2203 | return 0; |
| 2204 | } |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2205 | |
| 2206 | |
| 2207 | static int tapan_hphl_dac_event(struct snd_soc_dapm_widget *w, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2208 | struct snd_kcontrol *kcontrol, int event) |
| 2209 | { |
| 2210 | struct snd_soc_codec *codec = w->codec; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2211 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2212 | |
| 2213 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 2214 | |
| 2215 | switch (event) { |
| 2216 | case SND_SOC_DAPM_PRE_PMU: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2217 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, |
| 2218 | 0x02, 0x02); |
| 2219 | wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d, |
| 2220 | WCD9XXX_CLSH_STATE_HPHL, |
| 2221 | WCD9XXX_CLSH_REQ_ENABLE, |
| 2222 | WCD9XXX_CLSH_EVENT_PRE_DAC); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2223 | break; |
| 2224 | case SND_SOC_DAPM_POST_PMD: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2225 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, |
| 2226 | 0x02, 0x00); |
| 2227 | } |
| 2228 | return 0; |
| 2229 | } |
| 2230 | |
| 2231 | static int tapan_hphr_dac_event(struct snd_soc_dapm_widget *w, |
| 2232 | struct snd_kcontrol *kcontrol, int event) |
| 2233 | { |
| 2234 | struct snd_soc_codec *codec = w->codec; |
| 2235 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
| 2236 | |
| 2237 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 2238 | |
| 2239 | switch (event) { |
| 2240 | case SND_SOC_DAPM_PRE_PMU: |
| 2241 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, |
| 2242 | 0x04, 0x04); |
| 2243 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 2244 | wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d, |
| 2245 | WCD9XXX_CLSH_STATE_HPHR, |
| 2246 | WCD9XXX_CLSH_REQ_ENABLE, |
| 2247 | WCD9XXX_CLSH_EVENT_PRE_DAC); |
| 2248 | break; |
| 2249 | case SND_SOC_DAPM_POST_PMD: |
| 2250 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, |
| 2251 | 0x04, 0x00); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2252 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 2253 | break; |
| 2254 | } |
| 2255 | return 0; |
| 2256 | } |
| 2257 | |
| 2258 | static int tapan_hph_pa_event(struct snd_soc_dapm_widget *w, |
| 2259 | struct snd_kcontrol *kcontrol, int event) |
| 2260 | { |
| 2261 | struct snd_soc_codec *codec = w->codec; |
| 2262 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 2263 | enum wcd9xxx_notify_event e_pre_on, e_post_off; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2264 | u8 req_clsh_state; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2265 | |
| 2266 | dev_dbg(codec->dev, "%s: %s event = %d\n", __func__, w->name, event); |
| 2267 | if (w->shift == 5) { |
Patrick Lai | 6ef0590 | 2013-03-16 18:14:16 -0700 | [diff] [blame] | 2268 | e_pre_on = WCD9XXX_EVENT_PRE_HPHR_PA_ON; |
| 2269 | e_post_off = WCD9XXX_EVENT_POST_HPHR_PA_OFF; |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2270 | req_clsh_state = WCD9XXX_CLSH_STATE_HPHL; |
| 2271 | } else if (w->shift == 4) { |
| 2272 | e_pre_on = WCD9XXX_EVENT_PRE_HPHL_PA_ON; |
| 2273 | e_post_off = WCD9XXX_EVENT_POST_HPHL_PA_OFF; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2274 | req_clsh_state = WCD9XXX_CLSH_STATE_HPHR; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2275 | } else { |
| 2276 | pr_err("%s: Invalid w->shift %d\n", __func__, w->shift); |
| 2277 | return -EINVAL; |
| 2278 | } |
| 2279 | |
| 2280 | switch (event) { |
| 2281 | case SND_SOC_DAPM_PRE_PMU: |
| 2282 | /* Let MBHC module know PA is turning on */ |
| 2283 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_pre_on); |
| 2284 | break; |
| 2285 | |
| 2286 | case SND_SOC_DAPM_POST_PMU: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2287 | wcd9xxx_clsh_fsm(codec, &tapan->clsh_d, |
| 2288 | req_clsh_state, |
| 2289 | WCD9XXX_CLSH_REQ_ENABLE, |
| 2290 | WCD9XXX_CLSH_EVENT_POST_PA); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2291 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2292 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2293 | usleep_range(5000, 5010); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2294 | break; |
| 2295 | |
| 2296 | case SND_SOC_DAPM_POST_PMD: |
| 2297 | /* Let MBHC module know PA turned off */ |
| 2298 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_off); |
| 2299 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2300 | wcd9xxx_clsh_fsm(codec, &tapan->clsh_d, |
| 2301 | req_clsh_state, |
| 2302 | WCD9XXX_CLSH_REQ_DISABLE, |
| 2303 | WCD9XXX_CLSH_EVENT_POST_PA); |
| 2304 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2305 | dev_dbg(codec->dev, "%s: sleep 10 ms after %s PA disable.\n", |
| 2306 | __func__, w->name); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2307 | usleep_range(5000, 5010); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2308 | break; |
| 2309 | } |
| 2310 | return 0; |
| 2311 | } |
| 2312 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2313 | static int tapan_codec_enable_anc_hph(struct snd_soc_dapm_widget *w, |
| 2314 | struct snd_kcontrol *kcontrol, int event) |
| 2315 | { |
| 2316 | struct snd_soc_codec *codec = w->codec; |
| 2317 | int ret = 0; |
| 2318 | |
| 2319 | switch (event) { |
| 2320 | case SND_SOC_DAPM_PRE_PMU: |
| 2321 | ret = tapan_hph_pa_event(w, kcontrol, event); |
| 2322 | if (w->shift == 4) { |
| 2323 | ret |= tapan_codec_enable_anc(w, kcontrol, event); |
| 2324 | msleep(50); |
| 2325 | } |
| 2326 | break; |
| 2327 | case SND_SOC_DAPM_POST_PMU: |
| 2328 | if (w->shift == 4) { |
| 2329 | snd_soc_update_bits(codec, |
| 2330 | TAPAN_A_RX_HPH_CNP_EN, 0x30, 0x30); |
| 2331 | msleep(30); |
| 2332 | } |
| 2333 | ret = tapan_hph_pa_event(w, kcontrol, event); |
| 2334 | break; |
| 2335 | case SND_SOC_DAPM_PRE_PMD: |
| 2336 | if (w->shift == 5) { |
| 2337 | snd_soc_update_bits(codec, |
| 2338 | TAPAN_A_RX_HPH_CNP_EN, 0x30, 0x00); |
| 2339 | msleep(40); |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2340 | snd_soc_update_bits(codec, |
| 2341 | TAPAN_A_TX_7_MBHC_EN, 0x80, 00); |
| 2342 | ret |= tapan_codec_enable_anc(w, kcontrol, event); |
| 2343 | } |
Damir Didjusto | 1ede84a | 2013-05-23 16:38:11 -0700 | [diff] [blame] | 2344 | break; |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2345 | case SND_SOC_DAPM_POST_PMD: |
| 2346 | ret = tapan_hph_pa_event(w, kcontrol, event); |
| 2347 | break; |
| 2348 | } |
| 2349 | return ret; |
| 2350 | } |
| 2351 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2352 | static const struct snd_soc_dapm_widget tapan_dapm_i2s_widgets[] = { |
| 2353 | SND_SOC_DAPM_SUPPLY("I2S_CLK", TAPAN_A_CDC_CLK_I2S_CTL, |
| 2354 | 4, 0, NULL, 0), |
| 2355 | }; |
| 2356 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2357 | static int tapan_lineout_dac_event(struct snd_soc_dapm_widget *w, |
| 2358 | struct snd_kcontrol *kcontrol, int event) |
| 2359 | { |
| 2360 | struct snd_soc_codec *codec = w->codec; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2361 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2362 | |
| 2363 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 2364 | |
| 2365 | switch (event) { |
| 2366 | case SND_SOC_DAPM_PRE_PMU: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2367 | wcd9xxx_clsh_fsm(codec, &tapan->clsh_d, |
| 2368 | WCD9XXX_CLSH_STATE_LO, |
| 2369 | WCD9XXX_CLSH_REQ_ENABLE, |
| 2370 | WCD9XXX_CLSH_EVENT_PRE_DAC); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2371 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 2372 | break; |
| 2373 | |
| 2374 | case SND_SOC_DAPM_POST_PMD: |
| 2375 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 2376 | break; |
| 2377 | } |
| 2378 | return 0; |
| 2379 | } |
| 2380 | |
| 2381 | static int tapan_spk_dac_event(struct snd_soc_dapm_widget *w, |
| 2382 | struct snd_kcontrol *kcontrol, int event) |
| 2383 | { |
| 2384 | struct snd_soc_codec *codec = w->codec; |
| 2385 | |
| 2386 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 2387 | return 0; |
| 2388 | } |
| 2389 | |
| 2390 | static const struct snd_soc_dapm_route audio_i2s_map[] = { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2391 | {"I2S_CLK", NULL, "CDC_CONN"}, |
| 2392 | {"SLIM RX1", NULL, "I2S_CLK"}, |
| 2393 | {"SLIM RX2", NULL, "I2S_CLK"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2394 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2395 | {"SLIM TX1 MUX", NULL, "I2S_CLK"}, |
| 2396 | {"SLIM TX2 MUX", NULL, "I2S_CLK"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2397 | }; |
| 2398 | |
| 2399 | static const struct snd_soc_dapm_route audio_map[] = { |
| 2400 | /* SLIMBUS Connections */ |
| 2401 | {"AIF1 CAP", NULL, "AIF1_CAP Mixer"}, |
| 2402 | {"AIF2 CAP", NULL, "AIF2_CAP Mixer"}, |
| 2403 | {"AIF3 CAP", NULL, "AIF3_CAP Mixer"}, |
| 2404 | |
| 2405 | /* SLIM_MIXER("AIF1_CAP Mixer"),*/ |
| 2406 | {"AIF1_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 2407 | {"AIF1_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 2408 | {"AIF1_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 2409 | {"AIF1_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 2410 | {"AIF1_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2411 | /* SLIM_MIXER("AIF2_CAP Mixer"),*/ |
| 2412 | {"AIF2_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 2413 | {"AIF2_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 2414 | {"AIF2_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 2415 | {"AIF2_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 2416 | {"AIF2_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2417 | /* SLIM_MIXER("AIF3_CAP Mixer"),*/ |
| 2418 | {"AIF3_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 2419 | {"AIF3_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 2420 | {"AIF3_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 2421 | {"AIF3_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 2422 | {"AIF3_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2423 | |
| 2424 | {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2425 | {"SLIM TX1 MUX", "DEC2", "DEC2 MUX"}, |
| 2426 | {"SLIM TX1 MUX", "DEC3", "DEC3 MUX"}, |
| 2427 | {"SLIM TX1 MUX", "DEC4", "DEC4 MUX"}, |
| 2428 | {"SLIM TX1 MUX", "RMIX1", "RX1 MIX1"}, |
| 2429 | {"SLIM TX1 MUX", "RMIX2", "RX2 MIX1"}, |
| 2430 | {"SLIM TX1 MUX", "RMIX3", "RX3 MIX1"}, |
| 2431 | {"SLIM TX1 MUX", "RMIX4", "RX4 MIX1"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2432 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2433 | {"SLIM TX2 MUX", "DEC1", "DEC1 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2434 | {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2435 | {"SLIM TX2 MUX", "DEC3", "DEC3 MUX"}, |
| 2436 | {"SLIM TX2 MUX", "DEC4", "DEC4 MUX"}, |
| 2437 | {"SLIM TX2 MUX", "RMIX1", "RX1 MIX1"}, |
| 2438 | {"SLIM TX2 MUX", "RMIX2", "RX2 MIX1"}, |
| 2439 | {"SLIM TX2 MUX", "RMIX3", "RX3 MIX1"}, |
| 2440 | {"SLIM TX2 MUX", "RMIX4", "RX4 MIX1"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2441 | |
| 2442 | {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"}, |
| 2443 | {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"}, |
| 2444 | {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"}, |
| 2445 | {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"}, |
| 2446 | {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2447 | |
| 2448 | {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2449 | {"SLIM TX4 MUX", "RMIX1", "RX1 MIX1"}, |
| 2450 | {"SLIM TX4 MUX", "RMIX2", "RX2 MIX1"}, |
| 2451 | {"SLIM TX4 MUX", "RMIX3", "RX3 MIX1"}, |
| 2452 | {"SLIM TX4 MUX", "RMIX4", "RX4 MIX1"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2453 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2454 | {"SLIM TX5 MUX", "DEC1", "DEC1 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2455 | {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"}, |
| 2456 | {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"}, |
| 2457 | {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"}, |
| 2458 | {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2459 | |
| 2460 | /* Earpiece (RX MIX1) */ |
| 2461 | {"EAR", NULL, "EAR PA"}, |
| 2462 | {"EAR PA", NULL, "EAR_PA_MIXER"}, |
| 2463 | {"EAR_PA_MIXER", NULL, "DAC1"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2464 | {"DAC1", NULL, "RX_BIAS"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2465 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2466 | {"ANC EAR", NULL, "ANC EAR PA"}, |
| 2467 | {"ANC EAR PA", NULL, "EAR_PA_MIXER"}, |
| 2468 | {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"}, |
| 2469 | {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"}, |
| 2470 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2471 | /* Headset (RX MIX1 and RX MIX2) */ |
| 2472 | {"HEADPHONE", NULL, "HPHL"}, |
| 2473 | {"HEADPHONE", NULL, "HPHR"}, |
| 2474 | |
| 2475 | {"HPHL", NULL, "HPHL_PA_MIXER"}, |
| 2476 | {"HPHL_PA_MIXER", NULL, "HPHL DAC"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2477 | {"HPHL DAC", NULL, "RX_BIAS"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2478 | |
| 2479 | {"HPHR", NULL, "HPHR_PA_MIXER"}, |
| 2480 | {"HPHR_PA_MIXER", NULL, "HPHR DAC"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2481 | {"HPHR DAC", NULL, "RX_BIAS"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2482 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2483 | {"ANC HEADPHONE", NULL, "ANC HPHL"}, |
| 2484 | {"ANC HEADPHONE", NULL, "ANC HPHR"}, |
| 2485 | |
| 2486 | {"ANC HPHL", NULL, "HPHL_PA_MIXER"}, |
| 2487 | {"ANC HPHR", NULL, "HPHR_PA_MIXER"}, |
| 2488 | |
| 2489 | {"ANC1 MUX", "ADC1", "ADC1"}, |
| 2490 | {"ANC1 MUX", "ADC2", "ADC2"}, |
| 2491 | {"ANC1 MUX", "ADC3", "ADC3"}, |
| 2492 | {"ANC1 MUX", "ADC4", "ADC4"}, |
| 2493 | {"ANC1 MUX", "ADC5", "ADC5"}, |
| 2494 | {"ANC1 MUX", "DMIC1", "DMIC1"}, |
| 2495 | {"ANC1 MUX", "DMIC2", "DMIC2"}, |
| 2496 | {"ANC1 MUX", "DMIC3", "DMIC3"}, |
| 2497 | {"ANC1 MUX", "DMIC4", "DMIC4"}, |
| 2498 | {"ANC2 MUX", "ADC1", "ADC1"}, |
| 2499 | {"ANC2 MUX", "ADC2", "ADC2"}, |
| 2500 | {"ANC2 MUX", "ADC3", "ADC3"}, |
| 2501 | {"ANC2 MUX", "ADC4", "ADC4"}, |
| 2502 | {"ANC2 MUX", "ADC5", "ADC5"}, |
| 2503 | {"ANC2 MUX", "DMIC1", "DMIC1"}, |
| 2504 | {"ANC2 MUX", "DMIC2", "DMIC2"}, |
| 2505 | {"ANC2 MUX", "DMIC3", "DMIC3"}, |
| 2506 | {"ANC2 MUX", "DMIC4", "DMIC4"}, |
| 2507 | |
| 2508 | {"ANC HPHR", NULL, "CDC_CONN"}, |
| 2509 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2510 | {"DAC1", "Switch", "CLASS_H_DSM MUX"}, |
| 2511 | {"HPHL DAC", "Switch", "CLASS_H_DSM MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2512 | {"HPHR DAC", NULL, "RX2 CHAIN"}, |
| 2513 | |
| 2514 | {"LINEOUT1", NULL, "LINEOUT1 PA"}, |
| 2515 | {"LINEOUT2", NULL, "LINEOUT2 PA"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2516 | {"SPK_OUT", NULL, "SPK PA"}, |
| 2517 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2518 | {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"}, |
| 2519 | {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"}, |
| 2520 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2521 | {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"}, |
| 2522 | {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"}, |
| 2523 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2524 | {"LINEOUT1 DAC", NULL, "RX3 MIX1"}, |
| 2525 | |
| 2526 | {"RDAC5 MUX", "DEM3_INV", "RX3 MIX1"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2527 | {"RDAC5 MUX", "DEM4", "RX4 MIX2"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2528 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2529 | {"LINEOUT2 DAC", NULL, "RDAC5 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2530 | |
| 2531 | {"SPK PA", NULL, "SPK DAC"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2532 | {"SPK DAC", "Switch", "RX4 MIX2"}, |
| 2533 | {"SPK DAC", NULL, "VDD_SPKDRV"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2534 | |
| 2535 | {"RX1 CHAIN", NULL, "RX1 MIX2"}, |
| 2536 | {"RX2 CHAIN", NULL, "RX2 MIX2"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2537 | {"CLASS_H_DSM MUX", "RX_HPHL", "RX1 CHAIN"}, |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2538 | {"RX1 MIX2", NULL, "ANC1 MUX"}, |
| 2539 | {"RX2 MIX2", NULL, "ANC2 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2540 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2541 | {"LINEOUT1 DAC", NULL, "RX_BIAS"}, |
| 2542 | {"LINEOUT2 DAC", NULL, "RX_BIAS"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2543 | |
| 2544 | {"RX1 MIX1", NULL, "COMP1_CLK"}, |
| 2545 | {"RX2 MIX1", NULL, "COMP1_CLK"}, |
| 2546 | {"RX3 MIX1", NULL, "COMP2_CLK"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2547 | |
| 2548 | {"RX1 MIX1", NULL, "RX1 MIX1 INP1"}, |
| 2549 | {"RX1 MIX1", NULL, "RX1 MIX1 INP2"}, |
| 2550 | {"RX1 MIX1", NULL, "RX1 MIX1 INP3"}, |
| 2551 | {"RX2 MIX1", NULL, "RX2 MIX1 INP1"}, |
| 2552 | {"RX2 MIX1", NULL, "RX2 MIX1 INP2"}, |
| 2553 | {"RX3 MIX1", NULL, "RX3 MIX1 INP1"}, |
| 2554 | {"RX3 MIX1", NULL, "RX3 MIX1 INP2"}, |
| 2555 | {"RX4 MIX1", NULL, "RX4 MIX1 INP1"}, |
| 2556 | {"RX4 MIX1", NULL, "RX4 MIX1 INP2"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2557 | {"RX1 MIX2", NULL, "RX1 MIX1"}, |
| 2558 | {"RX1 MIX2", NULL, "RX1 MIX2 INP1"}, |
| 2559 | {"RX1 MIX2", NULL, "RX1 MIX2 INP2"}, |
| 2560 | {"RX2 MIX2", NULL, "RX2 MIX1"}, |
| 2561 | {"RX2 MIX2", NULL, "RX2 MIX2 INP1"}, |
| 2562 | {"RX2 MIX2", NULL, "RX2 MIX2 INP2"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2563 | {"RX4 MIX2", NULL, "RX4 MIX1"}, |
| 2564 | {"RX4 MIX2", NULL, "RX4 MIX2 INP1"}, |
| 2565 | {"RX4 MIX2", NULL, "RX4 MIX2 INP2"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2566 | |
| 2567 | /* SLIM_MUX("AIF1_PB", "AIF1 PB"),*/ |
| 2568 | {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"}, |
| 2569 | {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"}, |
| 2570 | {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"}, |
| 2571 | {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"}, |
| 2572 | {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2573 | /* SLIM_MUX("AIF2_PB", "AIF2 PB"),*/ |
| 2574 | {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"}, |
| 2575 | {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"}, |
| 2576 | {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"}, |
| 2577 | {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"}, |
| 2578 | {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2579 | /* SLIM_MUX("AIF3_PB", "AIF3 PB"),*/ |
| 2580 | {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"}, |
| 2581 | {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"}, |
| 2582 | {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"}, |
| 2583 | {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"}, |
| 2584 | {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2585 | |
| 2586 | {"SLIM RX1", NULL, "SLIM RX1 MUX"}, |
| 2587 | {"SLIM RX2", NULL, "SLIM RX2 MUX"}, |
| 2588 | {"SLIM RX3", NULL, "SLIM RX3 MUX"}, |
| 2589 | {"SLIM RX4", NULL, "SLIM RX4 MUX"}, |
| 2590 | {"SLIM RX5", NULL, "SLIM RX5 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2591 | |
| 2592 | {"RX1 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 2593 | {"RX1 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 2594 | {"RX1 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 2595 | {"RX1 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 2596 | {"RX1 MIX1 INP1", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2597 | {"RX1 MIX1 INP1", "IIR1", "IIR1"}, |
| 2598 | {"RX1 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 2599 | {"RX1 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 2600 | {"RX1 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 2601 | {"RX1 MIX1 INP2", "RX4", "SLIM RX4"}, |
| 2602 | {"RX1 MIX1 INP2", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2603 | {"RX1 MIX1 INP2", "IIR1", "IIR1"}, |
| 2604 | {"RX1 MIX1 INP3", "RX1", "SLIM RX1"}, |
| 2605 | {"RX1 MIX1 INP3", "RX2", "SLIM RX2"}, |
| 2606 | {"RX1 MIX1 INP3", "RX3", "SLIM RX3"}, |
| 2607 | {"RX1 MIX1 INP3", "RX4", "SLIM RX4"}, |
| 2608 | {"RX1 MIX1 INP3", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2609 | {"RX2 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 2610 | {"RX2 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 2611 | {"RX2 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 2612 | {"RX2 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 2613 | {"RX2 MIX1 INP1", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2614 | {"RX2 MIX1 INP1", "IIR1", "IIR1"}, |
| 2615 | {"RX2 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 2616 | {"RX2 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 2617 | {"RX2 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 2618 | {"RX2 MIX1 INP2", "RX4", "SLIM RX4"}, |
| 2619 | {"RX2 MIX1 INP2", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2620 | {"RX2 MIX1 INP2", "IIR1", "IIR1"}, |
| 2621 | {"RX3 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 2622 | {"RX3 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 2623 | {"RX3 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 2624 | {"RX3 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 2625 | {"RX3 MIX1 INP1", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2626 | {"RX3 MIX1 INP1", "IIR1", "IIR1"}, |
| 2627 | {"RX3 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 2628 | {"RX3 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 2629 | {"RX3 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 2630 | {"RX3 MIX1 INP2", "RX4", "SLIM RX4"}, |
| 2631 | {"RX3 MIX1 INP2", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2632 | {"RX3 MIX1 INP2", "IIR1", "IIR1"}, |
| 2633 | {"RX4 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 2634 | {"RX4 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 2635 | {"RX4 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 2636 | {"RX4 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 2637 | {"RX4 MIX1 INP1", "RX5", "SLIM RX5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2638 | {"RX4 MIX1 INP1", "IIR1", "IIR1"}, |
| 2639 | {"RX4 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 2640 | {"RX4 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 2641 | {"RX4 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 2642 | {"RX4 MIX1 INP2", "RX5", "SLIM RX5"}, |
| 2643 | {"RX4 MIX1 INP2", "RX4", "SLIM RX4"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2644 | {"RX4 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2645 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2646 | {"RX1 MIX2 INP1", "IIR1", "IIR1"}, |
| 2647 | {"RX1 MIX2 INP2", "IIR1", "IIR1"}, |
| 2648 | {"RX2 MIX2 INP1", "IIR1", "IIR1"}, |
| 2649 | {"RX2 MIX2 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2650 | {"RX4 MIX2 INP1", "IIR1", "IIR1"}, |
| 2651 | {"RX4 MIX2 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2652 | |
| 2653 | /* Decimator Inputs */ |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2654 | {"DEC1 MUX", "ADC1", "ADC1"}, |
| 2655 | {"DEC1 MUX", "ADC2", "ADC2"}, |
| 2656 | {"DEC1 MUX", "ADC3", "ADC3"}, |
| 2657 | {"DEC1 MUX", "ADC4", "ADC4"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2658 | {"DEC1 MUX", "DMIC1", "DMIC1"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2659 | {"DEC1 MUX", "DMIC2", "DMIC2"}, |
| 2660 | {"DEC1 MUX", "DMIC3", "DMIC3"}, |
| 2661 | {"DEC1 MUX", "DMIC4", "DMIC4"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2662 | {"DEC1 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2663 | |
| 2664 | {"DEC2 MUX", "ADC1", "ADC1"}, |
| 2665 | {"DEC2 MUX", "ADC2", "ADC2"}, |
| 2666 | {"DEC2 MUX", "ADC3", "ADC3"}, |
| 2667 | {"DEC2 MUX", "ADC4", "ADC4"}, |
| 2668 | {"DEC2 MUX", "DMIC1", "DMIC1"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2669 | {"DEC2 MUX", "DMIC2", "DMIC2"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2670 | {"DEC2 MUX", "DMIC3", "DMIC3"}, |
| 2671 | {"DEC2 MUX", "DMIC4", "DMIC4"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2672 | {"DEC2 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2673 | |
| 2674 | {"DEC3 MUX", "ADC1", "ADC1"}, |
| 2675 | {"DEC3 MUX", "ADC2", "ADC2"}, |
| 2676 | {"DEC3 MUX", "ADC3", "ADC3"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2677 | {"DEC3 MUX", "ADC4", "ADC4"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2678 | {"DEC3 MUX", "ADC5", "ADC5"}, |
| 2679 | {"DEC3 MUX", "DMIC1", "DMIC1"}, |
| 2680 | {"DEC3 MUX", "DMIC2", "DMIC2"}, |
| 2681 | {"DEC3 MUX", "DMIC3", "DMIC3"}, |
| 2682 | {"DEC3 MUX", "DMIC4", "DMIC4"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2683 | {"DEC3 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2684 | |
| 2685 | {"DEC4 MUX", "ADC1", "ADC1"}, |
| 2686 | {"DEC4 MUX", "ADC2", "ADC2"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2687 | {"DEC4 MUX", "ADC3", "ADC3"}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2688 | {"DEC4 MUX", "ADC4", "ADC4"}, |
| 2689 | {"DEC4 MUX", "ADC5", "ADC5"}, |
| 2690 | {"DEC4 MUX", "DMIC1", "DMIC1"}, |
| 2691 | {"DEC4 MUX", "DMIC2", "DMIC2"}, |
| 2692 | {"DEC4 MUX", "DMIC3", "DMIC3"}, |
| 2693 | {"DEC4 MUX", "DMIC4", "DMIC4"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2694 | {"DEC4 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2695 | |
| 2696 | /* ADC Connections */ |
| 2697 | {"ADC1", NULL, "AMIC1"}, |
| 2698 | {"ADC2", NULL, "AMIC2"}, |
| 2699 | {"ADC3", NULL, "AMIC3"}, |
| 2700 | {"ADC4", NULL, "AMIC4"}, |
| 2701 | {"ADC5", NULL, "AMIC5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2702 | |
| 2703 | /* AUX PGA Connections */ |
| 2704 | {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 2705 | {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 2706 | {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 2707 | {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 2708 | {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2709 | {"AUX_PGA_Left", NULL, "AMIC5"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2710 | |
| 2711 | {"IIR1", NULL, "IIR1 INP1 MUX"}, |
| 2712 | {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"}, |
| 2713 | {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"}, |
| 2714 | {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"}, |
| 2715 | {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2716 | |
| 2717 | {"MIC BIAS1 Internal1", NULL, "LDO_H"}, |
| 2718 | {"MIC BIAS1 Internal2", NULL, "LDO_H"}, |
| 2719 | {"MIC BIAS1 External", NULL, "LDO_H"}, |
| 2720 | {"MIC BIAS2 Internal1", NULL, "LDO_H"}, |
| 2721 | {"MIC BIAS2 Internal2", NULL, "LDO_H"}, |
| 2722 | {"MIC BIAS2 Internal3", NULL, "LDO_H"}, |
| 2723 | {"MIC BIAS2 External", NULL, "LDO_H"}, |
| 2724 | {"MIC BIAS3 Internal1", NULL, "LDO_H"}, |
| 2725 | {"MIC BIAS3 Internal2", NULL, "LDO_H"}, |
| 2726 | {"MIC BIAS3 External", NULL, "LDO_H"}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2727 | }; |
| 2728 | |
| 2729 | static int tapan_readable(struct snd_soc_codec *ssc, unsigned int reg) |
| 2730 | { |
| 2731 | return tapan_reg_readable[reg]; |
| 2732 | } |
| 2733 | |
| 2734 | static bool tapan_is_digital_gain_register(unsigned int reg) |
| 2735 | { |
| 2736 | bool rtn = false; |
| 2737 | switch (reg) { |
| 2738 | case TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL: |
| 2739 | case TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL: |
| 2740 | case TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL: |
| 2741 | case TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL: |
| 2742 | case TAPAN_A_CDC_TX1_VOL_CTL_GAIN: |
| 2743 | case TAPAN_A_CDC_TX2_VOL_CTL_GAIN: |
| 2744 | case TAPAN_A_CDC_TX3_VOL_CTL_GAIN: |
| 2745 | case TAPAN_A_CDC_TX4_VOL_CTL_GAIN: |
| 2746 | rtn = true; |
| 2747 | break; |
| 2748 | default: |
| 2749 | break; |
| 2750 | } |
| 2751 | return rtn; |
| 2752 | } |
| 2753 | |
| 2754 | static int tapan_volatile(struct snd_soc_codec *ssc, unsigned int reg) |
| 2755 | { |
| 2756 | /* Registers lower than 0x100 are top level registers which can be |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2757 | * written by the Tapan core driver. |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2758 | */ |
| 2759 | |
| 2760 | if ((reg >= TAPAN_A_CDC_MBHC_EN_CTL) || (reg < 0x100)) |
| 2761 | return 1; |
| 2762 | |
| 2763 | /* IIR Coeff registers are not cacheable */ |
| 2764 | if ((reg >= TAPAN_A_CDC_IIR1_COEF_B1_CTL) && |
| 2765 | (reg <= TAPAN_A_CDC_IIR2_COEF_B2_CTL)) |
| 2766 | return 1; |
| 2767 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 2768 | /* ANC filter registers are not cacheable */ |
| 2769 | if ((reg >= TAPAN_A_CDC_ANC1_IIR_B1_CTL) && |
| 2770 | (reg <= TAPAN_A_CDC_ANC1_LPF_B2_CTL)) |
| 2771 | return 1; |
| 2772 | if ((reg >= TAPAN_A_CDC_ANC2_IIR_B1_CTL) && |
| 2773 | (reg <= TAPAN_A_CDC_ANC2_LPF_B2_CTL)) |
| 2774 | return 1; |
| 2775 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2776 | /* Digital gain register is not cacheable so we have to write |
| 2777 | * the setting even it is the same |
| 2778 | */ |
| 2779 | if (tapan_is_digital_gain_register(reg)) |
| 2780 | return 1; |
| 2781 | |
| 2782 | /* HPH status registers */ |
| 2783 | if (reg == TAPAN_A_RX_HPH_L_STATUS || reg == TAPAN_A_RX_HPH_R_STATUS) |
| 2784 | return 1; |
| 2785 | |
| 2786 | if (reg == TAPAN_A_MBHC_INSERT_DET_STATUS) |
| 2787 | return 1; |
| 2788 | |
| 2789 | return 0; |
| 2790 | } |
| 2791 | |
| 2792 | #define TAPAN_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) |
| 2793 | static int tapan_write(struct snd_soc_codec *codec, unsigned int reg, |
| 2794 | unsigned int value) |
| 2795 | { |
| 2796 | int ret; |
| 2797 | |
| 2798 | if (reg == SND_SOC_NOPM) |
| 2799 | return 0; |
| 2800 | |
| 2801 | BUG_ON(reg > TAPAN_MAX_REGISTER); |
| 2802 | |
| 2803 | if (!tapan_volatile(codec, reg)) { |
| 2804 | ret = snd_soc_cache_write(codec, reg, value); |
| 2805 | if (ret != 0) |
| 2806 | dev_err(codec->dev, "Cache write to %x failed: %d\n", |
| 2807 | reg, ret); |
| 2808 | } |
| 2809 | |
| 2810 | return wcd9xxx_reg_write(codec->control_data, reg, value); |
| 2811 | } |
| 2812 | static unsigned int tapan_read(struct snd_soc_codec *codec, |
| 2813 | unsigned int reg) |
| 2814 | { |
| 2815 | unsigned int val; |
| 2816 | int ret; |
| 2817 | |
| 2818 | if (reg == SND_SOC_NOPM) |
| 2819 | return 0; |
| 2820 | |
| 2821 | BUG_ON(reg > TAPAN_MAX_REGISTER); |
| 2822 | |
| 2823 | if (!tapan_volatile(codec, reg) && tapan_readable(codec, reg) && |
| 2824 | reg < codec->driver->reg_cache_size) { |
| 2825 | ret = snd_soc_cache_read(codec, reg, &val); |
| 2826 | if (ret >= 0) { |
| 2827 | return val; |
| 2828 | } else |
| 2829 | dev_err(codec->dev, "Cache read from %x failed: %d\n", |
| 2830 | reg, ret); |
| 2831 | } |
| 2832 | |
| 2833 | val = wcd9xxx_reg_read(codec->control_data, reg); |
| 2834 | return val; |
| 2835 | } |
| 2836 | |
| 2837 | static int tapan_startup(struct snd_pcm_substream *substream, |
| 2838 | struct snd_soc_dai *dai) |
| 2839 | { |
| 2840 | struct wcd9xxx *tapan_core = dev_get_drvdata(dai->codec->dev->parent); |
| 2841 | dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n", |
| 2842 | __func__, substream->name, substream->stream); |
| 2843 | if ((tapan_core != NULL) && |
| 2844 | (tapan_core->dev != NULL) && |
| 2845 | (tapan_core->dev->parent != NULL)) |
| 2846 | pm_runtime_get_sync(tapan_core->dev->parent); |
| 2847 | |
| 2848 | return 0; |
| 2849 | } |
| 2850 | |
| 2851 | static void tapan_shutdown(struct snd_pcm_substream *substream, |
| 2852 | struct snd_soc_dai *dai) |
| 2853 | { |
| 2854 | struct wcd9xxx *tapan_core = dev_get_drvdata(dai->codec->dev->parent); |
| 2855 | dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n", |
| 2856 | __func__, substream->name, substream->stream); |
| 2857 | if ((tapan_core != NULL) && |
| 2858 | (tapan_core->dev != NULL) && |
| 2859 | (tapan_core->dev->parent != NULL)) { |
| 2860 | pm_runtime_mark_last_busy(tapan_core->dev->parent); |
| 2861 | pm_runtime_put(tapan_core->dev->parent); |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | int tapan_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, bool dapm) |
| 2866 | { |
| 2867 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 2868 | |
| 2869 | dev_dbg(codec->dev, "%s: mclk_enable = %u, dapm = %d\n", __func__, |
| 2870 | mclk_enable, dapm); |
| 2871 | |
| 2872 | WCD9XXX_BCL_LOCK(&tapan->resmgr); |
| 2873 | if (mclk_enable) { |
| 2874 | wcd9xxx_resmgr_get_bandgap(&tapan->resmgr, |
| 2875 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 2876 | wcd9xxx_resmgr_get_clk_block(&tapan->resmgr, WCD9XXX_CLK_MCLK); |
| 2877 | } else { |
| 2878 | /* Put clock and BG */ |
| 2879 | wcd9xxx_resmgr_put_clk_block(&tapan->resmgr, WCD9XXX_CLK_MCLK); |
| 2880 | wcd9xxx_resmgr_put_bandgap(&tapan->resmgr, |
| 2881 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 2882 | } |
| 2883 | WCD9XXX_BCL_UNLOCK(&tapan->resmgr); |
| 2884 | |
| 2885 | return 0; |
| 2886 | } |
| 2887 | |
| 2888 | static int tapan_set_dai_sysclk(struct snd_soc_dai *dai, |
| 2889 | int clk_id, unsigned int freq, int dir) |
| 2890 | { |
| 2891 | dev_dbg(dai->codec->dev, "%s\n", __func__); |
| 2892 | return 0; |
| 2893 | } |
| 2894 | |
| 2895 | static int tapan_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 2896 | { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2897 | u8 val = 0; |
| 2898 | struct snd_soc_codec *codec = dai->codec; |
| 2899 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 2900 | |
| 2901 | dev_dbg(codec->dev, "%s\n", __func__); |
| 2902 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 2903 | case SND_SOC_DAIFMT_CBS_CFS: |
| 2904 | /* CPU is master */ |
| 2905 | if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 2906 | if (dai->id == AIF1_CAP) |
| 2907 | snd_soc_update_bits(codec, |
| 2908 | TAPAN_A_CDC_CLK_I2S_CTL, |
| 2909 | TAPAN_I2S_MASTER_MODE_MASK, 0); |
| 2910 | else if (dai->id == AIF1_PB) |
| 2911 | snd_soc_update_bits(codec, |
| 2912 | TAPAN_A_CDC_CLK_I2S_CTL, |
| 2913 | TAPAN_I2S_MASTER_MODE_MASK, 0); |
| 2914 | } |
| 2915 | break; |
| 2916 | case SND_SOC_DAIFMT_CBM_CFM: |
| 2917 | /* CPU is slave */ |
| 2918 | if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 2919 | val = TAPAN_I2S_MASTER_MODE_MASK; |
| 2920 | if (dai->id == AIF1_CAP) |
| 2921 | snd_soc_update_bits(codec, |
| 2922 | TAPAN_A_CDC_CLK_I2S_CTL, val, val); |
| 2923 | else if (dai->id == AIF1_PB) |
| 2924 | snd_soc_update_bits(codec, |
| 2925 | TAPAN_A_CDC_CLK_I2S_CTL, val, val); |
| 2926 | } |
| 2927 | break; |
| 2928 | default: |
| 2929 | return -EINVAL; |
| 2930 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 2931 | return 0; |
| 2932 | } |
| 2933 | |
| 2934 | static int tapan_set_channel_map(struct snd_soc_dai *dai, |
| 2935 | unsigned int tx_num, unsigned int *tx_slot, |
| 2936 | unsigned int rx_num, unsigned int *rx_slot) |
| 2937 | |
| 2938 | { |
| 2939 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(dai->codec); |
| 2940 | struct wcd9xxx *core = dev_get_drvdata(dai->codec->dev->parent); |
| 2941 | if (!tx_slot && !rx_slot) { |
| 2942 | pr_err("%s: Invalid\n", __func__); |
| 2943 | return -EINVAL; |
| 2944 | } |
| 2945 | dev_dbg(dai->codec->dev, "%s(): dai_name = %s DAI-ID %x\n", |
| 2946 | __func__, dai->name, dai->id); |
| 2947 | dev_dbg(dai->codec->dev, "%s(): tx_ch %d rx_ch %d\n intf_type %d\n", |
| 2948 | __func__, tx_num, rx_num, tapan->intf_type); |
| 2949 | |
| 2950 | if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 2951 | wcd9xxx_init_slimslave(core, core->slim->laddr, |
| 2952 | tx_num, tx_slot, rx_num, rx_slot); |
| 2953 | return 0; |
| 2954 | } |
| 2955 | |
| 2956 | static int tapan_get_channel_map(struct snd_soc_dai *dai, |
| 2957 | unsigned int *tx_num, unsigned int *tx_slot, |
| 2958 | unsigned int *rx_num, unsigned int *rx_slot) |
| 2959 | |
| 2960 | { |
| 2961 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(dai->codec); |
| 2962 | u32 i = 0; |
| 2963 | struct wcd9xxx_ch *ch; |
| 2964 | |
| 2965 | switch (dai->id) { |
| 2966 | case AIF1_PB: |
| 2967 | case AIF2_PB: |
| 2968 | case AIF3_PB: |
| 2969 | if (!rx_slot || !rx_num) { |
| 2970 | pr_err("%s: Invalid rx_slot %d or rx_num %d\n", |
| 2971 | __func__, (u32) rx_slot, (u32) rx_num); |
| 2972 | return -EINVAL; |
| 2973 | } |
| 2974 | list_for_each_entry(ch, &tapan_p->dai[dai->id].wcd9xxx_ch_list, |
| 2975 | list) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 2976 | 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] | 2977 | __func__, i, rx_slot[i], ch->ch_num); |
| 2978 | rx_slot[i++] = ch->ch_num; |
| 2979 | } |
| 2980 | dev_dbg(dai->codec->dev, "%s: rx_num %d\n", __func__, i); |
| 2981 | *rx_num = i; |
| 2982 | break; |
| 2983 | case AIF1_CAP: |
| 2984 | case AIF2_CAP: |
| 2985 | case AIF3_CAP: |
| 2986 | if (!tx_slot || !tx_num) { |
| 2987 | pr_err("%s: Invalid tx_slot %d or tx_num %d\n", |
| 2988 | __func__, (u32) tx_slot, (u32) tx_num); |
| 2989 | return -EINVAL; |
| 2990 | } |
| 2991 | list_for_each_entry(ch, &tapan_p->dai[dai->id].wcd9xxx_ch_list, |
| 2992 | list) { |
| 2993 | dev_dbg(dai->codec->dev, "%s: tx_slot[%d] %d, ch->ch_num %d\n", |
| 2994 | __func__, i, tx_slot[i], ch->ch_num); |
| 2995 | tx_slot[i++] = ch->ch_num; |
| 2996 | } |
| 2997 | dev_dbg(dai->codec->dev, "%s: tx_num %d\n", __func__, i); |
| 2998 | *tx_num = i; |
| 2999 | break; |
| 3000 | |
| 3001 | default: |
| 3002 | pr_err("%s: Invalid DAI ID %x\n", __func__, dai->id); |
| 3003 | break; |
| 3004 | } |
| 3005 | |
| 3006 | return 0; |
| 3007 | } |
| 3008 | |
| 3009 | static int tapan_set_interpolator_rate(struct snd_soc_dai *dai, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3010 | u8 rx_fs_rate_reg_val, u32 compander_fs, u32 sample_rate) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3011 | { |
| 3012 | u32 j; |
| 3013 | u8 rx_mix1_inp; |
| 3014 | u16 rx_mix_1_reg_1, rx_mix_1_reg_2; |
| 3015 | u16 rx_fs_reg; |
| 3016 | u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val; |
| 3017 | struct snd_soc_codec *codec = dai->codec; |
| 3018 | struct wcd9xxx_ch *ch; |
| 3019 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 3020 | |
| 3021 | list_for_each_entry(ch, &tapan->dai[dai->id].wcd9xxx_ch_list, list) { |
| 3022 | /* for RX port starting from 16 instead of 10 like tabla */ |
| 3023 | rx_mix1_inp = ch->port + RX_MIX1_INP_SEL_RX1 - |
| 3024 | TAPAN_TX_PORT_NUMBER; |
| 3025 | if ((rx_mix1_inp < RX_MIX1_INP_SEL_RX1) || |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3026 | (rx_mix1_inp > RX_MIX1_INP_SEL_RX5)) { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3027 | pr_err("%s: Invalid TAPAN_RX%u port. Dai ID is %d\n", |
| 3028 | __func__, rx_mix1_inp - 5 , dai->id); |
| 3029 | return -EINVAL; |
| 3030 | } |
| 3031 | |
| 3032 | rx_mix_1_reg_1 = TAPAN_A_CDC_CONN_RX1_B1_CTL; |
| 3033 | |
| 3034 | for (j = 0; j < NUM_INTERPOLATORS; j++) { |
| 3035 | rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1; |
| 3036 | |
| 3037 | rx_mix_1_reg_1_val = snd_soc_read(codec, |
| 3038 | rx_mix_1_reg_1); |
| 3039 | rx_mix_1_reg_2_val = snd_soc_read(codec, |
| 3040 | rx_mix_1_reg_2); |
| 3041 | |
| 3042 | if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) || |
| 3043 | (((rx_mix_1_reg_1_val >> 4) & 0x0F) |
| 3044 | == rx_mix1_inp) || |
| 3045 | ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) { |
| 3046 | |
| 3047 | rx_fs_reg = TAPAN_A_CDC_RX1_B5_CTL + 8 * j; |
| 3048 | |
| 3049 | dev_dbg(codec->dev, "%s: AIF_PB DAI(%d) connected to RX%u\n", |
| 3050 | __func__, dai->id, j + 1); |
| 3051 | |
| 3052 | dev_dbg(codec->dev, "%s: set RX%u sample rate to %u\n", |
| 3053 | __func__, j + 1, sample_rate); |
| 3054 | |
| 3055 | snd_soc_update_bits(codec, rx_fs_reg, |
| 3056 | 0xE0, rx_fs_rate_reg_val); |
| 3057 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3058 | if (comp_rx_path[j] < COMPANDER_MAX) |
| 3059 | tapan->comp_fs[comp_rx_path[j]] |
| 3060 | = compander_fs; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3061 | } |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 3062 | if (j <= 1) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3063 | rx_mix_1_reg_1 += 3; |
| 3064 | else |
| 3065 | rx_mix_1_reg_1 += 2; |
| 3066 | } |
| 3067 | } |
| 3068 | return 0; |
| 3069 | } |
| 3070 | |
| 3071 | static int tapan_set_decimator_rate(struct snd_soc_dai *dai, |
| 3072 | u8 tx_fs_rate_reg_val, u32 sample_rate) |
| 3073 | { |
| 3074 | struct snd_soc_codec *codec = dai->codec; |
| 3075 | struct wcd9xxx_ch *ch; |
| 3076 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 3077 | u32 tx_port; |
| 3078 | u16 tx_port_reg, tx_fs_reg; |
| 3079 | u8 tx_port_reg_val; |
| 3080 | s8 decimator; |
| 3081 | |
| 3082 | list_for_each_entry(ch, &tapan->dai[dai->id].wcd9xxx_ch_list, list) { |
| 3083 | |
| 3084 | tx_port = ch->port + 1; |
| 3085 | dev_dbg(codec->dev, "%s: dai->id = %d, tx_port = %d", |
| 3086 | __func__, dai->id, tx_port); |
| 3087 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3088 | if ((tx_port < 1) || (tx_port > TAPAN_SLIM_CODEC_TX_PORTS)) { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3089 | pr_err("%s: Invalid SLIM TX%u port. DAI ID is %d\n", |
| 3090 | __func__, tx_port, dai->id); |
| 3091 | return -EINVAL; |
| 3092 | } |
| 3093 | |
| 3094 | tx_port_reg = TAPAN_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1); |
| 3095 | tx_port_reg_val = snd_soc_read(codec, tx_port_reg); |
| 3096 | |
| 3097 | decimator = 0; |
| 3098 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3099 | tx_port_reg_val = tx_port_reg_val & 0x0F; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3100 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3101 | if ((tx_port_reg_val >= 0x8) && |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3102 | (tx_port_reg_val <= 0x11)) { |
| 3103 | |
| 3104 | decimator = (tx_port_reg_val - 0x8) + 1; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3105 | } |
| 3106 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3107 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3108 | if (decimator) { /* SLIM_TX port has a DEC as input */ |
| 3109 | |
| 3110 | tx_fs_reg = TAPAN_A_CDC_TX1_CLK_FS_CTL + |
| 3111 | 8 * (decimator - 1); |
| 3112 | |
| 3113 | dev_dbg(codec->dev, "%s: set DEC%u (-> SLIM_TX%u) rate to %u\n", |
| 3114 | __func__, decimator, tx_port, sample_rate); |
| 3115 | |
| 3116 | snd_soc_update_bits(codec, tx_fs_reg, 0x07, |
| 3117 | tx_fs_rate_reg_val); |
| 3118 | |
| 3119 | } else { |
| 3120 | if ((tx_port_reg_val >= 0x1) && |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3121 | (tx_port_reg_val <= 0x4)) { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3122 | |
| 3123 | dev_dbg(codec->dev, "%s: RMIX%u going to SLIM TX%u\n", |
| 3124 | __func__, tx_port_reg_val, tx_port); |
| 3125 | |
| 3126 | } else if ((tx_port_reg_val >= 0x8) && |
| 3127 | (tx_port_reg_val <= 0x11)) { |
| 3128 | |
| 3129 | pr_err("%s: ERROR: Should not be here\n", |
| 3130 | __func__); |
| 3131 | pr_err("%s: ERROR: DEC connected to SLIM TX%u\n", |
| 3132 | __func__, tx_port); |
| 3133 | return -EINVAL; |
| 3134 | |
| 3135 | } else if (tx_port_reg_val == 0) { |
| 3136 | dev_dbg(codec->dev, "%s: no signal to SLIM TX%u\n", |
| 3137 | __func__, tx_port); |
| 3138 | } else { |
| 3139 | pr_err("%s: ERROR: wrong signal to SLIM TX%u\n", |
| 3140 | __func__, tx_port); |
| 3141 | pr_err("%s: ERROR: wrong signal = %u\n", |
| 3142 | __func__, tx_port_reg_val); |
| 3143 | return -EINVAL; |
| 3144 | } |
| 3145 | } |
| 3146 | } |
| 3147 | return 0; |
| 3148 | } |
| 3149 | |
| 3150 | static int tapan_hw_params(struct snd_pcm_substream *substream, |
| 3151 | struct snd_pcm_hw_params *params, |
| 3152 | struct snd_soc_dai *dai) |
| 3153 | { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3154 | struct snd_soc_codec *codec = dai->codec; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3155 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(dai->codec); |
| 3156 | u8 tx_fs_rate, rx_fs_rate; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3157 | u32 compander_fs; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3158 | int ret; |
| 3159 | |
| 3160 | dev_dbg(dai->codec->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", |
| 3161 | __func__, dai->name, dai->id, |
| 3162 | params_rate(params), params_channels(params)); |
| 3163 | |
| 3164 | switch (params_rate(params)) { |
| 3165 | case 8000: |
| 3166 | tx_fs_rate = 0x00; |
| 3167 | rx_fs_rate = 0x00; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3168 | compander_fs = COMPANDER_FS_8KHZ; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3169 | break; |
| 3170 | case 16000: |
| 3171 | tx_fs_rate = 0x01; |
| 3172 | rx_fs_rate = 0x20; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3173 | compander_fs = COMPANDER_FS_16KHZ; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3174 | break; |
| 3175 | case 32000: |
| 3176 | tx_fs_rate = 0x02; |
| 3177 | rx_fs_rate = 0x40; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3178 | compander_fs = COMPANDER_FS_32KHZ; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3179 | break; |
| 3180 | case 48000: |
| 3181 | tx_fs_rate = 0x03; |
| 3182 | rx_fs_rate = 0x60; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3183 | compander_fs = COMPANDER_FS_48KHZ; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3184 | break; |
| 3185 | case 96000: |
| 3186 | tx_fs_rate = 0x04; |
| 3187 | rx_fs_rate = 0x80; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3188 | compander_fs = COMPANDER_FS_96KHZ; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3189 | break; |
| 3190 | case 192000: |
| 3191 | tx_fs_rate = 0x05; |
| 3192 | rx_fs_rate = 0xA0; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3193 | compander_fs = COMPANDER_FS_192KHZ; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3194 | break; |
| 3195 | default: |
| 3196 | pr_err("%s: Invalid sampling rate %d\n", __func__, |
| 3197 | params_rate(params)); |
| 3198 | return -EINVAL; |
| 3199 | } |
| 3200 | |
| 3201 | switch (substream->stream) { |
| 3202 | case SNDRV_PCM_STREAM_CAPTURE: |
| 3203 | ret = tapan_set_decimator_rate(dai, tx_fs_rate, |
| 3204 | params_rate(params)); |
| 3205 | if (ret < 0) { |
| 3206 | pr_err("%s: set decimator rate failed %d\n", __func__, |
| 3207 | ret); |
| 3208 | return ret; |
| 3209 | } |
| 3210 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3211 | if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 3212 | switch (params_format(params)) { |
| 3213 | case SNDRV_PCM_FORMAT_S16_LE: |
| 3214 | snd_soc_update_bits(codec, |
| 3215 | TAPAN_A_CDC_CLK_I2S_CTL, |
| 3216 | 0x20, 0x20); |
| 3217 | break; |
| 3218 | case SNDRV_PCM_FORMAT_S32_LE: |
| 3219 | snd_soc_update_bits(codec, |
| 3220 | TAPAN_A_CDC_CLK_I2S_CTL, |
| 3221 | 0x20, 0x00); |
| 3222 | break; |
| 3223 | default: |
| 3224 | pr_err("invalid format\n"); |
| 3225 | break; |
| 3226 | } |
| 3227 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_I2S_CTL, |
| 3228 | 0x07, tx_fs_rate); |
| 3229 | } else { |
| 3230 | tapan->dai[dai->id].rate = params_rate(params); |
| 3231 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3232 | break; |
| 3233 | |
| 3234 | case SNDRV_PCM_STREAM_PLAYBACK: |
| 3235 | ret = tapan_set_interpolator_rate(dai, rx_fs_rate, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3236 | compander_fs, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3237 | params_rate(params)); |
| 3238 | if (ret < 0) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3239 | dev_err(codec->dev, "%s: set decimator rate failed %d\n", |
| 3240 | __func__, ret); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3241 | return ret; |
| 3242 | } |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3243 | if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 3244 | switch (params_format(params)) { |
| 3245 | case SNDRV_PCM_FORMAT_S16_LE: |
| 3246 | snd_soc_update_bits(codec, |
| 3247 | TAPAN_A_CDC_CLK_I2S_CTL, |
| 3248 | 0x20, 0x20); |
| 3249 | break; |
| 3250 | case SNDRV_PCM_FORMAT_S32_LE: |
| 3251 | snd_soc_update_bits(codec, |
| 3252 | TAPAN_A_CDC_CLK_I2S_CTL, |
| 3253 | 0x20, 0x00); |
| 3254 | break; |
| 3255 | default: |
| 3256 | dev_err(codec->dev, "invalid format\n"); |
| 3257 | break; |
| 3258 | } |
| 3259 | snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_I2S_CTL, |
| 3260 | 0x03, (rx_fs_rate >> 0x05)); |
| 3261 | } else { |
| 3262 | switch (params_format(params)) { |
| 3263 | case SNDRV_PCM_FORMAT_S16_LE: |
| 3264 | snd_soc_update_bits(codec, |
| 3265 | TAPAN_A_CDC_CONN_RX_SB_B1_CTL, |
| 3266 | 0xFF, 0xAA); |
| 3267 | snd_soc_update_bits(codec, |
| 3268 | TAPAN_A_CDC_CONN_RX_SB_B2_CTL, |
| 3269 | 0xFF, 0x2A); |
| 3270 | tapan->dai[dai->id].bit_width = 16; |
| 3271 | break; |
| 3272 | case SNDRV_PCM_FORMAT_S24_LE: |
| 3273 | snd_soc_update_bits(codec, |
| 3274 | TAPAN_A_CDC_CONN_RX_SB_B1_CTL, |
| 3275 | 0xFF, 0x00); |
| 3276 | snd_soc_update_bits(codec, |
| 3277 | TAPAN_A_CDC_CONN_RX_SB_B2_CTL, |
| 3278 | 0xFF, 0x00); |
| 3279 | tapan->dai[dai->id].bit_width = 24; |
| 3280 | break; |
| 3281 | default: |
| 3282 | dev_err(codec->dev, "Invalid format\n"); |
| 3283 | break; |
| 3284 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3285 | tapan->dai[dai->id].rate = params_rate(params); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3286 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3287 | break; |
| 3288 | default: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3289 | dev_err(codec->dev, "%s: Invalid stream type %d\n", __func__, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3290 | substream->stream); |
| 3291 | return -EINVAL; |
| 3292 | } |
| 3293 | |
| 3294 | return 0; |
| 3295 | } |
| 3296 | |
| 3297 | static struct snd_soc_dai_ops tapan_dai_ops = { |
| 3298 | .startup = tapan_startup, |
| 3299 | .shutdown = tapan_shutdown, |
| 3300 | .hw_params = tapan_hw_params, |
| 3301 | .set_sysclk = tapan_set_dai_sysclk, |
| 3302 | .set_fmt = tapan_set_dai_fmt, |
| 3303 | .set_channel_map = tapan_set_channel_map, |
| 3304 | .get_channel_map = tapan_get_channel_map, |
| 3305 | }; |
| 3306 | |
| 3307 | static struct snd_soc_dai_driver tapan_dai[] = { |
| 3308 | { |
| 3309 | .name = "tapan_rx1", |
| 3310 | .id = AIF1_PB, |
| 3311 | .playback = { |
| 3312 | .stream_name = "AIF1 Playback", |
| 3313 | .rates = WCD9306_RATES, |
| 3314 | .formats = TAPAN_FORMATS, |
| 3315 | .rate_max = 192000, |
| 3316 | .rate_min = 8000, |
| 3317 | .channels_min = 1, |
| 3318 | .channels_max = 2, |
| 3319 | }, |
| 3320 | .ops = &tapan_dai_ops, |
| 3321 | }, |
| 3322 | { |
| 3323 | .name = "tapan_tx1", |
| 3324 | .id = AIF1_CAP, |
| 3325 | .capture = { |
| 3326 | .stream_name = "AIF1 Capture", |
| 3327 | .rates = WCD9306_RATES, |
| 3328 | .formats = TAPAN_FORMATS, |
| 3329 | .rate_max = 192000, |
| 3330 | .rate_min = 8000, |
| 3331 | .channels_min = 1, |
| 3332 | .channels_max = 4, |
| 3333 | }, |
| 3334 | .ops = &tapan_dai_ops, |
| 3335 | }, |
| 3336 | { |
| 3337 | .name = "tapan_rx2", |
| 3338 | .id = AIF2_PB, |
| 3339 | .playback = { |
| 3340 | .stream_name = "AIF2 Playback", |
| 3341 | .rates = WCD9306_RATES, |
| 3342 | .formats = TAPAN_FORMATS, |
| 3343 | .rate_min = 8000, |
| 3344 | .rate_max = 192000, |
| 3345 | .channels_min = 1, |
| 3346 | .channels_max = 2, |
| 3347 | }, |
| 3348 | .ops = &tapan_dai_ops, |
| 3349 | }, |
| 3350 | { |
| 3351 | .name = "tapan_tx2", |
| 3352 | .id = AIF2_CAP, |
| 3353 | .capture = { |
| 3354 | .stream_name = "AIF2 Capture", |
| 3355 | .rates = WCD9306_RATES, |
| 3356 | .formats = TAPAN_FORMATS, |
| 3357 | .rate_max = 192000, |
| 3358 | .rate_min = 8000, |
| 3359 | .channels_min = 1, |
| 3360 | .channels_max = 4, |
| 3361 | }, |
| 3362 | .ops = &tapan_dai_ops, |
| 3363 | }, |
| 3364 | { |
| 3365 | .name = "tapan_tx3", |
| 3366 | .id = AIF3_CAP, |
| 3367 | .capture = { |
| 3368 | .stream_name = "AIF3 Capture", |
| 3369 | .rates = WCD9306_RATES, |
| 3370 | .formats = TAPAN_FORMATS, |
| 3371 | .rate_max = 48000, |
| 3372 | .rate_min = 8000, |
| 3373 | .channels_min = 1, |
| 3374 | .channels_max = 2, |
| 3375 | }, |
| 3376 | .ops = &tapan_dai_ops, |
| 3377 | }, |
| 3378 | { |
| 3379 | .name = "tapan_rx3", |
| 3380 | .id = AIF3_PB, |
| 3381 | .playback = { |
| 3382 | .stream_name = "AIF3 Playback", |
| 3383 | .rates = WCD9306_RATES, |
| 3384 | .formats = TAPAN_FORMATS, |
| 3385 | .rate_min = 8000, |
| 3386 | .rate_max = 192000, |
| 3387 | .channels_min = 1, |
| 3388 | .channels_max = 2, |
| 3389 | }, |
| 3390 | .ops = &tapan_dai_ops, |
| 3391 | }, |
| 3392 | }; |
| 3393 | |
| 3394 | static struct snd_soc_dai_driver tapan_i2s_dai[] = { |
| 3395 | { |
| 3396 | .name = "tapan_i2s_rx1", |
| 3397 | .id = AIF1_PB, |
| 3398 | .playback = { |
| 3399 | .stream_name = "AIF1 Playback", |
| 3400 | .rates = WCD9306_RATES, |
| 3401 | .formats = TAPAN_FORMATS, |
| 3402 | .rate_max = 192000, |
| 3403 | .rate_min = 8000, |
| 3404 | .channels_min = 1, |
| 3405 | .channels_max = 4, |
| 3406 | }, |
| 3407 | .ops = &tapan_dai_ops, |
| 3408 | }, |
| 3409 | { |
| 3410 | .name = "tapan_i2s_tx1", |
| 3411 | .id = AIF1_CAP, |
| 3412 | .capture = { |
| 3413 | .stream_name = "AIF1 Capture", |
| 3414 | .rates = WCD9306_RATES, |
| 3415 | .formats = TAPAN_FORMATS, |
| 3416 | .rate_max = 192000, |
| 3417 | .rate_min = 8000, |
| 3418 | .channels_min = 1, |
| 3419 | .channels_max = 4, |
| 3420 | }, |
| 3421 | .ops = &tapan_dai_ops, |
| 3422 | }, |
| 3423 | }; |
| 3424 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3425 | static int tapan_codec_enable_slim_chmask(struct wcd9xxx_codec_dai_data *dai, |
| 3426 | bool up) |
| 3427 | { |
| 3428 | int ret = 0; |
| 3429 | struct wcd9xxx_ch *ch; |
| 3430 | |
| 3431 | if (up) { |
| 3432 | list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) { |
| 3433 | ret = wcd9xxx_get_slave_port(ch->ch_num); |
| 3434 | if (ret < 0) { |
| 3435 | pr_debug("%s: Invalid slave port ID: %d\n", |
| 3436 | __func__, ret); |
| 3437 | ret = -EINVAL; |
| 3438 | } else { |
| 3439 | set_bit(ret, &dai->ch_mask); |
| 3440 | } |
| 3441 | } |
| 3442 | } else { |
| 3443 | ret = wait_event_timeout(dai->dai_wait, (dai->ch_mask == 0), |
| 3444 | msecs_to_jiffies( |
| 3445 | TAPAN_SLIM_CLOSE_TIMEOUT)); |
| 3446 | if (!ret) { |
| 3447 | pr_debug("%s: Slim close tx/rx wait timeout\n", |
| 3448 | __func__); |
| 3449 | ret = -ETIMEDOUT; |
| 3450 | } else { |
| 3451 | ret = 0; |
| 3452 | } |
| 3453 | } |
| 3454 | return ret; |
| 3455 | } |
| 3456 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3457 | static int tapan_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
| 3458 | struct snd_kcontrol *kcontrol, |
| 3459 | int event) |
| 3460 | { |
| 3461 | struct wcd9xxx *core; |
| 3462 | struct snd_soc_codec *codec = w->codec; |
| 3463 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3464 | int ret = 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3465 | struct wcd9xxx_codec_dai_data *dai; |
| 3466 | |
| 3467 | core = dev_get_drvdata(codec->dev->parent); |
| 3468 | |
| 3469 | dev_dbg(codec->dev, "%s: event called! codec name %s\n", |
| 3470 | __func__, w->codec->name); |
| 3471 | dev_dbg(codec->dev, "%s: num_dai %d stream name %s event %d\n", |
| 3472 | __func__, w->codec->num_dai, w->sname, event); |
| 3473 | |
| 3474 | /* Execute the callback only if interface type is slimbus */ |
| 3475 | if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 3476 | return 0; |
| 3477 | |
| 3478 | dai = &tapan_p->dai[w->shift]; |
| 3479 | dev_dbg(codec->dev, "%s: w->name %s w->shift %d event %d\n", |
| 3480 | __func__, w->name, w->shift, event); |
| 3481 | |
| 3482 | switch (event) { |
| 3483 | case SND_SOC_DAPM_POST_PMU: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3484 | (void) tapan_codec_enable_slim_chmask(dai, true); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3485 | ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list, |
| 3486 | dai->rate, dai->bit_width, |
| 3487 | &dai->grph); |
| 3488 | break; |
| 3489 | case SND_SOC_DAPM_POST_PMD: |
| 3490 | ret = wcd9xxx_close_slim_sch_rx(core, &dai->wcd9xxx_ch_list, |
| 3491 | dai->grph); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3492 | ret = tapan_codec_enable_slim_chmask(dai, false); |
| 3493 | if (ret < 0) { |
| 3494 | ret = wcd9xxx_disconnect_port(core, |
| 3495 | &dai->wcd9xxx_ch_list, |
| 3496 | dai->grph); |
| 3497 | dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n", |
| 3498 | __func__, ret); |
| 3499 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3500 | break; |
| 3501 | } |
| 3502 | return ret; |
| 3503 | } |
| 3504 | |
| 3505 | static int tapan_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
| 3506 | struct snd_kcontrol *kcontrol, |
| 3507 | int event) |
| 3508 | { |
| 3509 | struct wcd9xxx *core; |
| 3510 | struct snd_soc_codec *codec = w->codec; |
| 3511 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
| 3512 | u32 ret = 0; |
| 3513 | struct wcd9xxx_codec_dai_data *dai; |
| 3514 | |
| 3515 | core = dev_get_drvdata(codec->dev->parent); |
| 3516 | |
| 3517 | dev_dbg(codec->dev, "%s: event called! codec name %s\n", |
| 3518 | __func__, w->codec->name); |
| 3519 | dev_dbg(codec->dev, "%s: num_dai %d stream name %s\n", |
| 3520 | __func__, w->codec->num_dai, w->sname); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3521 | /* Execute the callback only if interface type is slimbus */ |
| 3522 | if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 3523 | return 0; |
| 3524 | |
| 3525 | dev_dbg(codec->dev, "%s(): w->name %s event %d w->shift %d\n", |
| 3526 | __func__, w->name, event, w->shift); |
| 3527 | |
| 3528 | dai = &tapan_p->dai[w->shift]; |
| 3529 | switch (event) { |
| 3530 | case SND_SOC_DAPM_POST_PMU: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3531 | (void) tapan_codec_enable_slim_chmask(dai, true); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3532 | ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 3533 | dai->rate, dai->bit_width, |
| 3534 | &dai->grph); |
| 3535 | break; |
| 3536 | case SND_SOC_DAPM_POST_PMD: |
| 3537 | ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 3538 | dai->grph); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3539 | ret = tapan_codec_enable_slim_chmask(dai, false); |
| 3540 | if (ret < 0) { |
| 3541 | ret = wcd9xxx_disconnect_port(core, |
| 3542 | &dai->wcd9xxx_ch_list, |
| 3543 | dai->grph); |
| 3544 | dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n", |
| 3545 | __func__, ret); |
| 3546 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3547 | break; |
| 3548 | } |
| 3549 | return ret; |
| 3550 | } |
| 3551 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3552 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3553 | static int tapan_codec_enable_ear_pa(struct snd_soc_dapm_widget *w, |
| 3554 | struct snd_kcontrol *kcontrol, int event) |
| 3555 | { |
| 3556 | struct snd_soc_codec *codec = w->codec; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3557 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3558 | |
| 3559 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 3560 | |
| 3561 | switch (event) { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3562 | case SND_SOC_DAPM_POST_PMU: |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3563 | wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d, |
| 3564 | WCD9XXX_CLSH_STATE_EAR, |
| 3565 | WCD9XXX_CLSH_REQ_ENABLE, |
| 3566 | WCD9XXX_CLSH_EVENT_POST_PA); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3567 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3568 | usleep_range(5000, 5010); |
| 3569 | break; |
| 3570 | case SND_SOC_DAPM_POST_PMD: |
| 3571 | wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d, |
| 3572 | WCD9XXX_CLSH_STATE_EAR, |
| 3573 | WCD9XXX_CLSH_REQ_DISABLE, |
| 3574 | WCD9XXX_CLSH_EVENT_POST_PA); |
| 3575 | usleep_range(5000, 5010); |
| 3576 | } |
| 3577 | return 0; |
| 3578 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3579 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3580 | static int tapan_codec_ear_dac_event(struct snd_soc_dapm_widget *w, |
| 3581 | struct snd_kcontrol *kcontrol, int event) |
| 3582 | { |
| 3583 | struct snd_soc_codec *codec = w->codec; |
| 3584 | struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec); |
| 3585 | |
| 3586 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 3587 | |
| 3588 | switch (event) { |
| 3589 | case SND_SOC_DAPM_PRE_PMU: |
| 3590 | wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d, |
| 3591 | WCD9XXX_CLSH_STATE_EAR, |
| 3592 | WCD9XXX_CLSH_REQ_ENABLE, |
| 3593 | WCD9XXX_CLSH_EVENT_PRE_DAC); |
| 3594 | break; |
| 3595 | } |
| 3596 | |
| 3597 | return 0; |
| 3598 | } |
| 3599 | |
| 3600 | static int tapan_codec_dsm_mux_event(struct snd_soc_dapm_widget *w, |
| 3601 | struct snd_kcontrol *kcontrol, int event) |
| 3602 | { |
| 3603 | struct snd_soc_codec *codec = w->codec; |
| 3604 | u8 reg_val, zoh_mux_val = 0x00; |
| 3605 | |
| 3606 | dev_dbg(codec->dev, "%s: event = %d\n", __func__, event); |
| 3607 | |
| 3608 | switch (event) { |
| 3609 | case SND_SOC_DAPM_POST_PMU: |
| 3610 | reg_val = snd_soc_read(codec, TAPAN_A_CDC_CONN_CLSH_CTL); |
| 3611 | |
| 3612 | if ((reg_val & 0x30) == 0x10) |
| 3613 | zoh_mux_val = 0x04; |
| 3614 | else if ((reg_val & 0x30) == 0x20) |
| 3615 | zoh_mux_val = 0x08; |
| 3616 | |
| 3617 | if (zoh_mux_val != 0x00) |
| 3618 | snd_soc_update_bits(codec, |
| 3619 | TAPAN_A_CDC_CONN_CLSH_CTL, |
| 3620 | 0x0C, zoh_mux_val); |
| 3621 | break; |
| 3622 | |
| 3623 | case SND_SOC_DAPM_POST_PMD: |
| 3624 | snd_soc_update_bits(codec, TAPAN_A_CDC_CONN_CLSH_CTL, |
| 3625 | 0x0C, 0x00); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3626 | break; |
| 3627 | } |
| 3628 | return 0; |
| 3629 | } |
| 3630 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 3631 | static int tapan_codec_enable_anc_ear(struct snd_soc_dapm_widget *w, |
| 3632 | struct snd_kcontrol *kcontrol, int event) |
| 3633 | { |
| 3634 | struct snd_soc_codec *codec = w->codec; |
| 3635 | int ret = 0; |
| 3636 | |
| 3637 | switch (event) { |
| 3638 | case SND_SOC_DAPM_PRE_PMU: |
| 3639 | ret = tapan_codec_enable_anc(w, kcontrol, event); |
| 3640 | msleep(50); |
| 3641 | snd_soc_update_bits(codec, TAPAN_A_RX_EAR_EN, 0x10, 0x10); |
| 3642 | break; |
| 3643 | case SND_SOC_DAPM_POST_PMU: |
| 3644 | ret = tapan_codec_enable_ear_pa(w, kcontrol, event); |
| 3645 | break; |
| 3646 | case SND_SOC_DAPM_PRE_PMD: |
| 3647 | snd_soc_update_bits(codec, TAPAN_A_RX_EAR_EN, 0x10, 0x00); |
| 3648 | msleep(40); |
| 3649 | ret |= tapan_codec_enable_anc(w, kcontrol, event); |
| 3650 | break; |
| 3651 | case SND_SOC_DAPM_POST_PMD: |
| 3652 | ret = tapan_codec_enable_ear_pa(w, kcontrol, event); |
| 3653 | break; |
| 3654 | } |
| 3655 | return ret; |
| 3656 | } |
| 3657 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3658 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3659 | /* Todo: Have seperate dapm widgets for I2S and Slimbus. |
| 3660 | * Might Need to have callbacks registered only for slimbus |
| 3661 | */ |
| 3662 | static const struct snd_soc_dapm_widget tapan_dapm_widgets[] = { |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3663 | |
| 3664 | SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM, |
| 3665 | AIF1_PB, 0, tapan_codec_enable_slimrx, |
| 3666 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3667 | SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM, |
| 3668 | AIF2_PB, 0, tapan_codec_enable_slimrx, |
| 3669 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3670 | SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM, |
| 3671 | AIF3_PB, 0, tapan_codec_enable_slimrx, |
| 3672 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3673 | |
| 3674 | SND_SOC_DAPM_MUX("SLIM RX1 MUX", SND_SOC_NOPM, TAPAN_RX1, 0, |
| 3675 | &slim_rx_mux[TAPAN_RX1]), |
| 3676 | SND_SOC_DAPM_MUX("SLIM RX2 MUX", SND_SOC_NOPM, TAPAN_RX2, 0, |
| 3677 | &slim_rx_mux[TAPAN_RX2]), |
| 3678 | SND_SOC_DAPM_MUX("SLIM RX3 MUX", SND_SOC_NOPM, TAPAN_RX3, 0, |
| 3679 | &slim_rx_mux[TAPAN_RX3]), |
| 3680 | SND_SOC_DAPM_MUX("SLIM RX4 MUX", SND_SOC_NOPM, TAPAN_RX4, 0, |
| 3681 | &slim_rx_mux[TAPAN_RX4]), |
| 3682 | SND_SOC_DAPM_MUX("SLIM RX5 MUX", SND_SOC_NOPM, TAPAN_RX5, 0, |
| 3683 | &slim_rx_mux[TAPAN_RX5]), |
| 3684 | |
| 3685 | SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 3686 | SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 3687 | SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 3688 | SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 3689 | SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 3690 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3691 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3692 | /* RX1 MIX1 mux inputs */ |
| 3693 | SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 3694 | &rx_mix1_inp1_mux), |
| 3695 | SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 3696 | &rx_mix1_inp2_mux), |
| 3697 | SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0, |
| 3698 | &rx_mix1_inp3_mux), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3699 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3700 | /* RX2 MIX1 mux inputs */ |
| 3701 | SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 3702 | &rx2_mix1_inp1_mux), |
| 3703 | SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 3704 | &rx2_mix1_inp2_mux), |
| 3705 | SND_SOC_DAPM_MUX("RX2 MIX1 INP3", SND_SOC_NOPM, 0, 0, |
| 3706 | &rx2_mix1_inp2_mux), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3707 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3708 | /* RX3 MIX1 mux inputs */ |
| 3709 | SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 3710 | &rx3_mix1_inp1_mux), |
| 3711 | SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 3712 | &rx3_mix1_inp2_mux), |
| 3713 | SND_SOC_DAPM_MUX("RX3 MIX1 INP3", SND_SOC_NOPM, 0, 0, |
| 3714 | &rx3_mix1_inp2_mux), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3715 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3716 | /* RX4 MIX1 mux inputs */ |
| 3717 | SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 3718 | &rx4_mix1_inp1_mux), |
| 3719 | SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 3720 | &rx4_mix1_inp2_mux), |
| 3721 | SND_SOC_DAPM_MUX("RX4 MIX1 INP3", SND_SOC_NOPM, 0, 0, |
| 3722 | &rx4_mix1_inp2_mux), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3723 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3724 | /* RX1 MIX2 mux inputs */ |
| 3725 | SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 3726 | &rx1_mix2_inp1_mux), |
| 3727 | SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 3728 | &rx1_mix2_inp2_mux), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3729 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3730 | /* RX2 MIX2 mux inputs */ |
| 3731 | SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 3732 | &rx2_mix2_inp1_mux), |
| 3733 | SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 3734 | &rx2_mix2_inp2_mux), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3735 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3736 | /* RX4 MIX2 mux inputs */ |
| 3737 | SND_SOC_DAPM_MUX("RX4 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 3738 | &rx4_mix2_inp1_mux), |
| 3739 | SND_SOC_DAPM_MUX("RX4 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 3740 | &rx4_mix2_inp2_mux), |
| 3741 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3742 | |
| 3743 | SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 3744 | SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3745 | SND_SOC_DAPM_MIXER("RX4 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3746 | |
| 3747 | SND_SOC_DAPM_MIXER_E("RX1 MIX2", TAPAN_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL, |
| 3748 | 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 3749 | SND_SOC_DAPM_POST_PMU), |
| 3750 | SND_SOC_DAPM_MIXER_E("RX2 MIX2", TAPAN_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL, |
| 3751 | 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 3752 | SND_SOC_DAPM_POST_PMU), |
| 3753 | SND_SOC_DAPM_MIXER_E("RX3 MIX1", TAPAN_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL, |
| 3754 | 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 3755 | SND_SOC_DAPM_POST_PMU), |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3756 | SND_SOC_DAPM_MIXER_E("RX4 MIX2", TAPAN_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3757 | 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 3758 | SND_SOC_DAPM_POST_PMU), |
| 3759 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3760 | SND_SOC_DAPM_MIXER("RX1 CHAIN", TAPAN_A_CDC_RX1_B6_CTL, 5, 0, |
| 3761 | NULL, 0), |
| 3762 | SND_SOC_DAPM_MIXER("RX2 CHAIN", TAPAN_A_CDC_RX2_B6_CTL, 5, 0, |
| 3763 | NULL, 0), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3764 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3765 | SND_SOC_DAPM_MUX_E("CLASS_H_DSM MUX", SND_SOC_NOPM, 0, 0, |
| 3766 | &class_h_dsm_mux, tapan_codec_dsm_mux_event, |
| 3767 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3768 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3769 | /* RX Bias */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3770 | SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0, |
| 3771 | tapan_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU | |
| 3772 | SND_SOC_DAPM_POST_PMD), |
| 3773 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3774 | /*EAR */ |
| 3775 | SND_SOC_DAPM_PGA_E("EAR PA", TAPAN_A_RX_EAR_EN, 4, 0, NULL, 0, |
| 3776 | tapan_codec_enable_ear_pa, SND_SOC_DAPM_POST_PMU | |
| 3777 | SND_SOC_DAPM_POST_PMD), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3778 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3779 | SND_SOC_DAPM_MIXER_E("DAC1", TAPAN_A_RX_EAR_EN, 6, 0, dac1_switch, |
| 3780 | ARRAY_SIZE(dac1_switch), tapan_codec_ear_dac_event, |
| 3781 | SND_SOC_DAPM_PRE_PMU), |
| 3782 | |
| 3783 | /* Headphone Left */ |
| 3784 | SND_SOC_DAPM_PGA_E("HPHL", TAPAN_A_RX_HPH_CNP_EN, 5, 0, NULL, 0, |
| 3785 | tapan_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 3786 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3787 | |
| 3788 | SND_SOC_DAPM_MIXER_E("HPHL DAC", TAPAN_A_RX_HPH_L_DAC_CTL, 7, 0, |
| 3789 | hphl_switch, ARRAY_SIZE(hphl_switch), tapan_hphl_dac_event, |
| 3790 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 3791 | |
| 3792 | /* Headphone Right */ |
| 3793 | SND_SOC_DAPM_PGA_E("HPHR", TAPAN_A_RX_HPH_CNP_EN, 4, 0, NULL, 0, |
| 3794 | tapan_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 3795 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3796 | |
| 3797 | SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TAPAN_A_RX_HPH_R_DAC_CTL, 7, 0, |
| 3798 | tapan_hphr_dac_event, |
| 3799 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 3800 | |
| 3801 | /* LINEOUT1*/ |
| 3802 | SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TAPAN_A_RX_LINE_1_DAC_CTL, 7, 0 |
| 3803 | , tapan_lineout_dac_event, |
| 3804 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 3805 | |
| 3806 | SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TAPAN_A_RX_LINE_CNP_EN, 0, 0, NULL, |
| 3807 | 0, tapan_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 3808 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3809 | |
| 3810 | /* LINEOUT2*/ |
| 3811 | SND_SOC_DAPM_MUX("RDAC5 MUX", SND_SOC_NOPM, 0, 0, |
| 3812 | &rx_dac5_mux), |
| 3813 | |
| 3814 | SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TAPAN_A_RX_LINE_2_DAC_CTL, 7, 0 |
| 3815 | , tapan_lineout_dac_event, |
| 3816 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 3817 | |
| 3818 | SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TAPAN_A_RX_LINE_CNP_EN, 1, 0, NULL, |
| 3819 | 0, tapan_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 3820 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3821 | |
| 3822 | /* CLASS-D SPK */ |
| 3823 | SND_SOC_DAPM_MIXER_E("SPK DAC", SND_SOC_NOPM, 0, 0, |
| 3824 | spk_dac_switch, ARRAY_SIZE(spk_dac_switch), tapan_spk_dac_event, |
| 3825 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 3826 | |
| 3827 | SND_SOC_DAPM_PGA_E("SPK PA", SND_SOC_NOPM, 0, 0 , NULL, |
| 3828 | 0, tapan_codec_enable_spk_pa, |
| 3829 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 3830 | |
| 3831 | SND_SOC_DAPM_SUPPLY("VDD_SPKDRV", SND_SOC_NOPM, 0, 0, |
| 3832 | tapan_codec_enable_vdd_spkr, |
| 3833 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 3834 | |
| 3835 | SND_SOC_DAPM_OUTPUT("EAR"), |
| 3836 | SND_SOC_DAPM_OUTPUT("HEADPHONE"), |
| 3837 | SND_SOC_DAPM_OUTPUT("LINEOUT1"), |
| 3838 | SND_SOC_DAPM_OUTPUT("LINEOUT2"), |
| 3839 | SND_SOC_DAPM_OUTPUT("SPK_OUT"), |
| 3840 | |
| 3841 | /* TX Path*/ |
| 3842 | SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0, |
| 3843 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 3844 | |
| 3845 | SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0, |
| 3846 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 3847 | |
| 3848 | SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0, |
| 3849 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 3850 | |
| 3851 | SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, TAPAN_TX1, 0, |
| 3852 | &sb_tx1_mux), |
| 3853 | SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, TAPAN_TX2, 0, |
| 3854 | &sb_tx2_mux), |
| 3855 | SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, TAPAN_TX3, 0, |
| 3856 | &sb_tx3_mux), |
| 3857 | SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, TAPAN_TX4, 0, |
| 3858 | &sb_tx4_mux), |
| 3859 | SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, TAPAN_TX5, 0, |
| 3860 | &sb_tx5_mux), |
| 3861 | |
| 3862 | 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] | 3863 | 0), |
| 3864 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3865 | /* Decimator MUX */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3866 | SND_SOC_DAPM_MUX_E("DEC1 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0, 0, |
| 3867 | &dec1_mux, tapan_codec_enable_dec, |
| 3868 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3869 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 3870 | |
| 3871 | SND_SOC_DAPM_MUX_E("DEC2 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 1, 0, |
| 3872 | &dec2_mux, tapan_codec_enable_dec, |
| 3873 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3874 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 3875 | |
| 3876 | SND_SOC_DAPM_MUX_E("DEC3 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 2, 0, |
| 3877 | &dec3_mux, tapan_codec_enable_dec, |
| 3878 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3879 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 3880 | |
| 3881 | SND_SOC_DAPM_MUX_E("DEC4 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 3, 0, |
| 3882 | &dec4_mux, tapan_codec_enable_dec, |
| 3883 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3884 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 3885 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3886 | SND_SOC_DAPM_SUPPLY("LDO_H", TAPAN_A_LDO_H_MODE_1, 7, 0, |
| 3887 | tapan_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU), |
| 3888 | |
| 3889 | SND_SOC_DAPM_SUPPLY("COMP0_CLK", SND_SOC_NOPM, 0, 0, |
| 3890 | tapan_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 3891 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 3892 | SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 1, 0, |
| 3893 | tapan_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 3894 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 3895 | SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 2, 0, |
| 3896 | tapan_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 3897 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 3898 | |
| 3899 | SND_SOC_DAPM_INPUT("AMIC1"), |
| 3900 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", TAPAN_A_MICB_1_CTL, 7, 0, |
| 3901 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 3902 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3903 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", TAPAN_A_MICB_1_CTL, 7, 0, |
| 3904 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 3905 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3906 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", TAPAN_A_MICB_1_CTL, 7, 0, |
| 3907 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 3908 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3909 | |
| 3910 | SND_SOC_DAPM_ADC_E("ADC1", NULL, TAPAN_A_TX_1_EN, 7, 0, |
| 3911 | tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 3912 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3913 | SND_SOC_DAPM_ADC_E("ADC2", NULL, TAPAN_A_TX_2_EN, 7, 0, |
| 3914 | tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 3915 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3916 | |
| 3917 | SND_SOC_DAPM_INPUT("AMIC3"), |
| 3918 | SND_SOC_DAPM_ADC_E("ADC3", NULL, TAPAN_A_TX_3_EN, 7, 0, |
| 3919 | tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 3920 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3921 | |
| 3922 | SND_SOC_DAPM_INPUT("AMIC4"), |
| 3923 | SND_SOC_DAPM_ADC_E("ADC4", NULL, TAPAN_A_TX_4_EN, 7, 0, |
| 3924 | tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 3925 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3926 | |
| 3927 | SND_SOC_DAPM_INPUT("AMIC5"), |
| 3928 | SND_SOC_DAPM_ADC_E("ADC5", NULL, TAPAN_A_TX_5_EN, 7, 0, |
| 3929 | tapan_codec_enable_adc, SND_SOC_DAPM_POST_PMU), |
| 3930 | |
| 3931 | SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux), |
| 3932 | SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux), |
| 3933 | |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 3934 | SND_SOC_DAPM_OUTPUT("ANC HEADPHONE"), |
| 3935 | SND_SOC_DAPM_PGA_E("ANC HPHL", SND_SOC_NOPM, 5, 0, NULL, 0, |
| 3936 | tapan_codec_enable_anc_hph, |
| 3937 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD | |
| 3938 | SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_POST_PMU), |
| 3939 | SND_SOC_DAPM_PGA_E("ANC HPHR", SND_SOC_NOPM, 4, 0, NULL, 0, |
| 3940 | tapan_codec_enable_anc_hph, SND_SOC_DAPM_PRE_PMU | |
| 3941 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD | |
| 3942 | SND_SOC_DAPM_POST_PMU), |
| 3943 | SND_SOC_DAPM_OUTPUT("ANC EAR"), |
| 3944 | SND_SOC_DAPM_PGA_E("ANC EAR PA", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 3945 | tapan_codec_enable_anc_ear, |
| 3946 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD | |
| 3947 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3948 | SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3949 | |
| 3950 | SND_SOC_DAPM_INPUT("AMIC2"), |
| 3951 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", TAPAN_A_MICB_2_CTL, 7, 0, |
| 3952 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 3953 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3954 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", TAPAN_A_MICB_2_CTL, 7, 0, |
| 3955 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 3956 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3957 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", TAPAN_A_MICB_2_CTL, 7, 0, |
| 3958 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 3959 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3960 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", TAPAN_A_MICB_2_CTL, 7, 0, |
| 3961 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 3962 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3963 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", TAPAN_A_MICB_3_CTL, 7, 0, |
| 3964 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 3965 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3966 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", TAPAN_A_MICB_3_CTL, 7, 0, |
| 3967 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 3968 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3969 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", TAPAN_A_MICB_3_CTL, 7, 0, |
| 3970 | tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 3971 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3972 | |
| 3973 | SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM, |
| 3974 | AIF1_CAP, 0, tapan_codec_enable_slimtx, |
| 3975 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3976 | |
| 3977 | SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM, |
| 3978 | AIF2_CAP, 0, tapan_codec_enable_slimtx, |
| 3979 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3980 | |
| 3981 | SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM, |
| 3982 | AIF3_CAP, 0, tapan_codec_enable_slimtx, |
| 3983 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 3984 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 3985 | /* Digital Mic Inputs */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 3986 | SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0, |
| 3987 | tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 3988 | SND_SOC_DAPM_POST_PMD), |
| 3989 | |
| 3990 | SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0, |
| 3991 | tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 3992 | SND_SOC_DAPM_POST_PMD), |
| 3993 | |
| 3994 | SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0, |
| 3995 | tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 3996 | SND_SOC_DAPM_POST_PMD), |
| 3997 | |
| 3998 | SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0, |
| 3999 | tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4000 | SND_SOC_DAPM_POST_PMD), |
| 4001 | |
| 4002 | /* Sidetone */ |
| 4003 | SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux), |
| 4004 | SND_SOC_DAPM_PGA("IIR1", TAPAN_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0), |
| 4005 | |
| 4006 | /* AUX PGA */ |
| 4007 | SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TAPAN_A_RX_AUX_SW_CTL, 7, 0, |
| 4008 | tapan_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 4009 | SND_SOC_DAPM_POST_PMD), |
| 4010 | |
| 4011 | SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TAPAN_A_RX_AUX_SW_CTL, 6, 0, |
| 4012 | tapan_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 4013 | SND_SOC_DAPM_POST_PMD), |
| 4014 | |
| 4015 | /* Lineout, ear and HPH PA Mixers */ |
| 4016 | |
| 4017 | SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4018 | ear_pa_mix, ARRAY_SIZE(ear_pa_mix)), |
| 4019 | |
| 4020 | SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4021 | hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)), |
| 4022 | |
| 4023 | SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4024 | hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)), |
| 4025 | |
| 4026 | SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4027 | lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)), |
| 4028 | |
| 4029 | SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4030 | lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4031 | }; |
| 4032 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4033 | static irqreturn_t tapan_slimbus_irq(int irq, void *data) |
| 4034 | { |
| 4035 | struct tapan_priv *priv = data; |
| 4036 | struct snd_soc_codec *codec = priv->codec; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4037 | unsigned long status = 0; |
| 4038 | int i, j, port_id, k; |
| 4039 | u32 bit; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4040 | u8 val; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4041 | bool tx, cleared; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4042 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4043 | for (i = TAPAN_SLIM_PGD_PORT_INT_STATUS_RX_0, j = 0; |
| 4044 | i <= TAPAN_SLIM_PGD_PORT_INT_STATUS_TX_1; i++, j++) { |
| 4045 | val = wcd9xxx_interface_reg_read(codec->control_data, i); |
| 4046 | status |= ((u32)val << (8 * j)); |
| 4047 | } |
| 4048 | |
| 4049 | for_each_set_bit(j, &status, 32) { |
| 4050 | tx = (j >= 16 ? true : false); |
| 4051 | port_id = (tx ? j - 16 : j); |
| 4052 | val = wcd9xxx_interface_reg_read(codec->control_data, |
| 4053 | TAPAN_SLIM_PGD_PORT_INT_RX_SOURCE0 + j); |
| 4054 | if (val & TAPAN_SLIM_IRQ_OVERFLOW) |
| 4055 | pr_err_ratelimited( |
| 4056 | "%s: overflow error on %s port %d, value %x\n", |
| 4057 | __func__, (tx ? "TX" : "RX"), port_id, val); |
| 4058 | if (val & TAPAN_SLIM_IRQ_UNDERFLOW) |
| 4059 | pr_err_ratelimited( |
| 4060 | "%s: underflow error on %s port %d, value %x\n", |
| 4061 | __func__, (tx ? "TX" : "RX"), port_id, val); |
| 4062 | if (val & TAPAN_SLIM_IRQ_PORT_CLOSED) { |
| 4063 | /* |
| 4064 | * INT SOURCE register starts from RX to TX |
| 4065 | * but port number in the ch_mask is in opposite way |
| 4066 | */ |
| 4067 | bit = (tx ? j - 16 : j + 16); |
| 4068 | dev_dbg(codec->dev, "%s: %s port %d closed value %x, bit %u\n", |
| 4069 | __func__, (tx ? "TX" : "RX"), port_id, val, |
| 4070 | bit); |
| 4071 | for (k = 0, cleared = false; k < NUM_CODEC_DAIS; k++) { |
| 4072 | dev_dbg(codec->dev, "%s: priv->dai[%d].ch_mask = 0x%lx\n", |
| 4073 | __func__, k, priv->dai[k].ch_mask); |
| 4074 | if (test_and_clear_bit(bit, |
| 4075 | &priv->dai[k].ch_mask)) { |
| 4076 | cleared = true; |
| 4077 | if (!priv->dai[k].ch_mask) |
| 4078 | wake_up(&priv->dai[k].dai_wait); |
| 4079 | /* |
| 4080 | * There are cases when multiple DAIs |
| 4081 | * might be using the same slimbus |
| 4082 | * channel. Hence don't break here. |
| 4083 | */ |
| 4084 | } |
| 4085 | } |
| 4086 | WARN(!cleared, |
| 4087 | "Couldn't find slimbus %s port %d for closing\n", |
| 4088 | (tx ? "TX" : "RX"), port_id); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4089 | } |
| 4090 | wcd9xxx_interface_reg_write(codec->control_data, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4091 | TAPAN_SLIM_PGD_PORT_INT_CLR_RX_0 + |
| 4092 | (j / 8), |
| 4093 | 1 << (j % 8)); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4094 | } |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4095 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4096 | return IRQ_HANDLED; |
| 4097 | } |
| 4098 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4099 | static int tapan_handle_pdata(struct tapan_priv *tapan) |
| 4100 | { |
| 4101 | struct snd_soc_codec *codec = tapan->codec; |
| 4102 | struct wcd9xxx_pdata *pdata = tapan->resmgr.pdata; |
| 4103 | int k1, k2, k3, rc = 0; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4104 | u8 txfe_bypass = pdata->amic_settings.txfe_enable; |
| 4105 | u8 txfe_buff = pdata->amic_settings.txfe_buff; |
| 4106 | u8 flag = pdata->amic_settings.use_pdata; |
| 4107 | u8 i = 0, j = 0; |
| 4108 | u8 val_txfe = 0, value = 0; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4109 | |
| 4110 | if (!pdata) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4111 | dev_err(codec->dev, "%s: NULL pdata\n", __func__); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4112 | rc = -ENODEV; |
| 4113 | goto done; |
| 4114 | } |
| 4115 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4116 | /* Make sure settings are correct */ |
| 4117 | if ((pdata->micbias.ldoh_v > WCD9XXX_LDOH_3P0_V) || |
| 4118 | (pdata->micbias.bias1_cfilt_sel > WCD9XXX_CFILT3_SEL) || |
| 4119 | (pdata->micbias.bias2_cfilt_sel > WCD9XXX_CFILT3_SEL) || |
| 4120 | (pdata->micbias.bias3_cfilt_sel > WCD9XXX_CFILT3_SEL)) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4121 | dev_err(codec->dev, "%s: Invalid ldoh voltage or bias cfilt\n", |
| 4122 | __func__); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4123 | rc = -EINVAL; |
| 4124 | goto done; |
| 4125 | } |
| 4126 | /* figure out k value */ |
| 4127 | k1 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt1_mv); |
| 4128 | k2 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt2_mv); |
| 4129 | k3 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt3_mv); |
| 4130 | |
| 4131 | 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] | 4132 | dev_err(codec->dev, |
| 4133 | "%s: could not get K value. k1 = %d k2 = %d k3 = %d\n", |
| 4134 | __func__, k1, k2, k3); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4135 | rc = -EINVAL; |
| 4136 | goto done; |
| 4137 | } |
| 4138 | /* Set voltage level and always use LDO */ |
| 4139 | snd_soc_update_bits(codec, TAPAN_A_LDO_H_MODE_1, 0x0C, |
| 4140 | (pdata->micbias.ldoh_v << 2)); |
| 4141 | |
| 4142 | snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_1_VAL, 0xFC, (k1 << 2)); |
| 4143 | snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_2_VAL, 0xFC, (k2 << 2)); |
| 4144 | snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_3_VAL, 0xFC, (k3 << 2)); |
| 4145 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4146 | i = 0; |
| 4147 | while (i < 5) { |
| 4148 | if (flag & (0x01 << i)) { |
| 4149 | val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00; |
| 4150 | val_txfe = val_txfe | |
| 4151 | ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00); |
| 4152 | snd_soc_update_bits(codec, |
| 4153 | TAPAN_A_TX_1_2_TEST_EN + j * 10, |
| 4154 | 0x30, val_txfe); |
| 4155 | } |
| 4156 | if (flag & (0x01 << (i + 1))) { |
| 4157 | val_txfe = (txfe_bypass & |
| 4158 | (0x01 << (i + 1))) ? 0x02 : 0x00; |
| 4159 | val_txfe |= (txfe_buff & |
| 4160 | (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 4161 | snd_soc_update_bits(codec, |
| 4162 | TAPAN_A_TX_1_2_TEST_EN + j * 10, |
| 4163 | 0x03, val_txfe); |
| 4164 | } |
| 4165 | /* Tapan only has TAPAN_A_TX_1_2_TEST_EN and |
| 4166 | TAPAN_A_TX_4_5_TEST_EN reg */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4167 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4168 | if (i == 0) { |
| 4169 | i = 3; |
| 4170 | continue; |
| 4171 | } else if (i == 3) { |
| 4172 | break; |
| 4173 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | if (pdata->ocp.use_pdata) { |
| 4177 | /* not defined in CODEC specification */ |
| 4178 | if (pdata->ocp.hph_ocp_limit == 1 || |
| 4179 | pdata->ocp.hph_ocp_limit == 5) { |
| 4180 | rc = -EINVAL; |
| 4181 | goto done; |
| 4182 | } |
| 4183 | snd_soc_update_bits(codec, TAPAN_A_RX_COM_OCP_CTL, |
| 4184 | 0x0F, pdata->ocp.num_attempts); |
| 4185 | snd_soc_write(codec, TAPAN_A_RX_COM_OCP_COUNT, |
| 4186 | ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time)); |
| 4187 | snd_soc_update_bits(codec, TAPAN_A_RX_HPH_OCP_CTL, |
| 4188 | 0xE0, (pdata->ocp.hph_ocp_limit << 5)); |
| 4189 | } |
| 4190 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4191 | /* Set micbias capless mode with tail current */ |
| 4192 | value = (pdata->micbias.bias1_cap_mode == MICBIAS_EXT_BYP_CAP ? |
| 4193 | 0x00 : 0x10); |
| 4194 | snd_soc_update_bits(codec, TAPAN_A_MICB_1_CTL, 0x10, value); |
| 4195 | value = (pdata->micbias.bias2_cap_mode == MICBIAS_EXT_BYP_CAP ? |
| 4196 | 0x00 : 0x10); |
| 4197 | snd_soc_update_bits(codec, TAPAN_A_MICB_2_CTL, 0x10, value); |
| 4198 | value = (pdata->micbias.bias3_cap_mode == MICBIAS_EXT_BYP_CAP ? |
| 4199 | 0x00 : 0x10); |
| 4200 | snd_soc_update_bits(codec, TAPAN_A_MICB_3_CTL, 0x10, value); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4201 | |
| 4202 | done: |
| 4203 | return rc; |
| 4204 | } |
| 4205 | |
| 4206 | static const struct tapan_reg_mask_val tapan_reg_defaults[] = { |
| 4207 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4208 | /* enable QFUSE for wcd9306 */ |
| 4209 | TAPAN_REG_VAL(TAPAN_A_QFUSE_CTL, 0x03), |
| 4210 | |
| 4211 | /* PROGRAM_THE_0P85V_VBG_REFERENCE = V_0P858V */ |
| 4212 | TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x04), |
| 4213 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4214 | TAPAN_REG_VAL(TAPAN_A_CDC_CLK_POWER_CTL, 0x03), |
| 4215 | |
| 4216 | /* EAR PA deafults */ |
| 4217 | TAPAN_REG_VAL(TAPAN_A_RX_EAR_CMBUFF, 0x05), |
| 4218 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4219 | /* RX1 and RX2 defaults */ |
| 4220 | TAPAN_REG_VAL(TAPAN_A_CDC_RX1_B6_CTL, 0xA0), |
| 4221 | TAPAN_REG_VAL(TAPAN_A_CDC_RX2_B6_CTL, 0xA0), |
| 4222 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4223 | /* Heaset set Right from RX2 */ |
| 4224 | TAPAN_REG_VAL(TAPAN_A_CDC_CONN_RX2_B2_CTL, 0x10), |
| 4225 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4226 | |
| 4227 | /* |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4228 | * The following only need to be written for Tapan 1.0 parts. |
| 4229 | * Tapan 2.0 will have appropriate defaults for these registers. |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4230 | */ |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4231 | |
| 4232 | /* Required defaults for class H operation */ |
| 4233 | /* borrowed from Taiko class-h */ |
| 4234 | TAPAN_REG_VAL(TAPAN_A_RX_HPH_CHOP_CTL, 0xF4), |
| 4235 | TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x08), |
| 4236 | TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_1, 0x5B), |
| 4237 | TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_3, 0x60), |
| 4238 | |
| 4239 | /* TODO: Check below reg writes conflict with above */ |
| 4240 | /* PROGRAM_THE_0P85V_VBG_REFERENCE = V_0P858V */ |
| 4241 | TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x04), |
| 4242 | TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_4, 0x54), |
| 4243 | TAPAN_REG_VAL(TAPAN_A_RX_HPH_CHOP_CTL, 0x74), |
| 4244 | TAPAN_REG_VAL(TAPAN_A_RX_BUCK_BIAS1, 0x62), |
| 4245 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4246 | /* Choose max non-overlap time for NCP */ |
| 4247 | TAPAN_REG_VAL(TAPAN_A_NCP_CLK, 0xFC), |
| 4248 | /* Use 25mV/50mV for deltap/m to reduce ripple */ |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4249 | TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_VCL_1, 0x08), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4250 | /* |
| 4251 | * Set DISABLE_MODE_SEL<1:0> to 0b10 (disable PWM in auto mode). |
| 4252 | * Note that the other bits of this register will be changed during |
| 4253 | * Rx PA bring up. |
| 4254 | */ |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4255 | TAPAN_REG_VAL(WCD9XXX_A_BUCK_MODE_3, 0xCE), |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4256 | /* Reduce HPH DAC bias to 70% */ |
| 4257 | TAPAN_REG_VAL(TAPAN_A_RX_HPH_BIAS_PA, 0x7A), |
| 4258 | /*Reduce EAR DAC bias to 70% */ |
| 4259 | TAPAN_REG_VAL(TAPAN_A_RX_EAR_BIAS_PA, 0x76), |
| 4260 | /* Reduce LINE DAC bias to 70% */ |
| 4261 | TAPAN_REG_VAL(TAPAN_A_RX_LINE_BIAS_PA, 0x78), |
| 4262 | |
| 4263 | /* |
| 4264 | * There is a diode to pull down the micbias while doing |
| 4265 | * insertion detection. This diode can cause leakage. |
| 4266 | * Set bit 0 to 1 to prevent leakage. |
| 4267 | * Setting this bit of micbias 2 prevents leakage for all other micbias. |
| 4268 | */ |
| 4269 | TAPAN_REG_VAL(TAPAN_A_MICB_2_MBHC, 0x41), |
| 4270 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4271 | }; |
| 4272 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4273 | static const struct tapan_reg_mask_val tapan_2_x_reg_reset_values[] = { |
| 4274 | |
| 4275 | TAPAN_REG_VAL(TAPAN_A_TX_7_MBHC_EN, 0x6C), |
| 4276 | TAPAN_REG_VAL(TAPAN_A_BUCK_CTRL_CCL_4, 0x51), |
| 4277 | TAPAN_REG_VAL(TAPAN_A_RX_HPH_CNP_WG_CTL, 0xDA), |
| 4278 | TAPAN_REG_VAL(TAPAN_A_RX_EAR_CNP, 0xC0), |
| 4279 | TAPAN_REG_VAL(TAPAN_A_RX_LINE_1_TEST, 0x02), |
| 4280 | TAPAN_REG_VAL(TAPAN_A_RX_LINE_2_TEST, 0x02), |
| 4281 | TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_OCP_CTL, 0x97), |
| 4282 | TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_CLIP_DET, 0x01), |
| 4283 | TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_IEC, 0x00), |
| 4284 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B1_CTL, 0xE4), |
| 4285 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B2_CTL, 0x00), |
| 4286 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B3_CTL, 0x00), |
| 4287 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_BUCK_NCP_VARS, 0x00), |
| 4288 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_HD_EAR, 0x00), |
| 4289 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_HD_HPH, 0x00), |
| 4290 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_MIN_EAR, 0x00), |
| 4291 | TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_MIN_HPH, 0x00), |
| 4292 | }; |
| 4293 | |
| 4294 | static const struct tapan_reg_mask_val tapan_1_0_reg_defaults[] = { |
| 4295 | /* Close leakage on the spkdrv */ |
| 4296 | TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_DBG_PWRSTG, 0x24), |
| 4297 | TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_DBG_DAC, 0xE5), |
| 4298 | |
| 4299 | }; |
| 4300 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4301 | static void tapan_update_reg_defaults(struct snd_soc_codec *codec) |
| 4302 | { |
| 4303 | u32 i; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4304 | struct wcd9xxx *tapan_core = dev_get_drvdata(codec->dev->parent); |
| 4305 | |
| 4306 | if (!TAPAN_IS_1_0(tapan_core->version)) { |
| 4307 | for (i = 0; i < ARRAY_SIZE(tapan_2_x_reg_reset_values); i++) |
| 4308 | snd_soc_write(codec, tapan_2_x_reg_reset_values[i].reg, |
| 4309 | tapan_2_x_reg_reset_values[i].val); |
| 4310 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4311 | |
| 4312 | for (i = 0; i < ARRAY_SIZE(tapan_reg_defaults); i++) |
| 4313 | snd_soc_write(codec, tapan_reg_defaults[i].reg, |
| 4314 | tapan_reg_defaults[i].val); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4315 | |
| 4316 | if (TAPAN_IS_1_0(tapan_core->version)) { |
| 4317 | for (i = 0; i < ARRAY_SIZE(tapan_1_0_reg_defaults); i++) |
| 4318 | snd_soc_write(codec, tapan_1_0_reg_defaults[i].reg, |
| 4319 | tapan_1_0_reg_defaults[i].val); |
| 4320 | } |
| 4321 | |
| 4322 | if (!TAPAN_IS_1_0(tapan_core->version)) |
| 4323 | spkr_drv_wrnd = -1; |
| 4324 | else if (spkr_drv_wrnd == 1) |
| 4325 | snd_soc_write(codec, TAPAN_A_SPKR_DRV_EN, 0xEF); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4326 | } |
| 4327 | |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame^] | 4328 | static void tapan_update_reg_mclk_rate(struct wcd9xxx *wcd9xxx) |
| 4329 | { |
| 4330 | struct snd_soc_codec *codec; |
| 4331 | |
| 4332 | codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv); |
| 4333 | dev_dbg(codec->dev, "%s: MCLK Rate = %x\n", |
| 4334 | __func__, wcd9xxx->mclk_rate); |
| 4335 | |
| 4336 | if (wcd9xxx->mclk_rate == TAPAN_MCLK_CLK_12P288MHZ) { |
| 4337 | snd_soc_update_bits(codec, TAPAN_A_CHIP_CTL, 0x06, 0x0); |
| 4338 | snd_soc_update_bits(codec, TAPAN_A_RX_COM_TIMER_DIV, 0x01, |
| 4339 | 0x01); |
| 4340 | } else if (wcd9xxx->mclk_rate == TAPAN_MCLK_CLK_9P6MHZ) { |
| 4341 | snd_soc_update_bits(codec, TAPAN_A_CHIP_CTL, 0x06, 0x2); |
| 4342 | } |
| 4343 | } |
| 4344 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4345 | static const struct tapan_reg_mask_val tapan_codec_reg_init_val[] = { |
| 4346 | /* Initialize current threshold to 350MA |
| 4347 | * number of wait and run cycles to 4096 |
| 4348 | */ |
| 4349 | {TAPAN_A_RX_HPH_OCP_CTL, 0xE1, 0x61}, |
| 4350 | {TAPAN_A_RX_COM_OCP_COUNT, 0xFF, 0xFF}, |
| 4351 | |
| 4352 | /* Initialize gain registers to use register gain */ |
| 4353 | {TAPAN_A_RX_HPH_L_GAIN, 0x20, 0x20}, |
| 4354 | {TAPAN_A_RX_HPH_R_GAIN, 0x20, 0x20}, |
| 4355 | {TAPAN_A_RX_LINE_1_GAIN, 0x20, 0x20}, |
| 4356 | {TAPAN_A_RX_LINE_2_GAIN, 0x20, 0x20}, |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4357 | {TAPAN_A_SPKR_DRV_GAIN, 0x04, 0x04}, |
| 4358 | |
| 4359 | /* Set RDAC5 MUX to take input from DEM3_INV. |
| 4360 | * This sets LO2 DAC to get input from DEM3_INV |
| 4361 | * for LO1 and LO2 to work as differential outputs. |
| 4362 | */ |
| 4363 | {TAPAN_A_CDC_CONN_MISC, 0x04, 0x04}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4364 | |
| 4365 | /* CLASS H config */ |
| 4366 | {TAPAN_A_CDC_CONN_CLSH_CTL, 0x3C, 0x14}, |
| 4367 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4368 | /* Use 16 bit sample size for TX1 to TX5 */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4369 | {TAPAN_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20}, |
| 4370 | {TAPAN_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20}, |
| 4371 | {TAPAN_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20}, |
| 4372 | {TAPAN_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20}, |
| 4373 | {TAPAN_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20}, |
| 4374 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4375 | /* Disable SPK SWITCH */ |
| 4376 | {TAPAN_A_SPKR_DRV_DAC_CTL, 0x04, 0x00}, |
| 4377 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4378 | /* Use 16 bit sample size for RX */ |
| 4379 | {TAPAN_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA}, |
| 4380 | {TAPAN_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0x2A}, |
| 4381 | |
| 4382 | /*enable HPF filter for TX paths */ |
| 4383 | {TAPAN_A_CDC_TX1_MUX_CTL, 0x8, 0x0}, |
| 4384 | {TAPAN_A_CDC_TX2_MUX_CTL, 0x8, 0x0}, |
| 4385 | {TAPAN_A_CDC_TX3_MUX_CTL, 0x8, 0x0}, |
| 4386 | {TAPAN_A_CDC_TX4_MUX_CTL, 0x8, 0x0}, |
| 4387 | |
| 4388 | /* config Decimator for DMIC CLK_MODE_1(3.2Mhz@9.6Mhz mclk) */ |
| 4389 | {TAPAN_A_CDC_TX1_DMIC_CTL, 0x7, 0x1}, |
| 4390 | {TAPAN_A_CDC_TX2_DMIC_CTL, 0x7, 0x1}, |
| 4391 | {TAPAN_A_CDC_TX3_DMIC_CTL, 0x7, 0x1}, |
| 4392 | {TAPAN_A_CDC_TX4_DMIC_CTL, 0x7, 0x1}, |
| 4393 | |
| 4394 | /* config DMIC clk to CLK_MODE_1 (3.2Mhz@9.6Mhz mclk) */ |
| 4395 | {TAPAN_A_CDC_CLK_DMIC_B1_CTL, 0xEE, 0x22}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4396 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4397 | /* Compander zone selection */ |
| 4398 | {TAPAN_A_CDC_COMP0_B4_CTL, 0x3F, 0x37}, |
| 4399 | {TAPAN_A_CDC_COMP1_B4_CTL, 0x3F, 0x37}, |
| 4400 | {TAPAN_A_CDC_COMP2_B4_CTL, 0x3F, 0x37}, |
| 4401 | {TAPAN_A_CDC_COMP0_B5_CTL, 0x7F, 0x7F}, |
| 4402 | {TAPAN_A_CDC_COMP1_B5_CTL, 0x7F, 0x7F}, |
| 4403 | {TAPAN_A_CDC_COMP2_B5_CTL, 0x7F, 0x7F}, |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4404 | }; |
| 4405 | |
| 4406 | static void tapan_codec_init_reg(struct snd_soc_codec *codec) |
| 4407 | { |
| 4408 | u32 i; |
| 4409 | |
| 4410 | for (i = 0; i < ARRAY_SIZE(tapan_codec_reg_init_val); i++) |
| 4411 | snd_soc_update_bits(codec, tapan_codec_reg_init_val[i].reg, |
| 4412 | tapan_codec_reg_init_val[i].mask, |
| 4413 | tapan_codec_reg_init_val[i].val); |
| 4414 | } |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame^] | 4415 | static void tapan_slim_interface_init_reg(struct snd_soc_codec *codec) |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4416 | { |
| 4417 | int i; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4418 | |
| 4419 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) |
| 4420 | wcd9xxx_interface_reg_write(codec->control_data, |
| 4421 | TAPAN_SLIM_PGD_PORT_INT_EN0 + i, |
| 4422 | 0xFF); |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame^] | 4423 | } |
| 4424 | |
| 4425 | static int tapan_setup_irqs(struct tapan_priv *tapan) |
| 4426 | { |
| 4427 | int ret = 0; |
| 4428 | struct snd_soc_codec *codec = tapan->codec; |
| 4429 | |
| 4430 | ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, |
| 4431 | tapan_slimbus_irq, "SLIMBUS Slave", tapan); |
| 4432 | if (ret) |
| 4433 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 4434 | WCD9XXX_IRQ_SLIMBUS); |
| 4435 | else |
| 4436 | tapan_slim_interface_init_reg(codec); |
| 4437 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4438 | return ret; |
| 4439 | } |
| 4440 | |
Ravishankar Sarawadi | 7b70036 | 2013-04-18 15:56:02 -0700 | [diff] [blame] | 4441 | static void tapan_cleanup_irqs(struct tapan_priv *tapan) |
| 4442 | { |
| 4443 | struct snd_soc_codec *codec = tapan->codec; |
| 4444 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, tapan); |
| 4445 | } |
| 4446 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4447 | int tapan_hs_detect(struct snd_soc_codec *codec, |
| 4448 | struct wcd9xxx_mbhc_config *mbhc_cfg) |
| 4449 | { |
| 4450 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 4451 | return wcd9xxx_mbhc_start(&tapan->mbhc, mbhc_cfg); |
| 4452 | } |
| 4453 | EXPORT_SYMBOL_GPL(tapan_hs_detect); |
| 4454 | |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame^] | 4455 | static int tapan_post_reset_cb(struct wcd9xxx *wcd9xxx) |
| 4456 | { |
| 4457 | int ret = 0; |
| 4458 | int rco_clk_rate; |
| 4459 | struct snd_soc_codec *codec; |
| 4460 | struct tapan_priv *tapan; |
| 4461 | |
| 4462 | codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv); |
| 4463 | tapan = snd_soc_codec_get_drvdata(codec); |
| 4464 | mutex_lock(&codec->mutex); |
| 4465 | WCD9XXX_BCL_LOCK(&tapan->resmgr); |
| 4466 | |
| 4467 | if (codec->reg_def_copy) { |
| 4468 | pr_debug("%s: Update ASOC cache", __func__); |
| 4469 | kfree(codec->reg_cache); |
| 4470 | codec->reg_cache = kmemdup(codec->reg_def_copy, |
| 4471 | codec->reg_size, GFP_KERNEL); |
| 4472 | if (!codec->reg_cache) { |
| 4473 | pr_err("%s: Cache update failed!\n", __func__); |
| 4474 | WCD9XXX_BCL_UNLOCK(&tapan->resmgr); |
| 4475 | mutex_unlock(&codec->mutex); |
| 4476 | return -ENOMEM; |
| 4477 | } |
| 4478 | } |
| 4479 | |
| 4480 | wcd9xxx_resmgr_post_ssr(&tapan->resmgr); |
| 4481 | if (spkr_drv_wrnd == 1) |
| 4482 | snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80); |
| 4483 | WCD9XXX_BCL_UNLOCK(&tapan->resmgr); |
| 4484 | |
| 4485 | tapan_update_reg_defaults(codec); |
| 4486 | tapan_update_reg_mclk_rate(wcd9xxx); |
| 4487 | tapan_codec_init_reg(codec); |
| 4488 | ret = tapan_handle_pdata(tapan); |
| 4489 | if (IS_ERR_VALUE(ret)) |
| 4490 | pr_err("%s: bad pdata\n", __func__); |
| 4491 | |
| 4492 | tapan_slim_interface_init_reg(codec); |
| 4493 | |
| 4494 | wcd9xxx_mbhc_deinit(&tapan->mbhc); |
| 4495 | |
| 4496 | if (TAPAN_IS_1_0(wcd9xxx->version)) |
| 4497 | rco_clk_rate = TAPAN_MCLK_CLK_12P288MHZ; |
| 4498 | else |
| 4499 | rco_clk_rate = TAPAN_MCLK_CLK_9P6MHZ; |
| 4500 | |
| 4501 | ret = wcd9xxx_mbhc_init(&tapan->mbhc, &tapan->resmgr, codec, NULL, |
| 4502 | WCD9XXX_MBHC_VERSION_TAPAN, |
| 4503 | rco_clk_rate); |
| 4504 | if (ret) |
| 4505 | pr_err("%s: mbhc init failed %d\n", __func__, ret); |
| 4506 | else |
| 4507 | wcd9xxx_mbhc_start(&tapan->mbhc, tapan->mbhc.mbhc_cfg); |
| 4508 | mutex_unlock(&codec->mutex); |
| 4509 | return ret; |
| 4510 | } |
| 4511 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4512 | static struct wcd9xxx_reg_address tapan_reg_address = { |
| 4513 | }; |
| 4514 | |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame^] | 4515 | static int wcd9xxx_ssr_register(struct wcd9xxx *control, |
| 4516 | int (*post_reset_cb)(struct wcd9xxx *wcd9xxx), void *priv) |
| 4517 | { |
| 4518 | control->post_reset = post_reset_cb; |
| 4519 | control->ssr_priv = priv; |
| 4520 | return 0; |
| 4521 | } |
| 4522 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4523 | static int tapan_codec_probe(struct snd_soc_codec *codec) |
| 4524 | { |
| 4525 | struct wcd9xxx *control; |
| 4526 | struct tapan_priv *tapan; |
| 4527 | struct wcd9xxx_pdata *pdata; |
| 4528 | struct wcd9xxx *wcd9xxx; |
| 4529 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 4530 | int ret = 0; |
Phani Kumar Uppalapati | 43bc415 | 2013-05-24 00:44:20 -0700 | [diff] [blame] | 4531 | int i, rco_clk_rate; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4532 | void *ptr = NULL; |
| 4533 | |
| 4534 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 4535 | control = codec->control_data; |
| 4536 | |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame^] | 4537 | wcd9xxx_ssr_register(control, tapan_post_reset_cb, (void *)codec); |
| 4538 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4539 | dev_info(codec->dev, "%s()\n", __func__); |
| 4540 | |
| 4541 | tapan = kzalloc(sizeof(struct tapan_priv), GFP_KERNEL); |
| 4542 | if (!tapan) { |
| 4543 | dev_err(codec->dev, "Failed to allocate private data\n"); |
| 4544 | return -ENOMEM; |
| 4545 | } |
| 4546 | for (i = 0 ; i < NUM_DECIMATORS; i++) { |
| 4547 | tx_hpf_work[i].tapan = tapan; |
| 4548 | tx_hpf_work[i].decimator = i + 1; |
| 4549 | INIT_DELAYED_WORK(&tx_hpf_work[i].dwork, |
| 4550 | tx_hpf_corner_freq_callback); |
| 4551 | } |
| 4552 | |
| 4553 | snd_soc_codec_set_drvdata(codec, tapan); |
| 4554 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4555 | /* TODO: Read buck voltage from DT property */ |
| 4556 | tapan->clsh_d.buck_mv = WCD9XXX_CDC_BUCK_MV_1P8; |
| 4557 | wcd9xxx_clsh_init(&tapan->clsh_d, &tapan->resmgr); |
| 4558 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4559 | /* codec resmgr module init */ |
| 4560 | wcd9xxx = codec->control_data; |
| 4561 | pdata = dev_get_platdata(codec->dev->parent); |
| 4562 | ret = wcd9xxx_resmgr_init(&tapan->resmgr, codec, wcd9xxx, pdata, |
| 4563 | &tapan_reg_address); |
| 4564 | if (ret) { |
| 4565 | pr_err("%s: wcd9xxx init failed %d\n", __func__, ret); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4566 | return ret; |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4567 | } |
| 4568 | |
Phani Kumar Uppalapati | 43bc415 | 2013-05-24 00:44:20 -0700 | [diff] [blame] | 4569 | if (TAPAN_IS_1_0(control->version)) |
| 4570 | rco_clk_rate = TAPAN_MCLK_CLK_12P288MHZ; |
| 4571 | else |
| 4572 | rco_clk_rate = TAPAN_MCLK_CLK_9P6MHZ; |
| 4573 | |
Joonwoo Park | ccccba7 | 2013-04-26 11:19:46 -0700 | [diff] [blame] | 4574 | ret = wcd9xxx_mbhc_init(&tapan->mbhc, &tapan->resmgr, codec, NULL, |
Phani Kumar Uppalapati | 43bc415 | 2013-05-24 00:44:20 -0700 | [diff] [blame] | 4575 | WCD9XXX_MBHC_VERSION_TAPAN, |
| 4576 | rco_clk_rate); |
Simmi Pateriya | 0a44d84 | 2013-04-03 01:12:42 +0530 | [diff] [blame] | 4577 | if (ret) { |
| 4578 | pr_err("%s: mbhc init failed %d\n", __func__, ret); |
| 4579 | return ret; |
| 4580 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4581 | |
| 4582 | tapan->codec = codec; |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4583 | for (i = 0; i < COMPANDER_MAX; i++) { |
| 4584 | tapan->comp_enabled[i] = 0; |
| 4585 | tapan->comp_fs[i] = COMPANDER_FS_48KHZ; |
| 4586 | } |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4587 | tapan->intf_type = wcd9xxx_get_intf_type(); |
| 4588 | tapan->aux_pga_cnt = 0; |
| 4589 | tapan->aux_l_gain = 0x1F; |
| 4590 | tapan->aux_r_gain = 0x1F; |
| 4591 | tapan_update_reg_defaults(codec); |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame^] | 4592 | tapan_update_reg_mclk_rate(wcd9xxx); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4593 | tapan_codec_init_reg(codec); |
| 4594 | ret = tapan_handle_pdata(tapan); |
| 4595 | if (IS_ERR_VALUE(ret)) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4596 | dev_err(codec->dev, "%s: bad pdata\n", __func__); |
| 4597 | goto err_pdata; |
| 4598 | } |
| 4599 | |
| 4600 | if (spkr_drv_wrnd > 0) { |
| 4601 | WCD9XXX_BCL_LOCK(&tapan->resmgr); |
| 4602 | wcd9xxx_resmgr_get_bandgap(&tapan->resmgr, |
| 4603 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 4604 | WCD9XXX_BCL_UNLOCK(&tapan->resmgr); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4605 | } |
| 4606 | |
| 4607 | ptr = kmalloc((sizeof(tapan_rx_chs) + |
| 4608 | sizeof(tapan_tx_chs)), GFP_KERNEL); |
| 4609 | if (!ptr) { |
| 4610 | pr_err("%s: no mem for slim chan ctl data\n", __func__); |
| 4611 | ret = -ENOMEM; |
| 4612 | goto err_nomem_slimch; |
| 4613 | } |
| 4614 | |
| 4615 | if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4616 | snd_soc_dapm_new_controls(dapm, tapan_dapm_i2s_widgets, |
| 4617 | ARRAY_SIZE(tapan_dapm_i2s_widgets)); |
| 4618 | snd_soc_dapm_add_routes(dapm, audio_i2s_map, |
| 4619 | ARRAY_SIZE(audio_i2s_map)); |
| 4620 | for (i = 0; i < ARRAY_SIZE(tapan_i2s_dai); i++) |
| 4621 | INIT_LIST_HEAD(&tapan->dai[i].wcd9xxx_ch_list); |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4622 | } else if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 4623 | for (i = 0; i < NUM_CODEC_DAIS; i++) { |
| 4624 | INIT_LIST_HEAD(&tapan->dai[i].wcd9xxx_ch_list); |
| 4625 | init_waitqueue_head(&tapan->dai[i].dai_wait); |
| 4626 | } |
| 4627 | } |
| 4628 | |
| 4629 | control->num_rx_port = TAPAN_RX_MAX; |
| 4630 | control->rx_chs = ptr; |
| 4631 | memcpy(control->rx_chs, tapan_rx_chs, sizeof(tapan_rx_chs)); |
| 4632 | control->num_tx_port = TAPAN_TX_MAX; |
| 4633 | control->tx_chs = ptr + sizeof(tapan_rx_chs); |
| 4634 | memcpy(control->tx_chs, tapan_tx_chs, sizeof(tapan_tx_chs)); |
| 4635 | |
| 4636 | snd_soc_dapm_sync(dapm); |
| 4637 | |
| 4638 | (void) tapan_setup_irqs(tapan); |
| 4639 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4640 | atomic_set(&kp_tapan_priv, (unsigned long)tapan); |
Phani Kumar Uppalapati | 3a5f8cc | 2013-04-08 21:30:02 -0700 | [diff] [blame] | 4641 | mutex_lock(&dapm->codec->mutex); |
| 4642 | snd_soc_dapm_disable_pin(dapm, "ANC HPHL"); |
| 4643 | snd_soc_dapm_disable_pin(dapm, "ANC HPHR"); |
| 4644 | snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE"); |
| 4645 | snd_soc_dapm_disable_pin(dapm, "ANC EAR PA"); |
| 4646 | snd_soc_dapm_disable_pin(dapm, "ANC EAR"); |
| 4647 | snd_soc_dapm_sync(dapm); |
| 4648 | mutex_unlock(&dapm->codec->mutex); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4649 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4650 | codec->ignore_pmdown_time = 1; |
Ravishankar Sarawadi | 7b70036 | 2013-04-18 15:56:02 -0700 | [diff] [blame] | 4651 | |
| 4652 | if (ret) |
| 4653 | tapan_cleanup_irqs(tapan); |
| 4654 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4655 | return ret; |
| 4656 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4657 | err_pdata: |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4658 | kfree(ptr); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4659 | err_nomem_slimch: |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4660 | kfree(tapan); |
| 4661 | return ret; |
| 4662 | } |
| 4663 | |
| 4664 | static int tapan_codec_remove(struct snd_soc_codec *codec) |
| 4665 | { |
| 4666 | struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec); |
| 4667 | |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4668 | WCD9XXX_BCL_LOCK(&tapan->resmgr); |
| 4669 | atomic_set(&kp_tapan_priv, 0); |
| 4670 | |
| 4671 | if (spkr_drv_wrnd > 0) |
| 4672 | wcd9xxx_resmgr_put_bandgap(&tapan->resmgr, |
| 4673 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 4674 | WCD9XXX_BCL_UNLOCK(&tapan->resmgr); |
Ravishankar Sarawadi | 7b70036 | 2013-04-18 15:56:02 -0700 | [diff] [blame] | 4675 | |
| 4676 | tapan_cleanup_irqs(tapan); |
| 4677 | |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4678 | /* cleanup MBHC */ |
| 4679 | wcd9xxx_mbhc_deinit(&tapan->mbhc); |
| 4680 | /* cleanup resmgr */ |
| 4681 | wcd9xxx_resmgr_deinit(&tapan->resmgr); |
| 4682 | |
| 4683 | kfree(tapan); |
| 4684 | return 0; |
| 4685 | } |
| 4686 | |
| 4687 | static struct snd_soc_codec_driver soc_codec_dev_tapan = { |
| 4688 | .probe = tapan_codec_probe, |
| 4689 | .remove = tapan_codec_remove, |
| 4690 | |
| 4691 | .read = tapan_read, |
| 4692 | .write = tapan_write, |
| 4693 | |
| 4694 | .readable_register = tapan_readable, |
| 4695 | .volatile_register = tapan_volatile, |
| 4696 | |
| 4697 | .reg_cache_size = TAPAN_CACHE_SIZE, |
| 4698 | .reg_cache_default = tapan_reset_reg_defaults, |
| 4699 | .reg_word_size = 1, |
| 4700 | |
| 4701 | .controls = tapan_snd_controls, |
| 4702 | .num_controls = ARRAY_SIZE(tapan_snd_controls), |
| 4703 | .dapm_widgets = tapan_dapm_widgets, |
| 4704 | .num_dapm_widgets = ARRAY_SIZE(tapan_dapm_widgets), |
| 4705 | .dapm_routes = audio_map, |
| 4706 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
| 4707 | }; |
| 4708 | |
| 4709 | #ifdef CONFIG_PM |
| 4710 | static int tapan_suspend(struct device *dev) |
| 4711 | { |
| 4712 | dev_dbg(dev, "%s: system suspend\n", __func__); |
| 4713 | return 0; |
| 4714 | } |
| 4715 | |
| 4716 | static int tapan_resume(struct device *dev) |
| 4717 | { |
| 4718 | struct platform_device *pdev = to_platform_device(dev); |
| 4719 | struct tapan_priv *tapan = platform_get_drvdata(pdev); |
| 4720 | dev_dbg(dev, "%s: system resume\n", __func__); |
Bhalchandra Gajare | ea89874 | 2013-03-05 18:15:53 -0800 | [diff] [blame] | 4721 | /* Notify */ |
Bhalchandra Gajare | dcf09f8 | 2012-11-09 11:58:26 -0800 | [diff] [blame] | 4722 | wcd9xxx_resmgr_notifier_call(&tapan->resmgr, WCD9XXX_EVENT_POST_RESUME); |
| 4723 | return 0; |
| 4724 | } |
| 4725 | |
| 4726 | static const struct dev_pm_ops tapan_pm_ops = { |
| 4727 | .suspend = tapan_suspend, |
| 4728 | .resume = tapan_resume, |
| 4729 | }; |
| 4730 | #endif |
| 4731 | |
| 4732 | static int __devinit tapan_probe(struct platform_device *pdev) |
| 4733 | { |
| 4734 | int ret = 0; |
| 4735 | if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 4736 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tapan, |
| 4737 | tapan_dai, ARRAY_SIZE(tapan_dai)); |
| 4738 | else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C) |
| 4739 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tapan, |
| 4740 | tapan_i2s_dai, ARRAY_SIZE(tapan_i2s_dai)); |
| 4741 | return ret; |
| 4742 | } |
| 4743 | static int __devexit tapan_remove(struct platform_device *pdev) |
| 4744 | { |
| 4745 | snd_soc_unregister_codec(&pdev->dev); |
| 4746 | return 0; |
| 4747 | } |
| 4748 | static struct platform_driver tapan_codec_driver = { |
| 4749 | .probe = tapan_probe, |
| 4750 | .remove = tapan_remove, |
| 4751 | .driver = { |
| 4752 | .name = "tapan_codec", |
| 4753 | .owner = THIS_MODULE, |
| 4754 | #ifdef CONFIG_PM |
| 4755 | .pm = &tapan_pm_ops, |
| 4756 | #endif |
| 4757 | }, |
| 4758 | }; |
| 4759 | |
| 4760 | static int __init tapan_codec_init(void) |
| 4761 | { |
| 4762 | return platform_driver_register(&tapan_codec_driver); |
| 4763 | } |
| 4764 | |
| 4765 | static void __exit tapan_codec_exit(void) |
| 4766 | { |
| 4767 | platform_driver_unregister(&tapan_codec_driver); |
| 4768 | } |
| 4769 | |
| 4770 | module_init(tapan_codec_init); |
| 4771 | module_exit(tapan_codec_exit); |
| 4772 | |
| 4773 | MODULE_DESCRIPTION("Tapan codec driver"); |
| 4774 | MODULE_LICENSE("GPL v2"); |