5f711443bb6cd3177d8203e423befd7fc7ba37c8
[firefly-linux-kernel-4.4.55.git] / include / linux / power / cw2015_battery.h
1 /*
2  * Fuel gauge driver for CellWise 2013 / 2015
3  *
4  * Copyright (C) 2012, RockChip
5  *
6  * Authors: xuhuicong <xhc@rock-chips.com>
7  *
8  * Based on rk30_adc_battery.c
9
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  *
14  */
15
16 #ifndef CW2015_BATTERY_H
17 #define CW2015_BATTERY_H
18
19 #define SIZE_BATINFO    64
20
21 #define CW2015_GPIO_HIGH  1
22 #define CW2015_GPIO_LOW   0
23
24 #define REG_VERSION             0x0
25 #define REG_VCELL               0x2
26 #define REG_SOC                 0x4
27 #define REG_RRT_ALERT           0x6
28 #define REG_CONFIG              0x8
29 #define REG_MODE                0xA
30 #define REG_BATINFO             0x10
31
32 #define MODE_SLEEP_MASK         (0x3<<6)
33 #define MODE_SLEEP              (0x3<<6)
34 #define MODE_NORMAL             (0x0<<6)
35 #define MODE_QUICK_START        (0x3<<4)
36 #define MODE_RESTART            (0xf<<0)
37
38 #define CONFIG_UPDATE_FLG       (0x1<<1)
39 #define ATHD                    (0x0<<3)
40
41 #define CW_I2C_SPEED            100000
42 #define BATTERY_UP_MAX_CHANGE   420
43 #define BATTERY_DOWN_CHANGE   60
44 #define BATTERY_DOWN_MIN_CHANGE_RUN 30
45 #define BATTERY_DOWN_MIN_CHANGE_SLEEP 1800
46
47 #define BATTERY_DOWN_MAX_CHANGE_RUN_AC_ONLINE 3600
48
49 #define NO_STANDARD_AC_BIG_CHARGE_MODE 1
50 /* #define SYSTEM_SHUTDOWN_VOLTAGE  3400000 */
51 #define BAT_LOW_INTERRUPT    1
52
53 #define USB_CHARGER_MODE        1
54 #define AC_CHARGER_MODE         2
55 #define   CW_QUICKSTART         0
56
57 struct cw_bat_platform_data {
58         int is_dc_charge;
59         int dc_det_pin;
60         int dc_det_level;
61
62         int is_usb_charge;
63         int chg_mode_sel_pin;
64         int chg_mode_sel_level;
65
66         int bat_low_pin;
67         int bat_low_level;
68         int chg_ok_pin;
69         int chg_ok_level;
70         u32 *cw_bat_config_info;
71 };
72
73 struct cw_battery {
74         struct i2c_client *client;
75         struct workqueue_struct *battery_workqueue;
76         struct delayed_work battery_delay_work;
77         struct delayed_work dc_wakeup_work;
78         struct delayed_work bat_low_wakeup_work;
79         struct cw_bat_platform_data plat_data;
80
81         struct power_supply rk_bat;
82         struct power_supply rk_ac;
83         struct power_supply rk_usb;
84
85         long sleep_time_capacity_change;
86         long run_time_capacity_change;
87
88         long sleep_time_charge_start;
89         long run_time_charge_start;
90
91         int dc_online;
92         int usb_online;
93         int charger_mode;
94         int charger_init_mode;
95         int capacity;
96         int voltage;
97         int status;
98         int time_to_empty;
99         int alt;
100
101         int bat_change;
102 };
103
104 #if defined(CONFIG_ARCH_ROCKCHIP)
105 int get_gadget_connect_flag(void);
106 int dwc_otg_check_dpdm(void);
107 void rk_send_wakeup_key(void);
108 int dwc_vbus_status(void);
109 #else
110 static inline int get_gadget_connect_flag(void)
111 {
112         return 0;
113 }
114
115 static inline int dwc_otg_check_dpdm(bool wait)
116 {
117         return 0;
118 }
119
120 static inline void rk_send_wakeup_key(void)
121 {
122 }
123
124 static inline int dwc_vbus_status(void);
125 {
126         return 0;
127 }
128 #endif
129
130 #endif