summaryrefstree
path: root/kernel/include/linux/battery/charger/max77693_charger.h
blob: 8e2e5cbe3e287be599bd6663add39f4d15a893c4 (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
/*
 * MAX77693_charger.h
 * Samsung MAX77693 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 __MAX77693_CHARGER_H
#define __MAX77693_CHARGER_H __FILE__
#include <linux/mfd/core.h>
#include <linux/mfd/max77693.h>
#include <linux/mfd/max77693-private.h>
#include <linux/regulator/machine.h>

#define ENABLE 1
#define DISABLE 0

/* macro */
#define MAX(x, y)	((x) > (y) ? (x) : (y))
#define MIN(x, y)	((x) < (y) ? (x) : (y))
#define ABS(x)		((x) < 0 ? (-1 * (x)) : (x))
/*
 * Use for battery
 */
#define OFF_CURR	0	/* charger off current */
#define KEEP_CURR	-1	/* keep previous current */

/* MAX77693_CHG_REG_CHG_INT */
#define MAX77693_BYP_I                  (1 << 0)
#define MAX77693_BATP_I			(1 << 2)
#define MAX77693_BAT_I                  (1 << 3)
#define MAX77693_CHG_I                  (1 << 4)
#define MAX77693_WCIN_I			(1 << 5)
#define MAX77693_CHGIN_I                (1 << 6)

/* MAX77693_CHG_REG_CHG_INT_MASK */
#define MAX77693_BYP_IM                 (1 << 0)
#define MAX77693_THM_IM                 (1 << 2)
#define MAX77693_BAT_IM                 (1 << 3)
#define MAX77693_CHG_IM                 (1 << 4)
#define MAX77693_WCIN_IM		(1 << 5)
#define MAX77693_CHGIN_IM               (1 << 6)

/* MAX77693_CHG_REG_CHG_INT_OK */
#define MAX77693_BYP_OK                 0x01
#define MAX77693_BYP_OK_SHIFT           0
#define MAX77693_BATP_OK		0x04
#define MAX77693_BATP_OK_SHIFT		2
#define MAX77693_BAT_OK                 0x08
#define MAX77693_BAT_OK_SHIFT           3
#define MAX77693_CHG_OK                 0x10
#define MAX77693_CHG_OK_SHIFT           4
#define MAX77693_WCIN_OK		0x20
#define MAX77693_WCIN_OK_SHIFT		5
#define MAX77693_CHGIN_OK               0x40
#define MAX77693_CHGIN_OK_SHIFT         6
#define MAX77693_DETBAT                 0x04
#define MAX77693_DETBAT_SHIFT           2

/* MAX77693_CHG_REG_CHG_DTLS_00 */
#define MAX77693_BATP_DTLS		0x01
#define MAX77693_BATP_DTLS_SHIFT	0
#define MAX77693_WCIN_DTLS		0x18
#define MAX77693_WCIN_DTLS_SHIFT	3
#define MAX77693_CHGIN_DTLS             0x60
#define MAX77693_CHGIN_DTLS_SHIFT       5

/* MAX77693_CHG_REG_CHG_DTLS_01 */
#define MAX77693_CHG_DTLS               0x0F
#define MAX77693_CHG_DTLS_SHIFT         0
#define MAX77693_BAT_DTLS               0x70
#define MAX77693_BAT_DTLS_SHIFT         4

/* MAX77693_CHG_REG_CHG_DTLS_02 */
#define MAX77693_BYP_DTLS               0x0F
#define MAX77693_BYP_DTLS_SHIFT         0
#define MAX77693_BYP_DTLS0      0x1
#define MAX77693_BYP_DTLS1      0x2
#define MAX77693_BYP_DTLS2      0x4
#define MAX77693_BYP_DTLS3      0x8

/* MAX77693_CHG_REG_CHG_CNFG_00 */
#define MAX77693_MODE_DEFAULT   0x04
#define MAX77693_MODE_CHGR      0x01
#define MAX77693_MODE_OTG       0x02
#define MAX77693_MODE_BUCK      0x04

/* MAX77693_CHG_REG_CHG_CNFG_02 */
#define MAX77693_CHG_CC         0x3F

/* MAX77693_CHG_REG_CHG_CNFG_03 */
#define MAX77693_CHG_TO_ITH		0x07

/* MAX77693_CHG_REG_CHG_CNFG_04 */
#define MAX77693_CHG_MINVSYS_MASK       0xE0
#define MAX77693_CHG_MINVSYS_SHIFT      5
#define MAX77693_CHG_PRM_MASK           0x1F
#define MAX77693_CHG_PRM_SHIFT          0

/* MAX77693_CHG_REG_CHG_CNFG_09 */
#define MAX77693_CHG_CHGIN_LIM  0x7F

/* MAX77693_CHG_REG_CHG_CNFG_12 */
#define MAX77693_CHG_WCINSEL		0x40

/* MAX77693_MUIC_REG_CDETCTRL1 */
#define MAX77693_CHGTYPMAN              0x02
#define MAX77693_CHGTYPMAN_SHIFT        1

/* MAX77693_MUIC_REG_STATUS2 */
#define MAX77693_VBVOLT                 0x40
#define MAX77693_VBVOLT_SHIFT           6
#define MAX77693_CHGDETRUN              0x08
#define MAX77693_CHGDETRUN_SHIFT        3
#define MAX77693_CHGTYPE                0x07
#define MAX77693_CHGTYPE_SHIFT          0

/* irq */
#define IRQ_DEBOUNCE_TIME       20      /* msec */

/* charger type detection */
#define DET_ERR_RETRY   5
#define DET_ERR_DELAY   200

/* soft charging */
#define SOFT_CHG_START_CURR     100     /* mA */
#define SOFT_CHG_START_DUR      100     /* ms */
#define SOFT_CHG_CURR_STEP      100     /* mA */
#define SOFT_CHG_STEP_DUR       20      /* ms */

#define DEFAULT_AC_CURRENT	1600	/* mA */
#define DEFAULT_USB_CURRENT	500	/* mA */

enum {
	POWER_SUPPLY_VBUS_UNKNOWN = 0,
	POWER_SUPPLY_VBUS_UVLO,
	POWER_SUPPLY_VBUS_WEAK,
	POWER_SUPPLY_VBUS_OVLO,
	POWER_SUPPLY_VBUS_GOOD,
};

extern sec_battery_platform_data_t sec_battery_pdata;
#endif