blob: d8e335be2f544d723290f198d08efea09e89a6aa [file] [log] [blame]
Shyam Kumar Thella91978d22021-06-24 12:08:33 +05301/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
2/*
3 * Copyright (c) 2021, The Linux Foundation. All rights reserved.
4 */
5
6#ifndef __QBG_H__
7#define __QBG_H__
8
9#define MAX_FIFO_COUNT 36
10#define QBG_MAX_STEP_CHG_ENTRIES 6
11
12enum QBG_STATE {
13 QBG_LPM,
14 QBG_MPM,
15 QBG_HPM,
16 QBG_FAST_CHAR,
17 QBG_PON_OCV,
18 QBG_STATE_MAX,
19};
20
21enum QBG_SDAM_DATA_OFFSET {
22 QBG_ACC0_OFFSET = 0,
23 QBG_ACC1_OFFSET = 2,
24 QBG_ACC2_OFFSET = 4,
25 QBG_TBAT_OFFSET = 6,
26 QBG_IBAT_OFFSET = 8,
27 QBG_VREF_OFFSET = 10,
28 QBG_DATA_TAG_OFFSET = 12,
29 QBG_QG_STS_OFFSET,
30 QBG_STS1_OFFSET,
31 QBG_STS2_OFFSET,
32 QBG_STS3_OFFSET,
33 QBG_ONE_FIFO_LENGTH,
34};
35
36enum qbg {
37 QBG_PARAM_SOC,
38 QBG_PARAM_BATT_SOC,
39 QBG_PARAM_SYS_SOC,
40 QBG_PARAM_ESR,
41 QBG_PARAM_OCV_UV,
42 QBG_PARAM_MAX_LOAD_NOW,
43 QBG_PARAM_MAX_LOAD_AVG,
44 QBG_PARAM_HOLD_SOC_100PCT,
45 QBG_PARAM_CHARGE_CYCLE_COUNT,
46 QBG_PARAM_LEARNED_CAPACITY,
47 QBG_PARAM_TTF_100MS,
48 QBG_PARAM_TTE_100MS,
49 QBG_PARAM_SOH,
50 QBG_PARAM_TBAT,
51 QBG_PARAM_SYS_SOC_HOLD_100PCT,
52 QBG_PARAM_JEITA_COOL_THRESHOLD,
53 QBG_PARAM_TOTAL_IMPEDANCE,
54 QBG_PARAM_ESSENTIAL_PARAM_REVID,
55 QBG_PARAM_FIFO_TIMESTAMP,
56 QBG_PARAM_MAX,
57};
58
59struct qbg_essential_params {
60 short int msoc;
61 short int cutoff_soc;
62 short int full_soc;
63 short int x0;
64 short int x1;
65 short int x2;
66 short int soh_r;
67 short int soh_c;
68 short int theta0;
69 short int theta1;
70 short int theta2;
71 short int i1full;
72 short int i2full;
73 short int i1cutoff;
74 short int i2cutoff;
75 short int syssoc;
76 int discharge_cycle_count;
77 int charge_cycle_count;
78 unsigned int rtc_time;
79 short int batt_therm;
80 unsigned short int ocv;
81} __attribute__ ((__packed__));
82
83struct fifo_data {
84 unsigned short int v1;
85 unsigned short int v2;
86 unsigned short int i;
87 unsigned short int tbat;
88 unsigned short int ibat;
89 unsigned short int vref;
90 char data_tag;
91 char qg_sts;
92 char sts1;
93 char sts2;
94 char sts3;
95} __attribute__ ((__packed__));
96
97struct k_fifo_data {
98 unsigned int v1;
99 unsigned int v2;
100 unsigned int i;
101 unsigned int tbat;
102 unsigned int ibat;
103 unsigned int vref;
104 unsigned int data_tag;
105 unsigned int qg_sts;
106 unsigned int sts1;
107 unsigned int sts2;
108 unsigned int sts3;
109} __attribute__ ((__packed__));
110
111struct qbg_config {
112 unsigned int batt_id;
113 unsigned int pon_ocv;
114 unsigned int pon_ibat;
115 unsigned int pon_tbat;
116 unsigned int pon_soc;
117 unsigned int float_volt_uv;
118 unsigned int fastchg_curr_ma;
119 unsigned int vbat_cutoff_mv;
120 unsigned int ibat_cutoff_ma;
121 unsigned int vph_min_mv;
122 unsigned int iterm_ma;
123 unsigned int rconn_mohm;
124 unsigned long current_time;
125 unsigned int sdam_batt_id;
126 unsigned int essential_param_revid;
127 unsigned long sample_time_us[QBG_STATE_MAX];
128} __attribute__ ((__packed__));
129
130struct qbg_param {
131 unsigned int data;
132 _Bool valid;
133};
134
135struct qbg_kernel_data {
136 unsigned int seq_no;
137 unsigned int fifo_time;
138 unsigned int fifo_count;
139 struct k_fifo_data fifo[MAX_FIFO_COUNT];
140 struct qbg_param param[QBG_PARAM_MAX];
141} __attribute__ ((__packed__));
142
143struct qbg_user_data {
144 struct qbg_param param[QBG_PARAM_MAX];
145} __attribute__ ((__packed__));
146
147struct range_data {
148 int low_threshold;
149 int high_threshold;
150 unsigned int value;
151} __attribute__ ((__packed__));
152
153struct ranges {
154 struct range_data data[QBG_MAX_STEP_CHG_ENTRIES];
155 unsigned char range_count;
156 _Bool valid;
157} __attribute__((__packed__));
158
159struct qbg_step_chg_jeita_params {
160 int jeita_full_fv_10nv;
161 int jeita_full_iterm_10na;
162 int jeita_warm_adc_value;
163 int jeita_cool_adc_value;
164 int battery_beta;
165 int battery_therm_kohm;
166 struct ranges step_fcc_cfg;
167 struct ranges jeita_fcc_cfg;
168 struct ranges jeita_fv_cfg;
169 unsigned char ttf_calc_mode;
170} __attribute__ ((__packed__));
171
172/* IOCTLs to read & write QBG config and essential params */
173#define QBGIOCXCFG _IOR('B', 0x01, struct qbg_config)
174#define QBGIOCXEPR _IOR('B', 0x02, struct qbg_essential_params)
175#define QBGIOCXEPW _IOWR('B', 0x03, struct qbg_essential_params)
176#define QBGIOCXSTEPCHGCFG \
177 _IOWR('B', 0x04, struct qbg_step_chg_jeita_params)
178
179#endif