1 /*
2  * comparator.h  --  Comparator Aux ADC for Wolfson WM8350 PMIC
3  *
4  * Copyright 2007 Wolfson Microelectronics PLC
5  *
6  *  This program is free software; you can redistribute  it and/or modify it
7  *  under  the terms of  the GNU General  Public License as published by the
8  *  Free Software Foundation;  either version 2 of the  License, or (at your
9  *  option) any later version.
10  */
11 
12 #ifndef __LINUX_MFD_WM8350_COMPARATOR_H_
13 #define __LINUX_MFD_WM8350_COMPARATOR_H_
14 
15 /*
16  * Registers
17  */
18 
19 #define WM8350_DIGITISER_CONTROL_1              0x90
20 #define WM8350_DIGITISER_CONTROL_2              0x91
21 #define WM8350_AUX1_READBACK                    0x98
22 #define WM8350_AUX2_READBACK                    0x99
23 #define WM8350_AUX3_READBACK                    0x9A
24 #define WM8350_AUX4_READBACK                    0x9B
25 #define WM8350_CHIP_TEMP_READBACK               0x9F
26 #define WM8350_GENERIC_COMPARATOR_CONTROL       0xA3
27 #define WM8350_GENERIC_COMPARATOR_1             0xA4
28 #define WM8350_GENERIC_COMPARATOR_2             0xA5
29 #define WM8350_GENERIC_COMPARATOR_3             0xA6
30 #define WM8350_GENERIC_COMPARATOR_4             0xA7
31 
32 /*
33  * R144 (0x90) - Digitiser Control (1)
34  */
35 #define WM8350_AUXADC_CTC                       0x4000
36 #define WM8350_AUXADC_POLL                      0x2000
37 #define WM8350_AUXADC_HIB_MODE                  0x1000
38 #define WM8350_AUXADC_SEL8                      0x0080
39 #define WM8350_AUXADC_SEL7                      0x0040
40 #define WM8350_AUXADC_SEL6                      0x0020
41 #define WM8350_AUXADC_SEL5                      0x0010
42 #define WM8350_AUXADC_SEL4                      0x0008
43 #define WM8350_AUXADC_SEL3                      0x0004
44 #define WM8350_AUXADC_SEL2                      0x0002
45 #define WM8350_AUXADC_SEL1                      0x0001
46 
47 /*
48  * R145 (0x91) - Digitiser Control (2)
49  */
50 #define WM8350_AUXADC_MASKMODE_MASK             0x3000
51 #define WM8350_AUXADC_CRATE_MASK                0x0700
52 #define WM8350_AUXADC_CAL                       0x0004
53 #define WM8350_AUX_RBMODE                       0x0002
54 #define WM8350_AUXADC_WAIT                      0x0001
55 
56 /*
57  * R152 (0x98) - AUX1 Readback
58  */
59 #define WM8350_AUXADC_SCALE1_MASK               0x6000
60 #define WM8350_AUXADC_REF1                      0x1000
61 #define WM8350_AUXADC_DATA1_MASK                0x0FFF
62 
63 /*
64  * R153 (0x99) - AUX2 Readback
65  */
66 #define WM8350_AUXADC_SCALE2_MASK               0x6000
67 #define WM8350_AUXADC_REF2                      0x1000
68 #define WM8350_AUXADC_DATA2_MASK                0x0FFF
69 
70 /*
71  * R154 (0x9A) - AUX3 Readback
72  */
73 #define WM8350_AUXADC_SCALE3_MASK               0x6000
74 #define WM8350_AUXADC_REF3                      0x1000
75 #define WM8350_AUXADC_DATA3_MASK                0x0FFF
76 
77 /*
78  * R155 (0x9B) - AUX4 Readback
79  */
80 #define WM8350_AUXADC_SCALE4_MASK               0x6000
81 #define WM8350_AUXADC_REF4                      0x1000
82 #define WM8350_AUXADC_DATA4_MASK                0x0FFF
83 
84 /*
85  * R156 (0x9C) - USB Voltage Readback
86  */
87 #define WM8350_AUXADC_DATA_USB_MASK             0x0FFF
88 
89 /*
90  * R157 (0x9D) - LINE Voltage Readback
91  */
92 #define WM8350_AUXADC_DATA_LINE_MASK            0x0FFF
93 
94 /*
95  * R158 (0x9E) - BATT Voltage Readback
96  */
97 #define WM8350_AUXADC_DATA_BATT_MASK            0x0FFF
98 
99 /*
100  * R159 (0x9F) - Chip Temp Readback
101  */
102 #define WM8350_AUXADC_DATA_CHIPTEMP_MASK        0x0FFF
103 
104 /*
105  * R163 (0xA3) - Generic Comparator Control
106  */
107 #define WM8350_DCMP4_ENA                        0x0008
108 #define WM8350_DCMP3_ENA                        0x0004
109 #define WM8350_DCMP2_ENA                        0x0002
110 #define WM8350_DCMP1_ENA                        0x0001
111 
112 /*
113  * R164 (0xA4) - Generic comparator 1
114  */
115 #define WM8350_DCMP1_SRCSEL_MASK                0xE000
116 #define WM8350_DCMP1_GT                         0x1000
117 #define WM8350_DCMP1_THR_MASK                   0x0FFF
118 
119 /*
120  * R165 (0xA5) - Generic comparator 2
121  */
122 #define WM8350_DCMP2_SRCSEL_MASK                0xE000
123 #define WM8350_DCMP2_GT                         0x1000
124 #define WM8350_DCMP2_THR_MASK                   0x0FFF
125 
126 /*
127  * R166 (0xA6) - Generic comparator 3
128  */
129 #define WM8350_DCMP3_SRCSEL_MASK                0xE000
130 #define WM8350_DCMP3_GT                         0x1000
131 #define WM8350_DCMP3_THR_MASK                   0x0FFF
132 
133 /*
134  * R167 (0xA7) - Generic comparator 4
135  */
136 #define WM8350_DCMP4_SRCSEL_MASK                0xE000
137 #define WM8350_DCMP4_GT                         0x1000
138 #define WM8350_DCMP4_THR_MASK                   0x0FFF
139 
140 /*
141  * Interrupts.
142  */
143 #define WM8350_IRQ_AUXADC_DATARDY		16
144 #define WM8350_IRQ_AUXADC_DCOMP4		17
145 #define WM8350_IRQ_AUXADC_DCOMP3		18
146 #define WM8350_IRQ_AUXADC_DCOMP2		19
147 #define WM8350_IRQ_AUXADC_DCOMP1		20
148 #define WM8350_IRQ_SYS_HYST_COMP_FAIL		21
149 #define WM8350_IRQ_SYS_CHIP_GT115		22
150 #define WM8350_IRQ_SYS_CHIP_GT140		23
151 
152 /*
153  * USB/2, LINE & BATT = ((VRTC * 2) / 4095)) * 10e6 uV
154  * Where VRTC = 2.7 V
155  */
156 #define WM8350_AUX_COEFF			1319
157 
158 #define WM8350_AUXADC_AUX1			0
159 #define WM8350_AUXADC_AUX2			1
160 #define WM8350_AUXADC_AUX3			2
161 #define WM8350_AUXADC_AUX4			3
162 #define WM8350_AUXADC_USB			4
163 #define WM8350_AUXADC_LINE			5
164 #define WM8350_AUXADC_BATT			6
165 #define WM8350_AUXADC_TEMP			7
166 
167 struct wm8350;
168 
169 /*
170  * AUX ADC Readback
171  */
172 int wm8350_read_auxadc(struct wm8350 *wm8350, int channel, int scale,
173 		       int vref);
174 
175 #endif
176