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
|
/*
* SM5701_core.h
* SiliconMitus SM5701 Charger Header
*
* Copyright (C) 2014 SiliconMitus
*
*
* 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 _sm5701_SW_H_
#define _sm5701_SW_H_
#include <linux/i2c.h>
#include <linux/power/sm5701.h>
#define MFD_DEV_NAME "sm5701"
/* Enable charger Operation Mode */
#define OP_MODE_CHG_ON 0x02
/* Disable charger Operation Mode */
#define OP_MODE_CHG_OFF 0x01
//FLEDCNTL1
#define SM5701_FLEDCNTL1_FLEDEN 0x03
#define SM5701_FLEDCNTL1_ABSTMR 0x0B
#define SM5701_FLEDCNTL1_ENABSTMR 0x10
//FLEDCNTL2
#define SM5701_FLEDCNTL2_ONETIMER 0x0F
#define SM5701_FLEDCNTL2_nONESHOT 0x10
#define SM5701_FLEDCNTL2_SAFET 0x60
#define SM5701_FLEDCNTL2_nENSAFET 0x80
//FLEDCNTL3
#define SM5701_FLEDCNTL3_IFLED 0x1F
//FLEDCNTL4
#define SM5701_FLEDCNTL4_IMLED 0x1F
//FLEDCNTL5
#define SM5701_FLEDCNTL5_LBDHYS 0x03
#define SM5701_FLEDCNTL5_LOWBATT 0x1B
#define SM5701_FLEDCNTL5_LBRSTIMER 0x60
#define SM5701_FLEDCNTL5_ENLOWBATT 0x80
//FLEDCNTL6
#define SM5701_FLEDCNTL6_BSTOUT 0x0F
#define SM5701_BSTOUT_4P5 0x05
#define SM5701_BSTOUT_5P0 0x0A
/**
* struct sm5701_dev
* @dev: master device of the chip (can be used to access platform data)
* @i2c: i2c client private data
* @iolock: mutex for serializing io access
* @irq_base: base IRQ number for sm5701, required for IRQs
* @irq: generic IRQ number for sm5701
*/
struct SM5701_dev {
struct device *dev;
struct i2c_client *i2c;
struct mutex i2c_lock;
struct mutex irqlock;
int type;
int irq;
int irq_base;
int irq_gpio;
int irqf_trigger;
bool wakeup;
};
struct SM5701_dt_platform_data {
int chg_gpio_en;
int chg_irq;
unsigned long chg_irq_attr;
};
struct SM5701_charger_data {
struct SM5701_dev *SM5701;
struct delayed_work isr_work;
unsigned int is_charging;
unsigned int nchgen;
unsigned int charging_type;
unsigned int battery_state;
unsigned int battery_present;
unsigned int cable_type;
unsigned int charging_current_max;
unsigned int charging_current;
unsigned int input_current_limit;
unsigned int vbus_state;
bool is_fullcharged;
int aicl_on;
int status;
int siop_level;
int input_curr_limit_step;
int charging_curr_step;
int dev_id;
struct SM5701_dt_platform_data *pdata;
};
struct SM5701_platform_data {
unsigned int irq;
unsigned int chgen;
struct SM5701_charger_data *charger_data;
};
//CNTL
#define SM5701_OPERATIONMODE_SUSPEND 0x0 // 000 : Suspend (charger-OFF) MODE
#define SM5701_OPERATIONMODE_FLASH_ON 0x1 // 001 : Flash LED Driver=ON Ready in Charger & OTG OFF Mode
#define SM5701_OPERATIONMODE_OTG_ON 0x2 // 010 : OTG=ON in Charger & Flash OFF Mode
#define SM5701_OPERATIONMODE_OTG_ON_FLASH_ON 0x3 // 011 : OTG=ON & Flash LED Driver=ON Ready in charger OFF Mode
#define SM5701_OPERATIONMODE_CHARGER_ON 0x4 // 100 : Charger=ON in OTG & Flash OFF Mode. Same as 0x6(110)
#define SM5701_OPERATIONMODE_CHARGER_ON_FLASH_ON 0x5 // 101 : Charger=ON & Flash LED Driver=ON Ready in OTG OFF Mode. Same as 0x7(111)
enum led_state {
LED_DISABLE,
LED_MOVIE,
LED_FLASH,
};
enum sm5701_flash_mode {
NONE_MODE = 0,
MOVIE_MODE,
FLASH_MODE,
};
enum sm5701_flash_operation {
SM5701_FLEDEN_DISABLED = 0,
SM5701_FLEDEN_ON_MOVIE,
SM5701_FLEDEN_ON_FLASH,
SM5701_FLEDEN_EXTERNAL_CONTOL
};
//sm5701_core.c
extern int SM5701_reg_read(struct i2c_client *i2c, u8 reg, u8 *dest);
extern int SM5701_bulk_read(struct i2c_client *i2c, u8 reg, int count, u8 *buf);
extern int SM5701_reg_write(struct i2c_client *i2c, u8 reg, u8 value);
extern int SM5701_bulk_write(struct i2c_client *i2c, u8 reg, int count, u8 *buf);
extern int SM5701_reg_update(struct i2c_client *i2c, u8 reg, u8 val, u8 mask);
extern void SM5701_test_read(struct i2c_client *client );
extern void SM5701_set_operationmode(int operation_mode);
extern void sm5701_led_ready(int led_status);
extern int SM5701_operation_mode_function_control(void);
extern void SM5701_set_charger_data(void *p);
//leds-sm5701.c
extern void SM5701_set_enabstmr(int abstmr_enable);
extern void SM5701_set_abstmr(int abstmr_sec);
extern void SM5701_set_fleden(int fled_enable);
extern void SM5701_set_nensafet(int nensafet_enable);
extern void SM5701_set_safet(int safet_us);
extern void SM5701_set_noneshot(int noneshot_enable);
extern void SM5701_set_onetimer(int onetimer_ms);
extern void SM5701_set_ifled(int ifled_ma);
extern void SM5701_set_imled(int imled_ma);
extern void SM5701_set_enlowbatt(int enlowbatt_enable);
extern void SM5701_set_lbrstimer(int lbrstimer_us);
extern void SM5701_set_lowbatt(int lowbatt_v);
extern void SM5701_set_lbdhys(int lbdhys_mv);
extern void SM5701_set_bstout(int bstout_mv);
extern void sm5701_set_fleden(int fled_enable);
//sm5701_irq
extern int SM5701_irq_init(struct SM5701_dev *sm5701);
extern void SM5701_irq_exit(struct SM5701_dev *sm5701);
#endif /* __SM5701_CHARGER_H */
|