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
|
/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
*/
#ifndef __QBG_H__
#define __QBG_H__
#define MAX_FIFO_COUNT 36
#define QBG_MAX_STEP_CHG_ENTRIES 6
enum QBG_STATE {
QBG_LPM,
QBG_MPM,
QBG_HPM,
QBG_FAST_CHAR,
QBG_PON_OCV,
QBG_STATE_MAX,
};
enum QBG_SDAM_DATA_OFFSET {
QBG_ACC0_OFFSET = 0,
QBG_ACC1_OFFSET = 2,
QBG_ACC2_OFFSET = 4,
QBG_TBAT_OFFSET = 6,
QBG_IBAT_OFFSET = 8,
QBG_VREF_OFFSET = 10,
QBG_DATA_TAG_OFFSET = 12,
QBG_QG_STS_OFFSET,
QBG_STS1_OFFSET,
QBG_STS2_OFFSET,
QBG_STS3_OFFSET,
QBG_ONE_FIFO_LENGTH,
};
enum qbg {
QBG_PARAM_SOC,
QBG_PARAM_BATT_SOC,
QBG_PARAM_SYS_SOC,
QBG_PARAM_ESR,
QBG_PARAM_OCV_UV,
QBG_PARAM_MAX_LOAD_NOW,
QBG_PARAM_MAX_LOAD_AVG,
QBG_PARAM_HOLD_SOC_100PCT,
QBG_PARAM_CHARGE_CYCLE_COUNT,
QBG_PARAM_LEARNED_CAPACITY,
QBG_PARAM_TTF_100MS,
QBG_PARAM_TTE_100MS,
QBG_PARAM_SOH,
QBG_PARAM_TBAT,
QBG_PARAM_SYS_SOC_HOLD_100PCT,
QBG_PARAM_JEITA_COOL_THRESHOLD,
QBG_PARAM_TOTAL_IMPEDANCE,
QBG_PARAM_ESSENTIAL_PARAM_REVID,
QBG_PARAM_FIFO_TIMESTAMP,
QBG_PARAM_MAX,
};
struct qbg_essential_params {
short int msoc;
short int cutoff_soc;
short int full_soc;
short int x0;
short int x1;
short int x2;
short int soh_r;
short int soh_c;
short int theta0;
short int theta1;
short int theta2;
short int i1full;
short int i2full;
short int i1cutoff;
short int i2cutoff;
short int syssoc;
int discharge_cycle_count;
int charge_cycle_count;
unsigned int rtc_time;
short int batt_therm;
unsigned short int ocv;
} __attribute__ ((__packed__));
struct fifo_data {
unsigned short int v1;
unsigned short int v2;
unsigned short int i;
unsigned short int tbat;
unsigned short int ibat;
unsigned short int vref;
char data_tag;
char qg_sts;
char sts1;
char sts2;
char sts3;
} __attribute__ ((__packed__));
struct k_fifo_data {
unsigned int v1;
unsigned int v2;
unsigned int i;
unsigned int tbat;
unsigned int ibat;
unsigned int vref;
unsigned int data_tag;
unsigned int qg_sts;
unsigned int sts1;
unsigned int sts2;
unsigned int sts3;
} __attribute__ ((__packed__));
struct qbg_config {
unsigned int batt_id;
unsigned int pon_ocv;
unsigned int pon_ibat;
unsigned int pon_tbat;
unsigned int pon_soc;
unsigned int float_volt_uv;
unsigned int fastchg_curr_ma;
unsigned int vbat_cutoff_mv;
unsigned int ibat_cutoff_ma;
unsigned int vph_min_mv;
unsigned int iterm_ma;
unsigned int rconn_mohm;
unsigned long current_time;
unsigned int sdam_batt_id;
unsigned int essential_param_revid;
unsigned long sample_time_us[QBG_STATE_MAX];
} __attribute__ ((__packed__));
struct qbg_param {
unsigned int data;
_Bool valid;
};
struct qbg_kernel_data {
unsigned int seq_no;
unsigned int fifo_time;
unsigned int fifo_count;
struct k_fifo_data fifo[MAX_FIFO_COUNT];
struct qbg_param param[QBG_PARAM_MAX];
} __attribute__ ((__packed__));
struct qbg_user_data {
struct qbg_param param[QBG_PARAM_MAX];
} __attribute__ ((__packed__));
struct range_data {
int low_threshold;
int high_threshold;
unsigned int value;
} __attribute__ ((__packed__));
struct ranges {
struct range_data data[QBG_MAX_STEP_CHG_ENTRIES];
unsigned char range_count;
_Bool valid;
} __attribute__((__packed__));
struct qbg_step_chg_jeita_params {
int jeita_full_fv_10nv;
int jeita_full_iterm_10na;
int jeita_warm_adc_value;
int jeita_cool_adc_value;
int battery_beta;
int battery_therm_kohm;
struct ranges step_fcc_cfg;
struct ranges jeita_fcc_cfg;
struct ranges jeita_fv_cfg;
unsigned char ttf_calc_mode;
} __attribute__ ((__packed__));
/* IOCTLs to read & write QBG config and essential params */
#define QBGIOCXCFG _IOR('B', 0x01, struct qbg_config)
#define QBGIOCXEPR _IOR('B', 0x02, struct qbg_essential_params)
#define QBGIOCXEPW _IOWR('B', 0x03, struct qbg_essential_params)
#define QBGIOCXSTEPCHGCFG \
_IOWR('B', 0x04, struct qbg_step_chg_jeita_params)
#endif
|