Merge branch 'linux-linaro-lsk-v4.4-android' of git://git.linaro.org/kernel/linux...
[firefly-linux-kernel-4.4.55.git] / include / linux / i2c / twl6030-gpadc.h
1 /*
2  * include/linux/i2c/twl6030-gpadc.h
3  *
4  * TWL6030 GPADC module driver header
5  *
6  * Copyright (C) 2009 Texas Instruments Inc.
7  * Nishant Kamat <nskamat@ti.com>
8  *
9  * Based on twl4030-madc.h
10  * Copyright (C) 2008 Nokia Corporation
11  * Mikko Ylinen <mikko.k.ylinen@nokia.com>
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * version 2 as published by the Free Software Foundation.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25  * 02110-1301 USA
26  *
27  */
28
29 #ifndef _TWL6030_GPADC_H
30 #define _TWL6030_GPADC_H
31
32 struct twl6030_gpadc_conversion_method {
33         u8 sel;
34         u8 rbase;
35         u8 ctrl;
36         u8 enable;
37         u8 mask;
38 };
39
40 #define TWL6030_GPADC_MAX_CHANNELS 17
41 #define TWL6032_GPADC_MAX_CHANNELS 19
42 /* Define this as the biggest of all chips using this driver */
43 #define GPADC_MAX_CHANNELS TWL6032_GPADC_MAX_CHANNELS
44
45 /*
46  * raw_code - raw adc value
47  * raw_channel_value - adc * channel gain
48  * code - calibrated adc value
49  */
50 struct twl6030_value {
51         int raw_code;
52         int raw_channel_value;
53         int code;
54 };
55
56 struct twl6030_gpadc_request {
57         u32 channels;
58         u16 do_avg;
59         u16 method;
60         u16 type;
61         int active;
62         int result_pending;
63         int rbuf[TWL6032_GPADC_MAX_CHANNELS];
64         void (*func_cb)(struct twl6030_gpadc_request *req);
65         struct twl6030_value buf[TWL6032_GPADC_MAX_CHANNELS];
66 };
67
68 enum conversion_methods {
69         TWL6030_GPADC_RT,
70         TWL6030_GPADC_SW2,
71         TWL6030_GPADC_NUM_METHODS
72 };
73
74 enum sample_type {
75         TWL6030_GPADC_WAIT,
76         TWL6030_GPADC_IRQ_ONESHOT,
77         TWL6030_GPADC_IRQ_REARM
78 };
79
80 #define TWL6030_GPADC_CTRL              0x00    /* 0x2e */
81 #define TWL6030_GPADC_CTRL2             0x01    /* 0x2f */
82
83 #define TWL6030_GPADC_RTSELECT_LSB      0x02    /* 0x30 */
84 #define TWL6030_GPADC_RTSELECT_ISB      0x03
85 #define TWL6030_GPADC_RTSELECT_MSB      0x04
86
87 #define TWL6032_GPADC_RTSELECT_LSB      0x04    /* 0x32 */
88 #define TWL6032_GPADC_RTSELECT_ISB      0x05
89 #define TWL6032_GPADC_RTSELECT_MSB      0x06
90
91 #define TWL6030_GPADC_CTRL_P1           0x05
92 #define TWL6030_GPADC_CTRL_P2           0x06
93
94 #define TWL6032_GPADC_GPSELECT_ISB      0x07
95 #define TWL6032_GPADC_CTRL_P1           0x08
96
97 #define TWL6032_RTCH0_LSB                       0x09
98 #define TWL6032_RTCH0_MSB                       0x0a
99 #define TWL6032_RTCH1_LSB                       0x0b
100 #define TWL6032_RTCH1_MSB                       0x0c
101 #define TWL6032_GPCH0_LSB                       0x0d
102 #define TWL6032_GPCH0_MSB                       0x0e
103
104 #define TWL6030_GPADC_CTRL_P1_SP1       (1 << 3)
105 #define TWL6030_GPADC_CTRL_P1_EOCRT     (1 << 2)
106 #define TWL6030_GPADC_CTRL_P1_EOCP1     (1 << 1)
107 #define TWL6030_GPADC_CTRL_P1_BUSY      (1 << 0)
108
109 #define TWL6030_GPADC_CTRL_P2_SP2       (1 << 2)
110 #define TWL6030_GPADC_CTRL_P2_EOCP2     (1 << 1)
111 #define TWL6030_GPADC_CTRL_P1_BUSY      (1 << 0)
112
113 #define TWL6030_GPADC_EOC_SW            (1 << 1)
114 #define TWL6030_GPADC_BUSY              (1 << 0)
115
116 #define TWL6030_GPADC_RTCH0_LSB         (0x07)
117 #define TWL6030_GPADC_GPCH0_LSB         (0x29)
118
119 /* Fixed channels */
120 #define TWL6030_GPADC_CTRL_TEMP1_EN     (1 << 0)    /* input ch 1 */
121 #define TWL6030_GPADC_CTRL_TEMP2_EN     (1 << 1)    /* input ch 4 */
122 #define TWL6030_GPADC_CTRL_SCALER_EN    (1 << 2)    /* input ch 2 */
123 #define TWL6030_GPADC_CTRL_SCALER_DIV4  (1 << 3)
124 #define TWL6030_GPADC_CTRL_SCALER_EN_CH11       (1 << 4)    /* input ch 11 */
125 #define TWL6030_GPADC_CTRL_TEMP1_EN_MONITOR     (1 << 5)
126 #define TWL6030_GPADC_CTRL_TEMP2_EN_MONITOR     (1 << 6)
127 #define TWL6030_GPADC_CTRL_ISOURCE_EN           (1 << 7)
128
129 #define TWL6030_GPADC_CTRL2_REMSENSE_0          (1 << 0)
130 #define TWL6030_GPADC_CTRL2_REMSENSE_1          (1 << 1)
131 #define TWL6030_GPADC_CTRL2_SCALER_EN_CH18      (1 << 2)
132 #define TWL6030_GPADC_CTRL2_VBAT_SCALER_DIV4    (1 << 3)
133
134 #define TWL6030_GPADC_RT_SW1_EOC_MASK           (1 << 5)
135 #define TWL6030_GPADC_SW2_EOC_MASK              (1 << 6)
136
137 #define TWL6032_GPADC_RT_EOC_MASK               (1 << 4)
138 #define TWL6032_GPADC_SW_EOC_MASK               (1 << 5)
139
140 #define TWL6030_GPADC_IOC_MAGIC '`'
141 #define TWL6030_GPADC_IOCX_ADC_RAW_READ _IO(TWL6030_GPADC_IOC_MAGIC, 0)
142 #define TWL6030_GPADC_IOCX_ADC_READ     _IO(TWL6030_GPADC_IOC_MAGIC+1, 0)
143
144 struct twl6030_gpadc_user_parms {
145         int channel;
146         int status;
147         u16 result;
148 };
149
150 int twl6030_gpadc_conversion(struct twl6030_gpadc_request *conv);
151
152 #endif