Kuirong Wang | 265f359 | 2012-12-05 16:17:41 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 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 | #ifndef MSM8X10_WCD_H |
| 13 | #define MSM8X10_WCD_H |
| 14 | |
| 15 | #include <sound/soc.h> |
| 16 | #include <sound/jack.h> |
| 17 | #include "wcd9xxx-mbhc.h" |
| 18 | #include "wcd9xxx-resmgr.h" |
Bhalchandra Gajare | 9943aa6 | 2013-10-09 18:40:11 -0700 | [diff] [blame] | 19 | #include <linux/mfd/wcd9xxx/pdata.h> |
Kuirong Wang | 265f359 | 2012-12-05 16:17:41 -0800 | [diff] [blame] | 20 | |
| 21 | #define MSM8X10_WCD_NUM_REGISTERS 0x600 |
| 22 | #define MSM8X10_WCD_MAX_REGISTER (MSM8X10_WCD_NUM_REGISTERS-1) |
| 23 | #define MSM8X10_WCD_CACHE_SIZE MSM8X10_WCD_NUM_REGISTERS |
| 24 | #define MSM8X10_WCD_NUM_IRQ_REGS 3 |
| 25 | #define MAX_REGULATOR 7 |
| 26 | #define MSM8X10_WCD_REG_VAL(reg, val) {reg, 0, val} |
Kuirong Wang | ae340de | 2013-05-30 18:11:07 -0700 | [diff] [blame] | 27 | #define MSM8X10_DINO_LPASS_AUDIO_CORE_DIG_CODEC_CLK_SEL 0xFE03B004 |
| 28 | #define MSM8X10_DINO_LPASS_DIGCODEC_CMD_RCGR 0xFE02C000 |
| 29 | #define MSM8X10_DINO_LPASS_DIGCODEC_CFG_RCGR 0xFE02C004 |
| 30 | #define MSM8X10_DINO_LPASS_DIGCODEC_M 0xFE02C008 |
| 31 | #define MSM8X10_DINO_LPASS_DIGCODEC_N 0xFE02C00C |
| 32 | #define MSM8X10_DINO_LPASS_DIGCODEC_D 0xFE02C010 |
| 33 | #define MSM8X10_DINO_LPASS_DIGCODEC_CBCR 0xFE02C014 |
| 34 | #define MSM8X10_DINO_LPASS_DIGCODEC_AHB_CBCR 0xFE02C018 |
| 35 | |
Kuirong Wang | 14b3fb9 | 2013-06-27 17:28:17 -0700 | [diff] [blame] | 36 | #define MSM8X10_CODEC_NAME "msm8x10_wcd_codec" |
Kuirong Wang | 265f359 | 2012-12-05 16:17:41 -0800 | [diff] [blame] | 37 | |
| 38 | #define MSM8X10_WCD_IS_DINO_REG(reg) \ |
| 39 | (((reg >= 0x400) && (reg <= 0x5FF)) ? 1 : 0) |
| 40 | #define MSM8X10_WCD_IS_HELICON_REG(reg) \ |
| 41 | (((reg >= 0x000) && (reg <= 0x1FF)) ? 1 : 0) |
| 42 | extern const u8 msm8x10_wcd_reg_readable[MSM8X10_WCD_CACHE_SIZE]; |
| 43 | extern const u8 msm8x10_wcd_reset_reg_defaults[MSM8X10_WCD_CACHE_SIZE]; |
| 44 | struct msm8x10_wcd_codec_dai_data { |
| 45 | u32 rate; |
| 46 | u32 *ch_num; |
| 47 | u32 ch_act; |
| 48 | u32 ch_tot; |
| 49 | }; |
| 50 | |
| 51 | enum msm8x10_wcd_pid_current { |
| 52 | MSM8X10_WCD_PID_MIC_2P5_UA, |
| 53 | MSM8X10_WCD_PID_MIC_5_UA, |
| 54 | MSM8X10_WCD_PID_MIC_10_UA, |
| 55 | MSM8X10_WCD_PID_MIC_20_UA, |
| 56 | }; |
| 57 | |
| 58 | struct msm8x10_wcd_reg_mask_val { |
| 59 | u16 reg; |
| 60 | u8 mask; |
| 61 | u8 val; |
| 62 | }; |
| 63 | |
| 64 | enum msm8x10_wcd_mbhc_analog_pwr_cfg { |
| 65 | MSM8X10_WCD_ANALOG_PWR_COLLAPSED = 0, |
| 66 | MSM8X10_WCD_ANALOG_PWR_ON, |
| 67 | MSM8X10_WCD_NUM_ANALOG_PWR_CONFIGS, |
| 68 | }; |
| 69 | |
| 70 | /* Number of input and output Slimbus port */ |
| 71 | enum { |
| 72 | MSM8X10_WCD_RX1 = 0, |
| 73 | MSM8X10_WCD_RX2, |
| 74 | MSM8X10_WCD_RX3, |
| 75 | MSM8X10_WCD_RX_MAX, |
| 76 | }; |
| 77 | |
| 78 | enum { |
| 79 | MSM8X10_WCD_TX1 = 0, |
| 80 | MSM8X10_WCD_TX2, |
| 81 | MSM8X10_WCD_TX3, |
| 82 | MSM8X10_WCD_TX4, |
| 83 | MSM8X10_WCD_TX_MAX, |
| 84 | }; |
| 85 | |
| 86 | enum { |
| 87 | /* INTR_REG 0 */ |
| 88 | MSM8X10_WCD_IRQ_RESERVED_0 = 0, |
| 89 | MSM8X10_WCD_IRQ_MBHC_REMOVAL, |
| 90 | MSM8X10_WCD_IRQ_MBHC_SHORT_TERM, |
| 91 | MSM8X10_WCD_IRQ_MBHC_PRESS, |
| 92 | MSM8X10_WCD_IRQ_MBHC_RELEASE, |
| 93 | MSM8X10_WCD_IRQ_MBHC_POTENTIAL, |
| 94 | MSM8X10_WCD_IRQ_MBHC_INSERTION, |
| 95 | MSM8X10_WCD_IRQ_MBHC_HS_DET, |
| 96 | /* INTR_REG 1 */ |
| 97 | MSM8X10_WCD_IRQ_PA_STARTUP, |
| 98 | MSM8X10_WCD_IRQ_BG_PRECHARGE, |
| 99 | MSM8X10_WCD_IRQ_RESERVED_1, |
| 100 | MSM8X10_WCD_IRQ_EAR_PA_OCPL_FAULT, |
| 101 | MSM8X10_WCD_IRQ_EAR_PA_STARTUP, |
| 102 | MSM8X10_WCD_IRQ_SPKR_PA_OCPL_FAULT, |
| 103 | MSM8X10_WCD_IRQ_SPKR_CLIP_FAULT, |
| 104 | MSM8X10_WCD_IRQ_RESERVED_2, |
| 105 | /* INTR_REG 2 */ |
| 106 | MSM8X10_WCD_IRQ_HPH_L_PA_STARTUP, |
| 107 | MSM8X10_WCD_IRQ_HPH_R_PA_STARTUP, |
| 108 | MSM8X10_WCD_IRQ_HPH_PA_OCPL_FAULT, |
| 109 | MSM8X10_WCD_IRQ_HPH_PA_OCPR_FAULT, |
| 110 | MSM8X10_WCD_IRQ_RESERVED_3, |
| 111 | MSM8X10_WCD_IRQ_RESERVED_4, |
| 112 | MSM8X10_WCD_IRQ_RESERVED_5, |
| 113 | MSM8X10_WCD_IRQ_RESERVED_6, |
| 114 | MSM8X10_WCD_NUM_IRQS, |
| 115 | }; |
| 116 | |
Kuirong Wang | 265f359 | 2012-12-05 16:17:41 -0800 | [diff] [blame] | 117 | struct msm8x10_wcd_ocp_setting { |
| 118 | unsigned int use_pdata:1; /* 0 - use sys default as recommended */ |
| 119 | unsigned int num_attempts:4; /* up to 15 attempts */ |
| 120 | unsigned int run_time:4; /* in duty cycle */ |
| 121 | unsigned int wait_time:4; /* in duty cycle */ |
| 122 | unsigned int hph_ocp_limit:3; /* Headphone OCP current limit */ |
| 123 | }; |
| 124 | |
| 125 | struct msm8x10_wcd_regulator { |
| 126 | const char *name; |
| 127 | int min_uV; |
| 128 | int max_uV; |
| 129 | int optimum_uA; |
Kuirong Wang | 49f506a | 2013-05-22 17:38:26 -0700 | [diff] [blame] | 130 | bool ondemand; |
Kuirong Wang | 265f359 | 2012-12-05 16:17:41 -0800 | [diff] [blame] | 131 | struct regulator *regulator; |
| 132 | }; |
| 133 | |
| 134 | struct msm8x10_wcd_pdata { |
| 135 | int irq; |
| 136 | int irq_base; |
| 137 | int num_irqs; |
| 138 | int reset_gpio; |
| 139 | void *msm8x10_wcd_ahb_base_vaddr; |
Bhalchandra Gajare | 9943aa6 | 2013-10-09 18:40:11 -0700 | [diff] [blame] | 140 | struct wcd9xxx_micbias_setting micbias; |
Kuirong Wang | 265f359 | 2012-12-05 16:17:41 -0800 | [diff] [blame] | 141 | struct msm8x10_wcd_ocp_setting ocp; |
| 142 | struct msm8x10_wcd_regulator regulator[MAX_REGULATOR]; |
| 143 | u32 mclk_rate; |
| 144 | }; |
| 145 | |
| 146 | enum msm8x10_wcd_micbias_num { |
| 147 | MSM8X10_WCD_MICBIAS1 = 0, |
| 148 | }; |
| 149 | |
Kuirong Wang | 265f359 | 2012-12-05 16:17:41 -0800 | [diff] [blame] | 150 | enum msm8x10_wcd_pm_state { |
| 151 | MSM8X10_WCD_PM_SLEEPABLE, |
| 152 | MSM8X10_WCD_PM_AWAKE, |
| 153 | MSM8X10_WCD_PM_ASLEEP, |
| 154 | }; |
| 155 | |
| 156 | struct msm8x10_wcd { |
| 157 | struct device *dev; |
| 158 | struct mutex io_lock; |
| 159 | struct mutex xfer_lock; |
Kuirong Wang | 265f359 | 2012-12-05 16:17:41 -0800 | [diff] [blame] | 160 | u8 version; |
| 161 | |
| 162 | int reset_gpio; |
Kuirong Wang | 3a6408d | 2013-02-20 17:46:46 -0800 | [diff] [blame] | 163 | int (*read_dev)(struct msm8x10_wcd *msm8x10, |
Bhalchandra Gajare | d610c6b | 2013-07-11 16:28:56 -0700 | [diff] [blame] | 164 | unsigned short reg); |
Kuirong Wang | 3a6408d | 2013-02-20 17:46:46 -0800 | [diff] [blame] | 165 | int (*write_dev)(struct msm8x10_wcd *msm8x10, |
Kuirong Wang | 91e5253 | 2013-03-31 14:24:22 -0700 | [diff] [blame] | 166 | unsigned short reg, u8 val); |
Kuirong Wang | 265f359 | 2012-12-05 16:17:41 -0800 | [diff] [blame] | 167 | |
| 168 | u32 num_of_supplies; |
| 169 | struct regulator_bulk_data *supplies; |
| 170 | |
Kuirong Wang | 265f359 | 2012-12-05 16:17:41 -0800 | [diff] [blame] | 171 | u8 idbyte[4]; |
| 172 | |
Kuirong Wang | 265f359 | 2012-12-05 16:17:41 -0800 | [diff] [blame] | 173 | int num_irqs; |
| 174 | u32 mclk_rate; |
Fred Oh | 4d716bb | 2013-07-30 10:14:46 -0700 | [diff] [blame] | 175 | char __iomem *pdino_base; |
Bhalchandra Gajare | d610c6b | 2013-07-11 16:28:56 -0700 | [diff] [blame] | 176 | |
| 177 | struct wcd9xxx_core_resource wcd9xxx_res; |
Kuirong Wang | 265f359 | 2012-12-05 16:17:41 -0800 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | extern int msm8x10_wcd_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, |
| 181 | bool dapm); |
| 182 | extern int msm8x10_wcd_hs_detect(struct snd_soc_codec *codec, |
Bhalchandra Gajare | 9c19dc2 | 2013-07-11 17:16:53 -0700 | [diff] [blame] | 183 | struct wcd9xxx_mbhc_config *mbhc_cfg); |
Kuirong Wang | 265f359 | 2012-12-05 16:17:41 -0800 | [diff] [blame] | 184 | |
| 185 | #endif |