power: rk81x-battery: update verison to 4.0.0
[firefly-linux-kernel-4.4.55.git] / include / linux / mfd / rk818.h
1 /* include/linux/regulator/rk818.h
2  *
3  * This software is licensed under the terms of the GNU General Public
4  * License version 2, as published by the Free Software Foundation, and
5  * may be copied, distributed, and modified under those terms.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  */
13 #ifndef __LINUX_REGULATOR_rk818_H
14 #define __LINUX_REGULATOR_rk818_H
15
16 #include <linux/regulator/machine.h>
17 #include <linux/wakelock.h>
18 #include <linux/power_supply.h>
19 //#include <linux/power/rk818_battery.h>
20
21 //#define RK818_START 30
22
23 #define RK818_DCDC1  0                     //(0+RK818_START) 
24
25 #define RK818_LDO1 4                //(4+RK818_START)
26
27 #define RK818_SECONDS_REG 0x00
28 #define RK818_MINUTES_REG 0x01
29 #define RK818_HOURS_REG 0x02
30 #define RK818_DAYS_REG 0x03
31 #define RK818_MONTHS_REG 0x04
32 #define RK818_YEARS_REG 0x05
33 #define RK818_WEEKS_REG 0x06
34 #define RK818_ALARM_SECONDS_REG 0x07
35 #define RK818_ALARM_MINUTES_REG 0x08
36 #define RK818_ALARM_HOURS_REG 0x09
37 #define RK818_ALARM_DAYS_REG 0x0a
38 #define RK818_ALARM_MONTHS_REG 0x0b
39 #define RK818_ALARM_YEARS_REG 0x0c
40 #define RK818_RTC_CTRL_REG 0x10
41 #define RK818_RTC_STATUS_REG 0x11
42 #define RK818_RTC_INT_REG 0x12
43 #define RK818_RTC_COMP_LSB_REG 0x13
44 #define RK818_RTC_COMP_MSB_REG 0x14
45 #define RK818_CLK32OUT_REG 0x20
46 #define RK818_VB_MON_REG 0x21
47 #define RK818_THERMAL_REG 0x22
48 #define RK818_DCDC_EN_REG 0x23
49 #define RK818_LDO_EN_REG 0x24
50 #define RK818_SLEEP_SET_OFF_REG1 0x25
51 #define RK818_SLEEP_SET_OFF_REG2 0x26
52 #define RK818_DCDC_UV_STS_REG 0x27
53 #define RK818_DCDC_UV_ACT_REG 0x28
54 #define RK818_LDO_UV_STS_REG 0x29
55 #define RK818_LDO_UV_ACT_REG 0x2a
56 #define RK818_DCDC_PG_REG 0x2b
57 #define RK818_LDO_PG_REG 0x2c
58 #define RK818_VOUT_MON_TDB_REG 0x2d
59 #define RK818_BUCK1_CONFIG_REG 0x2e
60 #define RK818_BUCK1_ON_REG 0x2f
61 #define RK818_BUCK1_SLP_REG 0x30
62 #define RK818_BUCK2_CONFIG_REG 0x32
63 #define RK818_BUCK2_ON_REG 0x33
64 #define RK818_BUCK2_SLP_REG 0x34
65 #define RK818_BUCK3_CONFIG_REG 0x36
66 #define RK818_BUCK4_CONFIG_REG 0x37
67 #define RK818_BUCK4_ON_REG 0x38
68 #define RK818_BUCK4_SLP_VSEL_REG 0x39
69 #define RK818_BOOST_CONFIG_REG 0x3a
70 #define RK818_LDO1_ON_VSEL_REG 0x3b
71 #define RK818_LDO1_SLP_VSEL_REG 0x3c
72 #define RK818_LDO2_ON_VSEL_REG 0x3d
73 #define RK818_LDO2_SLP_VSEL_REG 0x3e
74 #define RK818_LDO3_ON_VSEL_REG 0x3f
75 #define RK818_LDO3_SLP_VSEL_REG 0x40
76 #define RK818_LDO4_ON_VSEL_REG 0x41
77 #define RK818_LDO4_SLP_VSEL_REG 0x42
78 #define RK818_LDO5_ON_VSEL_REG 0x43
79 #define RK818_LDO5_SLP_VSEL_REG 0x44
80 #define RK818_LDO6_ON_VSEL_REG 0x45
81 #define RK818_LDO6_SLP_VSEL_REG 0x46
82 #define RK818_LDO7_ON_VSEL_REG 0x47
83 #define RK818_LDO7_SLP_VSEL_REG 0x48
84 #define RK818_LDO8_ON_VSEL_REG 0x49
85 #define RK818_LDO8_SLP_VSEL_REG 0x4a
86 #define RK818_BOOST_LDO9_ON_VSEL_REG 0x54
87 #define RK818_BOOST_LDO9_SLP_VSEL_REG 0x55
88 #define RK818_DEVCTRL_REG 0x4b
89 #define RK818_INT_STS_REG1 0X4c
90 #define RK818_INT_STS_MSK_REG1 0X4d
91 #define RK818_INT_STS_REG2 0X4e
92 #define RK818_INT_STS_MSK_REG2 0X4f
93 #define RK818_IO_POL_REG 0X50
94
95 /* IRQ Definitions */
96 #define RK818_IRQ_VOUT_LO                       0
97 #define RK818_IRQ_VB_LO                         1
98 #define RK818_IRQ_PWRON                         2
99 #define RK818_IRQ_PWRON_LP                              3
100 #define RK818_IRQ_HOTDIE                                4
101 #define RK818_IRQ_RTC_ALARM                             5
102 #define RK818_IRQ_RTC_PERIOD                            6
103 #define RK818_IRQ_USB_OV                                7
104 #define RK818_IRQ_PLUG_IN                               8
105 #define RK818_IRQ_PLUG_OUT                              9
106 #define RK818_IRQ_CHG_OK                                10
107 #define RK818_IRQ_CHG_TE                                11
108 #define RK818_IRQ_CHG_TS1                               12
109 #define RK818_IRQ_TS2                           13
110 #define RK818_IRQ_CHG_CVTLIM            14
111 #define RK818_IRQ_DISCHG_ILIM                           6
112
113 #define RK818_NUM_IRQ  16
114
115 #define rk818_NUM_REGULATORS 14
116 struct rk818;
117
118
119 #define RK818_VBAT_LOW_2V8  0x00
120 #define RK818_VBAT_LOW_2V9  0x01
121 #define RK818_VBAT_LOW_3V0  0x02
122 #define RK818_VBAT_LOW_3V1  0x03
123 #define RK818_VBAT_LOW_3V2  0x04
124 #define RK818_VBAT_LOW_3V3  0x05
125 #define RK818_VBAT_LOW_3V4  0x06
126 #define RK818_VBAT_LOW_3V5  0x07
127 #define VBAT_LOW_VOL_MASK (0x07 << 0)
128 #define EN_VABT_LOW_SHUT_DOWN (0x00 << 4)
129 #define EN_VBAT_LOW_IRQ (0x1 <<4 )
130 #define VBAT_LOW_ACT_MASK (0x1 << 4)
131
132 struct rk818_board {
133         int irq;
134         int irq_base;
135         int irq_gpio;
136         int wakeup;
137         struct regulator_init_data *rk818_init_data[rk818_NUM_REGULATORS];
138         struct device_node *of_node[rk818_NUM_REGULATORS];
139         int pmic_sleep_gpio; /* */
140         unsigned int dcdc_slp_voltage[3]; /* buckx_voltage in uV */
141         bool pmic_sleep;
142         unsigned int ldo_slp_voltage[7];
143         bool pm_off;
144 };
145
146 struct rk818_regulator_subdev {
147         int id;
148         struct regulator_init_data *initdata;
149 };
150
151 struct rk818 {
152         struct device *dev;
153         struct mutex io_lock;
154         struct i2c_client *i2c;
155         int num_regulators;
156         struct regulator_dev **rdev;
157         struct wake_lock        irq_wake;
158         struct mutex irq_lock;
159         int irq_base;
160         int irq_num;
161         int chip_irq;
162         int irq_gpio;
163         int wakeup;
164         u32 irq_mask;
165         struct irq_domain *irq_domain;
166         int (*read)(struct rk818 *rk818, u8 reg, int size, void *dest);
167         int (*write)(struct rk818 *rk818, u8 reg, int size, void *src);
168         struct battery_platform_data *battery_data;
169         int pmic_sleep_gpio; /* */
170         unsigned int dcdc_slp_voltage[3]; /* buckx_voltage in uV */
171         bool pmic_sleep;
172         unsigned int ldo_slp_voltage[7];
173 };
174
175 struct rk818_platform_data {
176         int num_regulators;
177         struct rk818_regulator_subdev *regulators;
178         struct battery_platform_data *battery_data;
179         int irq;
180         int irq_base;
181         struct irq_domain *irq_domain;
182 };
183
184 int rk818_irq_init(struct rk818 *rk818, int irq,struct rk818_board *pdata);
185 int rk818_i2c_read(struct rk818 *rk818, char reg, int count,u8 *dest);
186 //int rk818_i2c_read(struct i2c_client *i2c, char reg, int count,u16 *dest);
187 // int rk818_i2c_read(struct rk818 *rk818 , u8 reg, int bytes,void *dest); 
188 int rk818_i2c_write(struct rk818 *rk818, char reg, int count, const u8 src);
189 int rk818_set_bits(struct rk818 *rk818, u8 reg, u8 mask, u8 val);
190 int rk818_clear_bits(struct rk818 *rk818, u8 reg, u8 mask);
191 u8 rk818_reg_read(struct rk818 *rk818, u8 reg);
192 int rk818_reg_write(struct rk818 *rk818, u8 reg, u8 val);
193 int rk818_bulk_read(struct rk818 *rk818, u8 reg,
194                      int count, u8 *buf);
195 int rk818_bulk_write(struct rk818 *rk818, u8 reg,
196                      int count, u8 *buf);
197 void rk818_device_shutdown(void);
198
199 #endif
200