1 #ifndef __MFD_AIC3262_CORE_H__
2 #define __MFD_AIC3262_CORE_H__
4 #include <linux/interrupt.h>
5 #include <linux/mfd/core.h>
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
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
25 typedef union aic326x_reg_union {
32 unsigned int aic326x_register_int;
36 /**************************** ************************************/
39 *****************************************************************************
40 * Structures Definitions
41 *****************************************************************************
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 *----------------------------------------------------------------------------
51 struct aic3262_setup_data {
52 unsigned short i2c_address;
56 #define AIC3262_NUM_GPIO 5 // include 2 GPI and 1 GPO pins
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
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
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,
105 *----------------------------------------------------------------------------
106 * @struct aic3262_configs |
107 * AIC3262 initialization data which has register offset and register
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 *----------------------------------------------------------------------------
117 struct aic3262_configs {
124 *----------------------------------------------------------------------------
125 * @struct aic3262_rate_divs |
126 * Setting up the values to get different freqencies
128 * @field u32 | mclk |
130 * @field u32 | rate |
132 * @field u8 | p_val |
134 * @field u32 | pll_j |
136 * @field u32 | pll_d |
138 * @field u32 | dosr |
139 * value to store dosr
140 * @field u32 | ndac |
142 * @field u32 | mdac |
144 * @field u32 | aosr |
146 * @field u32 | nadc |
148 * @field u32 | madc |
150 * @field u32 | blck_N |
154 struct mutex io_lock;
155 struct mutex irq_lock;
157 enum aic3262_type type;
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);
170 unsigned int irq_base;
175 /* Used over suspend/resume */
182 struct aic3262_gpio_setup
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
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;
203 static inline int aic3262_request_irq(struct aic3262 *aic3262, int irq,
204 irq_handler_t handler, unsigned long irqflags,const char *name,
207 if (!aic3262->irq_base)
210 return request_threaded_irq(aic3262->irq_base + irq, NULL, handler,
211 irqflags, name, data);
214 static inline void aic3262_free_irq(struct aic3262 *aic3262, int irq,
217 if (!aic3262->irq_base)
220 free_irq(aic3262->irq_base + irq, data);
224 int aic3262_reg_read(struct aic3262 *aic3262, unsigned int reg);
225 int aic3262_reg_write(struct aic3262 *aic3262, unsigned int reg,
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,
231 int aic3262_bulk_write(struct aic3262 *aic3262, unsigned int reg,
232 int count, const u8 *buf);
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,
240 if (!aic3262->irq_base)
242 return request_threaded_irq(aic3262->irq_base + irq, NULL, handler,
243 IRQF_TRIGGER_RISING, name,
246 static inline void aic3262_free_irq(struct aic3262 *aic3262, int irq, void *data)
248 if (!aic3262->irq_base)
250 free_irq(aic3262->irq_base + irq, data);
253 int aic3262_irq_init(struct aic3262 *aic3262);
254 void aic3262_irq_exit(struct aic3262 *aic3262);