Merge branch 'android-4.4' of https://android.googlesource.com/kernel/common
[firefly-linux-kernel-4.4.55.git] / include / linux / mfd / tlv320aic3262-core.h
1 #ifndef __MFD_AIC3262_CORE_H__
2 #define __MFD_AIC3262_CORE_H__
3
4 #include <linux/interrupt.h>
5 #include <linux/mfd/core.h>
6 enum aic3262_type {
7         TLV320AIC3262 = 0,
8 };
9
10
11 #define AIC3262_IRQ_HEADSET_DETECT      0
12 #define AIC3262_IRQ_BUTTON_PRESS        1
13 #define AIC3262_IRQ_DAC_DRC             2
14 #define AIC3262_IRQ_AGC_NOISE           3
15 #define AIC3262_IRQ_OVER_CURRENT        4
16 #define AIC3262_IRQ_OVERFLOW_EVENT      5
17 #define AIC3262_IRQ_SPEAKER_OVER_TEMP   6
18
19 #define AIC3262_GPIO1                   7
20 #define AIC3262_GPIO2                   8
21 #define AIC3262_GPI1                    9
22 #define AIC3262_GPI2                    10
23 #define AIC3262_GPO1                    11
24
25 typedef union aic326x_reg_union {
26         struct aic326x_reg{
27         u8 offset;
28         u8 page;
29         u8 book;
30         u8 reserved;
31         }aic326x_register;
32         unsigned int aic326x_register_int;
33 }aic326x_reg_union;
34
35
36 /****************************             ************************************/
37
38 /*
39  *****************************************************************************
40  * Structures Definitions
41  *****************************************************************************
42  */
43 /*
44  *----------------------------------------------------------------------------
45  * @struct  aic3262_setup_data |
46  *          i2c specific data setup for AIC3262.
47  * @field   unsigned short |i2c_address |
48  *          Unsigned short for i2c address.
49  *----------------------------------------------------------------------------
50  */
51 struct aic3262_setup_data {
52         unsigned short i2c_address;
53 };
54
55 /* GPIO API */                                                                                                                                              
56 #define AIC3262_NUM_GPIO 5 // include 2 GPI and 1 GPO pins
57 enum {                                                                                                                                                      
58         AIC3262_GPIO1_FUNC_DISABLED             = 0,                                                                                                        
59         AIC3262_GPIO1_FUNC_INPUT                = 1,                                                                                                        
60         AIC3262_GPIO1_FUNC_OUTPUT               = 3,                                                                                                        
61         AIC3262_GPIO1_FUNC_CLOCK_OUTPUT         = 4,
62         AIC3262_GPIO1_FUNC_INT1_OUTPUT          = 5,
63         AIC3262_GPIO1_FUNC_INT2_OUTPUT          = 6,
64         AIC3262_GPIO1_FUNC_ADC_MOD_CLK_OUTPUT   = 10,
65         AIC3262_GPIO1_FUNC_SAR_ADC_INTERRUPT    = 12,
66         AIC3262_GPIO1_FUNC_ASI1_DATA_OUTPUT     = 15,
67         AIC3262_GPIO1_FUNC_ASI1_WCLK            = 16,
68         AIC3262_GPIO1_FUNC_ASI1_BCLK            = 17,
69         AIC3262_GPIO1_FUNC_ASI2_WCLK            = 18,
70         AIC3262_GPIO1_FUNC_ASI2_BCLK            = 19,
71         AIC3262_GPIO1_FUNC_ASI3_WCLK            = 20,
72         AIC3262_GPIO1_FUNC_ASI3_BCLK            = 21
73
74 };                                                                                                                                                          
75                                                                                                                                                             
76 enum {                                                                                                                                                      
77         AIC3262_GPIO2_FUNC_DISABLED             = 0,                                                                                                        
78         AIC3262_GPIO2_FUNC_INPUT                = 1,                                                                                                        
79         AIC3262_GPIO2_FUNC_OUTPUT               = 3,                                                                                                        
80         AIC3262_GPIO2_FUNC_CLOCK_OUTPUT         = 4,
81         AIC3262_GPIO2_FUNC_INT1_OUTPUT          = 5,
82         AIC3262_GPIO2_FUNC_INT2_OUTPUT          = 6,
83         AIC3262_GPIO2_FUNC_ADC_MOD_CLK_OUTPUT   = 10,
84         AIC3262_GPIO2_FUNC_SAR_ADC_INTERRUPT    = 12,
85         AIC3262_GPIO2_FUNC_ASI1_DATA_OUTPUT     = 15,
86         AIC3262_GPIO2_FUNC_ASI1_WCLK            = 16,
87         AIC3262_GPIO2_FUNC_ASI1_BCLK            = 17,
88         AIC3262_GPIO2_FUNC_ASI2_WCLK            = 18,
89         AIC3262_GPIO2_FUNC_ASI2_BCLK            = 19,
90         AIC3262_GPIO2_FUNC_ASI3_WCLK            = 20,
91         AIC3262_GPIO2_FUNC_ASI3_BCLK            = 21
92 };                                   
93 enum {                                                                                                                                                      
94         AIC3262_GPO1_FUNC_DISABLED              = 0,                                                                                                        
95         AIC3262_GPO1_FUNC_MSO_OUTPUT_FOR_SPI    = 1,                                                                                                        
96         AIC3262_GPO1_FUNC_GENERAL_PURPOSE_OUTPUT= 2,
97         AIC3262_GPO1_FUNC_CLOCK_OUTPUT          = 3,
98         AIC3262_GPO1_FUNC_INT1_OUTPUT           = 4,
99         AIC3262_GPO1_FUNC_INT2_OUTPUT           = 5,
100         AIC3262_GPO1_FUNC_ADC_MOD_CLK_OUTPUT   = 7,
101         AIC3262_GPO1_FUNC_SAR_ADC_INTERRUPT    = 12,
102         AIC3262_GPO1_FUNC_ASI1_DATA_OUTPUT     = 15,
103 };                                   
104 /*
105  *----------------------------------------------------------------------------
106  * @struct  aic3262_configs |
107  *          AIC3262 initialization data which has register offset and register
108  *          value.
109  * @field   u8 | book_no |
110  *          AIC3262 Book Number Offsets required for initialization..
111  * @field   u16 | reg_offset |
112  *          AIC3262 Register offsets required for initialization..
113  * @field   u8 | reg_val |
114  *          value to set the AIC3262 register to initialize the AIC3262.
115  *----------------------------------------------------------------------------
116  */
117 struct aic3262_configs {
118         u8 book_no;
119         u16 reg_offset;
120         u8  reg_val;
121 };
122
123 /*
124  *----------------------------------------------------------------------------
125  * @struct  aic3262_rate_divs |
126  *          Setting up the values to get different freqencies
127  *
128  * @field   u32 | mclk |
129  *          Master clock
130  * @field   u32 | rate |
131  *          sample rate
132  * @field   u8 | p_val |
133  *          value of p in PLL
134  * @field   u32 | pll_j |
135  *          value for pll_j
136  * @field   u32 | pll_d |
137  *          value for pll_d
138  * @field   u32 | dosr |
139  *          value to store dosr
140  * @field   u32 | ndac |
141  *          value for ndac
142  * @field   u32 | mdac |
143  *          value for mdac
144  * @field   u32 | aosr |
145  *          value for aosr
146  * @field   u32 | nadc |
147  *          value for nadc
148  * @field   u32 | madc |
149  *          value for madc
150  * @field   u32 | blck_N |
151  *          value for block N
152  */
153 struct aic3262 {
154         struct mutex io_lock;
155         struct mutex irq_lock;
156
157         enum aic3262_type type;
158
159         struct device *dev;
160         int (*read_dev)(struct aic3262 *aic3262, unsigned int reg,
161                         int bytes, void *dest);
162         int (*write_dev)(struct aic3262 *aic3262, unsigned int reg,
163                          int bytes, const void *src);
164
165         void *control_data;
166
167 //      int gpio_base;
168         
169         unsigned int irq;
170         unsigned int irq_base;
171
172         u8 irq_masks_cur;
173         u8 irq_masks_cache;
174
175         /* Used over suspend/resume */
176         bool suspended;
177                 
178         u8 book_no;
179         u8 page_no;
180 };
181
182 struct aic3262_gpio_setup 
183 {
184         u8 used; // GPIO, GPI and GPO is used in the board, used = 1 else 0
185         u8 in; // GPIO is used as input, in = 1 else in = 0. GPI in = 1, GPO in = 0
186         unsigned int in_reg; // if GPIO is input, register to write the mask to.
187         u8 in_reg_bitmask; // bitmask for 'value' to be written into in_reg
188         u8 in_reg_shift; // bits to shift to write 'value' into in_reg
189         u8 value; // value to be written gpio_control_reg if GPIO is output, in_reg if its input        
190 }; 
191 struct aic3262_pdata {
192         unsigned int audio_mclk1; 
193         unsigned int audio_mclk2; 
194         unsigned int gpio_irq; /* whether AIC3262 interrupts the host AP on a GPIO pin of AP */ 
195         unsigned int gpio_reset; /* is the codec being reset by a gpio [host] pin, if yes provide the number. */
196         struct aic3262_gpio_setup *gpio;/* all gpio configuration */
197         int naudint_irq; /* audio interrupt */
198         unsigned int irq_base;
199 };
200                 
201
202
203 static inline int aic3262_request_irq(struct aic3262 *aic3262, int irq,
204                                       irq_handler_t handler, unsigned long irqflags,const char *name,
205                                       void *data)
206 {
207         if (!aic3262->irq_base)
208                 return -EINVAL;
209
210         return request_threaded_irq(aic3262->irq_base + irq, NULL, handler,
211                                     irqflags, name, data);
212 }
213
214 static inline void aic3262_free_irq(struct aic3262 *aic3262, int irq,
215                                     void *data)
216 {
217         if (!aic3262->irq_base)
218                 return;
219
220         free_irq(aic3262->irq_base + irq, data);
221 }
222
223 /* Device I/O API */
224 int aic3262_reg_read(struct aic3262 *aic3262, unsigned int reg);
225 int aic3262_reg_write(struct aic3262 *aic3262, unsigned int reg,
226                  unsigned char val);
227 int aic3262_set_bits(struct aic3262 *aic3262, unsigned int reg,
228                     unsigned char mask, unsigned char val);
229 int aic3262_bulk_read(struct aic3262 *aic3262, unsigned int reg,
230                      int count, u8 *buf);
231 int aic3262_bulk_write(struct aic3262 *aic3262, unsigned int reg,
232                      int count, const u8 *buf);
233
234
235 /* Helper to save on boilerplate */
236 /*static inline int aic3262_request_irq(struct aic3262 *aic3262, int irq,
237                                      irq_handler_t handler, const char *name,
238                                      void *data)
239 {
240         if (!aic3262->irq_base)
241                 return -EINVAL;
242         return request_threaded_irq(aic3262->irq_base + irq, NULL, handler,
243                                     IRQF_TRIGGER_RISING, name,
244                                     data);
245 }
246 static inline void aic3262_free_irq(struct aic3262 *aic3262, int irq, void *data)
247 {
248         if (!aic3262->irq_base)
249                 return;
250         free_irq(aic3262->irq_base + irq, data);
251 }
252 */
253 int aic3262_irq_init(struct aic3262 *aic3262);
254 void aic3262_irq_exit(struct aic3262 *aic3262);
255
256 #endif