1 /*
2  * Arizona MFD internals
3  *
4  * Copyright 2012 Wolfson Microelectronics plc
5  *
6  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12 
13 #ifndef _WM_ARIZONA_CORE_H
14 #define _WM_ARIZONA_CORE_H
15 
16 #include <linux/clk.h>
17 #include <linux/interrupt.h>
18 #include <linux/notifier.h>
19 #include <linux/regmap.h>
20 #include <linux/regulator/consumer.h>
21 #include <linux/mfd/arizona/pdata.h>
22 
23 #define ARIZONA_MAX_CORE_SUPPLIES 2
24 
25 enum {
26 	ARIZONA_MCLK1,
27 	ARIZONA_MCLK2,
28 	ARIZONA_NUM_MCLK
29 };
30 
31 enum arizona_type {
32 	WM5102 = 1,
33 	WM5110 = 2,
34 	WM8997 = 3,
35 	WM8280 = 4,
36 	WM8998 = 5,
37 	WM1814 = 6,
38 	WM1831 = 7,
39 	CS47L24 = 8,
40 };
41 
42 #define ARIZONA_IRQ_GP1                    0
43 #define ARIZONA_IRQ_GP2                    1
44 #define ARIZONA_IRQ_GP3                    2
45 #define ARIZONA_IRQ_GP4                    3
46 #define ARIZONA_IRQ_GP5_FALL               4
47 #define ARIZONA_IRQ_GP5_RISE               5
48 #define ARIZONA_IRQ_JD_FALL                6
49 #define ARIZONA_IRQ_JD_RISE                7
50 #define ARIZONA_IRQ_DSP1_RAM_RDY           8
51 #define ARIZONA_IRQ_DSP2_RAM_RDY           9
52 #define ARIZONA_IRQ_DSP3_RAM_RDY          10
53 #define ARIZONA_IRQ_DSP4_RAM_RDY          11
54 #define ARIZONA_IRQ_DSP_IRQ1              12
55 #define ARIZONA_IRQ_DSP_IRQ2              13
56 #define ARIZONA_IRQ_DSP_IRQ3              14
57 #define ARIZONA_IRQ_DSP_IRQ4              15
58 #define ARIZONA_IRQ_DSP_IRQ5              16
59 #define ARIZONA_IRQ_DSP_IRQ6              17
60 #define ARIZONA_IRQ_DSP_IRQ7              18
61 #define ARIZONA_IRQ_DSP_IRQ8              19
62 #define ARIZONA_IRQ_SPK_OVERHEAT_WARN     20
63 #define ARIZONA_IRQ_SPK_OVERHEAT          21
64 #define ARIZONA_IRQ_MICDET                22
65 #define ARIZONA_IRQ_HPDET                 23
66 #define ARIZONA_IRQ_WSEQ_DONE             24
67 #define ARIZONA_IRQ_DRC2_SIG_DET          25
68 #define ARIZONA_IRQ_DRC1_SIG_DET          26
69 #define ARIZONA_IRQ_ASRC2_LOCK            27
70 #define ARIZONA_IRQ_ASRC1_LOCK            28
71 #define ARIZONA_IRQ_UNDERCLOCKED          29
72 #define ARIZONA_IRQ_OVERCLOCKED           30
73 #define ARIZONA_IRQ_FLL2_LOCK             31
74 #define ARIZONA_IRQ_FLL1_LOCK             32
75 #define ARIZONA_IRQ_CLKGEN_ERR            33
76 #define ARIZONA_IRQ_CLKGEN_ERR_ASYNC      34
77 #define ARIZONA_IRQ_ASRC_CFG_ERR          35
78 #define ARIZONA_IRQ_AIF3_ERR              36
79 #define ARIZONA_IRQ_AIF2_ERR              37
80 #define ARIZONA_IRQ_AIF1_ERR              38
81 #define ARIZONA_IRQ_CTRLIF_ERR            39
82 #define ARIZONA_IRQ_MIXER_DROPPED_SAMPLES 40
83 #define ARIZONA_IRQ_ASYNC_CLK_ENA_LOW     41
84 #define ARIZONA_IRQ_SYSCLK_ENA_LOW        42
85 #define ARIZONA_IRQ_ISRC1_CFG_ERR         43
86 #define ARIZONA_IRQ_ISRC2_CFG_ERR         44
87 #define ARIZONA_IRQ_BOOT_DONE             45
88 #define ARIZONA_IRQ_DCS_DAC_DONE          46
89 #define ARIZONA_IRQ_DCS_HP_DONE           47
90 #define ARIZONA_IRQ_FLL2_CLOCK_OK         48
91 #define ARIZONA_IRQ_FLL1_CLOCK_OK         49
92 #define ARIZONA_IRQ_MICD_CLAMP_RISE	  50
93 #define ARIZONA_IRQ_MICD_CLAMP_FALL	  51
94 #define ARIZONA_IRQ_HP3R_DONE             52
95 #define ARIZONA_IRQ_HP3L_DONE             53
96 #define ARIZONA_IRQ_HP2R_DONE             54
97 #define ARIZONA_IRQ_HP2L_DONE             55
98 #define ARIZONA_IRQ_HP1R_DONE             56
99 #define ARIZONA_IRQ_HP1L_DONE             57
100 #define ARIZONA_IRQ_ISRC3_CFG_ERR         58
101 #define ARIZONA_IRQ_DSP_SHARED_WR_COLL    59
102 #define ARIZONA_IRQ_SPK_SHUTDOWN          60
103 #define ARIZONA_IRQ_SPK1R_SHORT           61
104 #define ARIZONA_IRQ_SPK1L_SHORT           62
105 #define ARIZONA_IRQ_HP3R_SC_NEG           63
106 #define ARIZONA_IRQ_HP3R_SC_POS           64
107 #define ARIZONA_IRQ_HP3L_SC_NEG           65
108 #define ARIZONA_IRQ_HP3L_SC_POS           66
109 #define ARIZONA_IRQ_HP2R_SC_NEG           67
110 #define ARIZONA_IRQ_HP2R_SC_POS           68
111 #define ARIZONA_IRQ_HP2L_SC_NEG           69
112 #define ARIZONA_IRQ_HP2L_SC_POS           70
113 #define ARIZONA_IRQ_HP1R_SC_NEG           71
114 #define ARIZONA_IRQ_HP1R_SC_POS           72
115 #define ARIZONA_IRQ_HP1L_SC_NEG           73
116 #define ARIZONA_IRQ_HP1L_SC_POS           74
117 
118 #define ARIZONA_NUM_IRQ                   75
119 
120 struct snd_soc_dapm_context;
121 
122 struct arizona {
123 	struct regmap *regmap;
124 	struct device *dev;
125 
126 	enum arizona_type type;
127 	unsigned int rev;
128 
129 	int num_core_supplies;
130 	struct regulator_bulk_data core_supplies[ARIZONA_MAX_CORE_SUPPLIES];
131 	struct regulator *dcvdd;
132 	bool has_fully_powered_off;
133 
134 	struct arizona_pdata pdata;
135 
136 	unsigned int external_dcvdd:1;
137 
138 	int irq;
139 	struct irq_domain *virq;
140 	struct regmap_irq_chip_data *aod_irq_chip;
141 	struct regmap_irq_chip_data *irq_chip;
142 
143 	bool hpdet_clamp;
144 	unsigned int hp_ena;
145 
146 	struct mutex clk_lock;
147 	int clk32k_ref;
148 
149 	struct clk *mclk[ARIZONA_NUM_MCLK];
150 
151 	bool ctrlif_error;
152 
153 	struct snd_soc_dapm_context *dapm;
154 
155 	int tdm_width[ARIZONA_MAX_AIF];
156 	int tdm_slots[ARIZONA_MAX_AIF];
157 
158 	uint16_t dac_comp_coeff;
159 	uint8_t dac_comp_enabled;
160 	struct mutex dac_comp_lock;
161 
162 	struct blocking_notifier_head notifier;
163 };
164 
arizona_call_notifiers(struct arizona * arizona,unsigned long event,void * data)165 static inline int arizona_call_notifiers(struct arizona *arizona,
166 					 unsigned long event,
167 					 void *data)
168 {
169 	return blocking_notifier_call_chain(&arizona->notifier, event, data);
170 }
171 
172 int arizona_clk32k_enable(struct arizona *arizona);
173 int arizona_clk32k_disable(struct arizona *arizona);
174 
175 int arizona_request_irq(struct arizona *arizona, int irq, char *name,
176 			irq_handler_t handler, void *data);
177 void arizona_free_irq(struct arizona *arizona, int irq, void *data);
178 int arizona_set_irq_wake(struct arizona *arizona, int irq, int on);
179 
180 #ifdef CONFIG_MFD_WM5102
181 int wm5102_patch(struct arizona *arizona);
182 #else
wm5102_patch(struct arizona * arizona)183 static inline int wm5102_patch(struct arizona *arizona)
184 {
185 	return 0;
186 }
187 #endif
188 
189 int wm5110_patch(struct arizona *arizona);
190 int cs47l24_patch(struct arizona *arizona);
191 int wm8997_patch(struct arizona *arizona);
192 int wm8998_patch(struct arizona *arizona);
193 
194 #endif
195