summaryrefstree
path: root/kernel/include/linux/battery/charger/max77843_charger.h
blob: e3145e9bbe5ae759e3c8c9d8d0da2825de360065 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
 * max77843_charger.h
 * Samsung MAX77843 Charger Header
 *
 * Copyright (C) 2012 Samsung Electronics, Inc.
 *
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef __MAX77843_CHARGER_H
#define __MAX77843_CHARGER_H __FILE__

#include <linux/mfd/core.h>
#include <linux/mfd/max77843.h>
#include <linux/mfd/max77843-private.h>
#include <linux/regulator/machine.h>

#define WC_CURRENT_STEP		100
#define WC_CURRENT_START	500

enum {
	CHIP_ID = 0,
};

ssize_t max77843_chg_show_attrs(struct device *dev,
				struct device_attribute *attr, char *buf);

ssize_t max77843_chg_store_attrs(struct device *dev,
				struct device_attribute *attr,
				const char *buf, size_t count);

#define MAX77843_CHARGER_ATTR(_name)				\
{							\
	.attr = {.name = #_name, .mode = 0664},	\
	.show = max77843_chg_show_attrs,			\
	.store = max77843_chg_store_attrs,			\
}

enum {
	CHG_REG = 0,
	CHG_DATA,
	CHG_REGS,
};

extern sec_battery_platform_data_t sec_battery_pdata;

#define MAX77843_CHG_SAFEOUT2                0x80

/* MAX77843_CHG_REG_CHG_INT */
#define MAX77843_BYP_I                  (1 << 0)
#define MAX77843_BATP_I                 (1 << 2)
#define MAX77843_BAT_I                  (1 << 3)
#define MAX77843_CHG_I                  (1 << 4)
#define MAX77843_WCIN_I                 (1 << 5)
#define MAX77843_CHGIN_I                (1 << 6)
#define MAX77843_AICL_I                 (1 << 7)

/* MAX77843_CHG_REG_CHG_INT_MASK */
#define MAX77843_BYP_IM                 (1 << 0)
#define MAX77843_BATP_IM                (1 << 2)
#define MAX77843_BAT_IM                 (1 << 3)
#define MAX77843_CHG_IM                 (1 << 4)
#define MAX77843_WCIN_IM                (1 << 5)
#define MAX77843_CHGIN_IM               (1 << 6)
#define MAX77843_AICL_IM                (1 << 7)

/* MAX77843_CHG_REG_CHG_INT_OK */
#define MAX77843_BYP_OK                 0x01
#define MAX77843_BYP_OK_SHIFT           0
#define MAX77843_BATP_OK		0x04
#define MAX77843_BATP_OK_SHIFT		2
#define MAX77843_BAT_OK                 0x08
#define MAX77843_BAT_OK_SHIFT           3
#define MAX77843_CHG_OK                 0x10
#define MAX77843_CHG_OK_SHIFT           4
#define MAX77843_WCIN_OK		0x20
#define MAX77843_WCIN_OK_SHIFT		5
#define MAX77843_CHGIN_OK               0x40
#define MAX77843_CHGIN_OK_SHIFT         6
#define MAX77843_DETBAT                 0x04
#define MAX77843_DETBAT_SHIFT           2

/* MAX77843_CHG_REG_CHG_DTLS_00 */
#define MAX77843_BATP_DTLS		0x01
#define MAX77843_BATP_DTLS_SHIFT	0
#define MAX77843_WCIN_DTLS		0x18
#define MAX77843_WCIN_DTLS_SHIFT	3
#define MAX77843_CHGIN_DTLS             0x60
#define MAX77843_CHGIN_DTLS_SHIFT       5

/* MAX77843_CHG_REG_CHG_DTLS_01 */
#define MAX77843_CHG_DTLS               0x0F
#define MAX77843_CHG_DTLS_SHIFT         0
#define MAX77843_BAT_DTLS               0x70
#define MAX77843_BAT_DTLS_SHIFT         4

/* MAX77843_CHG_REG_CHG_DTLS_02 */
#define MAX77843_BYP_DTLS               0x0F
#define MAX77843_BYP_DTLS_SHIFT         0
#define MAX77843_BYP_DTLS0      0x1
#define MAX77843_BYP_DTLS1      0x2
#define MAX77843_BYP_DTLS2      0x4
#define MAX77843_BYP_DTLS3      0x8

/* MAX77843_CHG_REG_CHG_CNFG_00 */
#define CHG_CNFG_00_MODE_SHIFT		        0
#define CHG_CNFG_00_CHG_SHIFT		        0
#define CHG_CNFG_00_OTG_SHIFT		        1
#define CHG_CNFG_00_BUCK_SHIFT		        2
#define CHG_CNFG_00_BOOST_SHIFT		        3
#define CHG_CNFG_00_MODE_MASK		        (0xf << CHG_CNFG_00_MODE_SHIFT)
#define CHG_CNFG_00_CHG_MASK		        (1 << CHG_CNFG_00_CHG_SHIFT)
#define CHG_CNFG_00_OTG_MASK		        (1 << CHG_CNFG_00_OTG_SHIFT)
#define CHG_CNFG_00_BUCK_MASK		        (1 << CHG_CNFG_00_BUCK_SHIFT)
#define CHG_CNFG_00_BOOST_MASK		        (1 << CHG_CNFG_00_BOOST_SHIFT)
#define CHG_CNFG_00_OTG_CTRL			(CHG_CNFG_00_OTG_MASK | CHG_CNFG_00_BOOST_MASK)
#define MAX77843_MODE_DEFAULT                   0x04
#define MAX77843_MODE_CHGR                      0x01
#define MAX77843_MODE_OTG                       0x02
#define MAX77843_MODE_BUCK                      0x04
#define MAX77843_MODE_BOOST		        0x08
#define MAX77843_WDTEN				0x10

/* MAX&7843_CHG_REG_CHG_CNFG_01 */
#define MAX77843_CHG_FQ_2MHz                    (1 << 3)
/* MAX77843_CHG_REG_CHG_CNFG_02 */
#define MAX77843_CHG_CC                         0x3F

/* MAX77843_CHG_REG_CHG_CNFG_03 */
#define MAX77843_CHG_TO_ITH		        0x07

/* MAX77843_CHG_REG_CHG_CNFG_04 */
#define MAX77843_CHG_MINVSYS_MASK               0xE0
#define MAX77843_CHG_MINVSYS_SHIFT              5
#define MAX77843_CHG_PRM_MASK                   0x1F
#define MAX77843_CHG_PRM_SHIFT                  0

#define CHG_CNFG_04_CHG_CV_PRM_SHIFT            0
#define CHG_CNFG_04_CHG_CV_PRM_MASK             (0x3F << CHG_CNFG_04_CHG_CV_PRM_SHIFT)

/* MAX77843_CHG_REG_CHG_CNFG_06 */
#define CHG_CNFG_06_WDTCLR_MASK			0x03
#define MAX77843_WDTCLR				0x01

/* MAX77843_CHG_REG_CHG_CNFG_09 */
#define MAX77843_CHG_CHGIN_LIM                  0x7F

/* MAX77843_CHG_REG_CHG_CNFG_10 */
#define MAX77843_CHG_WCIN_LIM                   0x3F

/* MAX77843_CHG_REG_CHG_CNFG_12 */
#define MAX77843_CHG_WCINSEL		        0x40
#define CHG_CNFG_12_CHGINSEL_SHIFT			5
#define CHG_CNFG_12_CHGINSEL_MASK			(0x1 << CHG_CNFG_12_CHGINSEL_SHIFT)

/* MAX77843_CHG_REG_CHG_DTLS_00 */
#define MAX77843_BATP_DTLS		        0x01
#define MAX77843_BATP_DTLS_SHIFT	        0
#define MAX77843_WCIN_DTLS		        0x18
#define MAX77843_WCIN_DTLS_SHIFT	        3
#define MAX77843_CHGIN_DTLS                     0x60
#define MAX77843_CHGIN_DTLS_SHIFT               5

/* MAX77843_CHG_DETAILS_01 */
#define MAX77843_CHG_DTLS                       0x0F
#define MAX77843_CHG_DTLS_SHIFT                 0
#define MAX77843_BAT_DTLS                       0x70
#define MAX77843_BAT_DTLS_SHIFT                 4

#define REDUCE_CURRENT_STEP						100
#define MINIMUM_INPUT_CURRENT					300
#define SIOP_INPUT_LIMIT_CURRENT                1200
#define SIOP_CHARGING_LIMIT_CURRENT             1000
#define SIOP_WIRELESS_INPUT_LIMIT_CURRENT       530
#define SIOP_WIRELESS_CHARGING_LIMIT_CURRENT    780
#define SLOW_CHARGING_CURRENT_STANDARD          400
#define STORE_MODE_INPUT_CURRENT                440

#define INPUT_CURRENT_TA		                1000
struct max77843_charger_data {
	struct device           *dev;
	struct i2c_client       *i2c;
	struct i2c_client       *pmic_i2c;
	struct mutex            charger_mutex;

	struct max77843_platform_data *max77843_pdata;

	struct power_supply	psy_chg;
	struct power_supply	psy_otg;

	struct workqueue_struct *wqueue;
	struct work_struct	chgin_work;
	struct delayed_work	isr_work;
	struct delayed_work	recovery_work;	/*  softreg recovery work */
	struct delayed_work	wpc_work;	/*  wpc detect work */
	struct delayed_work	chgin_init_work;	/*  chgin init work */
	struct delayed_work afc_work;
	struct delayed_work	aicl_work;
	struct delayed_work wc_current_work;

/* mutex */
	struct mutex irq_lock;
	struct mutex ops_lock;

	/* wakelock */
	struct wake_lock recovery_wake_lock;
	struct wake_lock wpc_wake_lock;
	struct wake_lock wpc_curr_wake_lock;
	struct wake_lock afc_wake_lock;
	struct wake_lock chgin_wake_lock;
	struct wake_lock aicl_wake_lock;
	struct wake_lock wc_current_wake_lock;

	unsigned int	is_charging;
	unsigned int	charging_type;
	unsigned int	battery_state;
	unsigned int	battery_present;
	unsigned int	cable_type;
	unsigned int	batt_cable_type;
	unsigned int	charging_current_max;
	unsigned int	charging_current;
	unsigned int	input_current_limit;
	unsigned int	vbus_state;
	int		aicl_on;
	int		status;
	int		siop_level;
	int uvlo_attach_flag;
	int uvlo_attach_cable_type;

	int		irq_bypass;
	int		irq_batp;
	int		irq_aicl;
	int		irq_aicl_enabled;

	int		irq_battery;
	int		irq_chg;
	int		irq_wcin;
	int		irq_chgin;

	/* software regulation */
	bool		soft_reg_state;
	int		soft_reg_current;

	/* unsufficient power */
	bool		reg_loop_deted;
	bool		is_lcd_on;
	bool		is_call_on;

	/* wireless charge, w(wpc), v(vbus) */
	int		wc_w_gpio;
	int		wc_w_irq;
	int		wc_w_state;
	int		wc_v_gpio;
	int		wc_v_irq;
	int		wc_v_state;
	bool		wc_pwr_det;
	int		soft_reg_recovery_cnt;
	int		wc_current;
	int		wc_pre_current;

	int vbus_changing;
	bool afc_detect;
	bool is_mdock;
	bool store_mode;

	int pmic_ver;
	int input_curr_limit_step;
	int wpc_input_curr_limit_step;
	int charging_curr_step;

	sec_charger_platform_data_t	*pdata;
};

#endif /* __MAX77843_CHARGER_H */