blob: eeeb5574a00f5f260213b552c372e831e453f3f6 [file] [log] [blame]
Kuirong Wang265f3592012-12-05 16:17:41 -08001/* 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 Gajare9943aa62013-10-09 18:40:11 -070019#include <linux/mfd/wcd9xxx/pdata.h>
Kuirong Wang265f3592012-12-05 16:17:41 -080020
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 Wangae340de2013-05-30 18:11:07 -070027#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 Wang14b3fb92013-06-27 17:28:17 -070036#define MSM8X10_CODEC_NAME "msm8x10_wcd_codec"
Kuirong Wang265f3592012-12-05 16:17:41 -080037
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)
42extern const u8 msm8x10_wcd_reg_readable[MSM8X10_WCD_CACHE_SIZE];
43extern const u8 msm8x10_wcd_reset_reg_defaults[MSM8X10_WCD_CACHE_SIZE];
44struct msm8x10_wcd_codec_dai_data {
45 u32 rate;
46 u32 *ch_num;
47 u32 ch_act;
48 u32 ch_tot;
49};
50
51enum 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
58struct msm8x10_wcd_reg_mask_val {
59 u16 reg;
60 u8 mask;
61 u8 val;
62};
63
64enum 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 */
71enum {
72 MSM8X10_WCD_RX1 = 0,
73 MSM8X10_WCD_RX2,
74 MSM8X10_WCD_RX3,
75 MSM8X10_WCD_RX_MAX,
76};
77
78enum {
79 MSM8X10_WCD_TX1 = 0,
80 MSM8X10_WCD_TX2,
81 MSM8X10_WCD_TX3,
82 MSM8X10_WCD_TX4,
83 MSM8X10_WCD_TX_MAX,
84};
85
86enum {
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 Wang265f3592012-12-05 16:17:41 -0800117struct 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
125struct msm8x10_wcd_regulator {
126 const char *name;
127 int min_uV;
128 int max_uV;
129 int optimum_uA;
Kuirong Wang49f506a2013-05-22 17:38:26 -0700130 bool ondemand;
Kuirong Wang265f3592012-12-05 16:17:41 -0800131 struct regulator *regulator;
132};
133
134struct 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 Gajare9943aa62013-10-09 18:40:11 -0700140 struct wcd9xxx_micbias_setting micbias;
Kuirong Wang265f3592012-12-05 16:17:41 -0800141 struct msm8x10_wcd_ocp_setting ocp;
142 struct msm8x10_wcd_regulator regulator[MAX_REGULATOR];
143 u32 mclk_rate;
144};
145
146enum msm8x10_wcd_micbias_num {
147 MSM8X10_WCD_MICBIAS1 = 0,
148};
149
Kuirong Wang265f3592012-12-05 16:17:41 -0800150enum msm8x10_wcd_pm_state {
151 MSM8X10_WCD_PM_SLEEPABLE,
152 MSM8X10_WCD_PM_AWAKE,
153 MSM8X10_WCD_PM_ASLEEP,
154};
155
156struct msm8x10_wcd {
157 struct device *dev;
158 struct mutex io_lock;
159 struct mutex xfer_lock;
Kuirong Wang265f3592012-12-05 16:17:41 -0800160 u8 version;
161
162 int reset_gpio;
Kuirong Wang3a6408d2013-02-20 17:46:46 -0800163 int (*read_dev)(struct msm8x10_wcd *msm8x10,
Bhalchandra Gajared610c6b2013-07-11 16:28:56 -0700164 unsigned short reg);
Kuirong Wang3a6408d2013-02-20 17:46:46 -0800165 int (*write_dev)(struct msm8x10_wcd *msm8x10,
Kuirong Wang91e52532013-03-31 14:24:22 -0700166 unsigned short reg, u8 val);
Kuirong Wang265f3592012-12-05 16:17:41 -0800167
168 u32 num_of_supplies;
169 struct regulator_bulk_data *supplies;
170
Kuirong Wang265f3592012-12-05 16:17:41 -0800171 u8 idbyte[4];
172
Kuirong Wang265f3592012-12-05 16:17:41 -0800173 int num_irqs;
174 u32 mclk_rate;
Fred Oh4d716bb2013-07-30 10:14:46 -0700175 char __iomem *pdino_base;
Bhalchandra Gajared610c6b2013-07-11 16:28:56 -0700176
177 struct wcd9xxx_core_resource wcd9xxx_res;
Kuirong Wang265f3592012-12-05 16:17:41 -0800178};
179
180extern int msm8x10_wcd_mclk_enable(struct snd_soc_codec *codec, int mclk_enable,
181 bool dapm);
182extern int msm8x10_wcd_hs_detect(struct snd_soc_codec *codec,
Bhalchandra Gajare9c19dc22013-07-11 17:16:53 -0700183 struct wcd9xxx_mbhc_config *mbhc_cfg);
Kuirong Wang265f3592012-12-05 16:17:41 -0800184
185#endif