Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | #ifndef WCD9335_H |
| 14 | #define WCD9335_H |
| 15 | |
| 16 | #include <sound/soc.h> |
| 17 | #include <sound/jack.h> |
| 18 | #include <sound/apr_audio-v2.h> |
| 19 | #include <linux/mfd/wcd9xxx/wcd9xxx-slimslave.h> |
| 20 | #include "wcd-mbhc-v2.h" |
| 21 | |
| 22 | #define TASHA_REG_VAL(reg, val) {reg, 0, val} |
| 23 | |
| 24 | #define TASHA_REGISTER_START_OFFSET 0x800 |
| 25 | #define TASHA_SB_PGD_PORT_RX_BASE 0x40 |
| 26 | #define TASHA_SB_PGD_PORT_TX_BASE 0x50 |
| 27 | |
| 28 | #define TASHA_ZDET_SUPPORTED true |
| 29 | /* z value defined in milliohm */ |
| 30 | #define TASHA_ZDET_VAL_32 32000 |
| 31 | #define TASHA_ZDET_VAL_400 400000 |
| 32 | #define TASHA_ZDET_VAL_1200 1200000 |
| 33 | #define TASHA_ZDET_VAL_100K 100000000 |
| 34 | /* z floating defined in ohms */ |
| 35 | #define TASHA_ZDET_FLOATING_IMPEDANCE 0x0FFFFFFE |
| 36 | |
| 37 | #define WCD9335_DMIC_CLK_DIV_2 0x0 |
| 38 | #define WCD9335_DMIC_CLK_DIV_3 0x1 |
| 39 | #define WCD9335_DMIC_CLK_DIV_4 0x2 |
| 40 | #define WCD9335_DMIC_CLK_DIV_6 0x3 |
| 41 | #define WCD9335_DMIC_CLK_DIV_8 0x4 |
| 42 | #define WCD9335_DMIC_CLK_DIV_16 0x5 |
| 43 | #define WCD9335_DMIC_CLK_DRIVE_DEFAULT 0x02 |
| 44 | |
| 45 | #define WCD9335_ANC_DMIC_X2_FULL_RATE 1 |
| 46 | #define WCD9335_ANC_DMIC_X2_HALF_RATE 0 |
| 47 | |
| 48 | /* Number of input and output Slimbus port */ |
| 49 | enum { |
| 50 | TASHA_RX0 = 0, |
| 51 | TASHA_RX1, |
| 52 | TASHA_RX2, |
| 53 | TASHA_RX3, |
| 54 | TASHA_RX4, |
| 55 | TASHA_RX5, |
| 56 | TASHA_RX6, |
| 57 | TASHA_RX7, |
| 58 | TASHA_RX8, |
| 59 | TASHA_RX9, |
| 60 | TASHA_RX10, |
| 61 | TASHA_RX11, |
| 62 | TASHA_RX12, |
| 63 | TASHA_RX_MAX, |
| 64 | }; |
| 65 | |
| 66 | enum { |
| 67 | TASHA_TX0 = 0, |
| 68 | TASHA_TX1, |
| 69 | TASHA_TX2, |
| 70 | TASHA_TX3, |
| 71 | TASHA_TX4, |
| 72 | TASHA_TX5, |
| 73 | TASHA_TX6, |
| 74 | TASHA_TX7, |
| 75 | TASHA_TX8, |
| 76 | TASHA_TX9, |
| 77 | TASHA_TX10, |
| 78 | TASHA_TX11, |
| 79 | TASHA_TX12, |
| 80 | TASHA_TX13, |
| 81 | TASHA_TX14, |
| 82 | TASHA_TX15, |
| 83 | TASHA_TX_MAX, |
| 84 | }; |
| 85 | |
| 86 | enum { |
| 87 | /* INTR_REG 0 */ |
| 88 | WCD9335_IRQ_FLL_LOCK_LOSS = 1, |
| 89 | WCD9335_IRQ_HPH_PA_OCPL_FAULT, |
| 90 | WCD9335_IRQ_HPH_PA_OCPR_FAULT, |
| 91 | WCD9335_IRQ_EAR_PA_OCP_FAULT, |
| 92 | WCD9335_IRQ_HPH_PA_CNPL_COMPLETE, |
| 93 | WCD9335_IRQ_HPH_PA_CNPR_COMPLETE, |
| 94 | WCD9335_IRQ_EAR_PA_CNP_COMPLETE, |
| 95 | /* INTR_REG 1 */ |
| 96 | WCD9335_IRQ_MBHC_SW_DET, |
| 97 | WCD9335_IRQ_MBHC_ELECT_INS_REM_DET, |
| 98 | WCD9335_IRQ_MBHC_BUTTON_PRESS_DET, |
| 99 | WCD9335_IRQ_MBHC_BUTTON_RELEASE_DET, |
| 100 | WCD9335_IRQ_MBHC_ELECT_INS_REM_LEG_DET, |
| 101 | WCD9335_IRQ_RESERVED_0, |
| 102 | WCD9335_IRQ_RESERVED_1, |
| 103 | WCD9335_IRQ_RESERVED_2, |
| 104 | /* INTR_REG 2 */ |
| 105 | WCD9335_IRQ_LINE_PA1_CNP_COMPLETE, |
| 106 | WCD9335_IRQ_LINE_PA2_CNP_COMPLETE, |
| 107 | WCD9335_IRQ_LINE_PA3_CNP_COMPLETE, |
| 108 | WCD9335_IRQ_LINE_PA4_CNP_COMPLETE, |
| 109 | WCD9335_IRQ_SOUNDWIRE, |
| 110 | WCD9335_IRQ_VDD_DIG_RAMP_COMPLETE, |
| 111 | WCD9335_IRQ_RCO_ERROR, |
| 112 | WCD9335_IRQ_SVA_ERROR, |
| 113 | /* INTR_REG 3 */ |
| 114 | WCD9335_IRQ_MAD_AUDIO, |
| 115 | WCD9335_IRQ_MAD_BEACON, |
| 116 | WCD9335_IRQ_MAD_ULTRASOUND, |
| 117 | WCD9335_IRQ_VBAT_ATTACK, |
| 118 | WCD9335_IRQ_VBAT_RESTORE, |
| 119 | WCD9335_IRQ_SVA_OUTBOX1, |
| 120 | WCD9335_IRQ_SVA_OUTBOX2, |
| 121 | WCD9335_NUM_IRQS, |
| 122 | }; |
| 123 | |
| 124 | enum wcd9335_codec_event { |
| 125 | WCD9335_CODEC_EVENT_CODEC_UP = 0, |
| 126 | }; |
| 127 | |
| 128 | enum tasha_on_demand_supply { |
| 129 | ON_DEMAND_MICBIAS = 0, |
| 130 | ON_DEMAND_SUPPLIES_MAX, |
| 131 | }; |
| 132 | |
| 133 | /* structure used to put the defined |
| 134 | * ondemand supply for codec |
| 135 | * and count being used. |
| 136 | */ |
| 137 | struct on_demand_supply { |
| 138 | struct regulator *supply; |
| 139 | int ondemand_supply_count; |
| 140 | }; |
| 141 | |
| 142 | /* Dai data structure holds the |
| 143 | * dai specific info like rate, |
| 144 | * channel number etc. |
| 145 | */ |
| 146 | struct tasha_codec_dai_data { |
| 147 | u32 rate; |
| 148 | u32 *ch_num; |
| 149 | u32 ch_act; |
| 150 | u32 ch_tot; |
| 151 | }; |
| 152 | |
| 153 | /* Structure used to update codec |
| 154 | * register defaults after reset |
| 155 | */ |
| 156 | struct tasha_reg_mask_val { |
| 157 | u16 reg; |
| 158 | u8 mask; |
| 159 | u8 val; |
| 160 | }; |
| 161 | |
| 162 | /* Selects compander and smart boost settings |
| 163 | * for a given speaker mode |
| 164 | */ |
| 165 | enum { |
| 166 | SPKR_MODE_DEFAULT, |
| 167 | SPKR_MODE_1, /* COMP Gain = 12dB, Smartboost Max = 5.5V */ |
| 168 | }; |
| 169 | |
| 170 | /* |
| 171 | * Rx path gain offsets |
| 172 | */ |
| 173 | enum { |
| 174 | RX_GAIN_OFFSET_M1P5_DB, |
| 175 | RX_GAIN_OFFSET_0_DB, |
| 176 | }; |
| 177 | |
| 178 | extern void *tasha_get_afe_config(struct snd_soc_codec *codec, |
| 179 | enum afe_config_type config_type); |
| 180 | extern int tasha_cdc_mclk_enable(struct snd_soc_codec *codec, int enable, |
| 181 | bool dapm); |
| 182 | extern int tasha_cdc_mclk_tx_enable(struct snd_soc_codec *codec, int enable, |
| 183 | bool dapm); |
| 184 | extern int tasha_enable_efuse_sensing(struct snd_soc_codec *codec); |
| 185 | extern int tasha_mbhc_hs_detect(struct snd_soc_codec *codec, |
| 186 | struct wcd_mbhc_config *mbhc_cfg); |
| 187 | extern void tasha_mbhc_hs_detect_exit(struct snd_soc_codec *codec); |
| 188 | extern void tasha_mbhc_zdet_gpio_ctrl( |
| 189 | int (*zdet_gpio_cb)(struct snd_soc_codec *codec, bool high), |
| 190 | struct snd_soc_codec *codec); |
| 191 | extern int tasha_codec_info_create_codec_entry( |
| 192 | struct snd_info_entry *codec_root, |
| 193 | struct snd_soc_codec *codec); |
| 194 | extern void tasha_event_register( |
| 195 | int (*machine_event_cb)(struct snd_soc_codec *codec, |
| 196 | enum wcd9335_codec_event), |
| 197 | struct snd_soc_codec *codec); |
| 198 | extern int tasha_codec_enable_standalone_micbias(struct snd_soc_codec *codec, |
| 199 | int micb_num, |
| 200 | bool enable); |
| 201 | extern int tasha_set_spkr_mode(struct snd_soc_codec *codec, int mode); |
| 202 | extern int tasha_set_spkr_gain_offset(struct snd_soc_codec *codec, int offset); |
| 203 | extern enum codec_variant tasha_codec_ver(void); |
| 204 | #endif |