Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Google Battery Management System |
| 3 | * |
| 4 | * Copyright (C) 2018 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #ifndef __GOOGLE_BMS_H_ |
| 18 | #define __GOOGLE_BMS_H_ |
| 19 | |
Jenny Ho | 1911278 | 2021-11-24 13:13:36 +0800 | [diff] [blame] | 20 | #include <linux/minmax.h> |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 21 | #include <linux/types.h> |
| 22 | #include <linux/usb/pd.h> |
Jenny Ho | 08b8a84 | 2022-01-19 16:30:54 +0800 | [diff] [blame] | 23 | #include <misc/logbuffer.h> |
AleX Pelosi | 856679c | 2020-09-01 13:47:28 -0700 | [diff] [blame] | 24 | #include "gbms_power_supply.h" |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 25 | #include "qmath.h" |
| 26 | #include "gbms_storage.h" |
| 27 | |
| 28 | struct device_node; |
| 29 | |
| 30 | #define GBMS_CHG_TEMP_NB_LIMITS_MAX 10 |
| 31 | #define GBMS_CHG_VOLT_NB_LIMITS_MAX 5 |
Jenny Ho | 171aea1 | 2022-10-05 16:57:29 +0800 | [diff] [blame] | 32 | #define GBMS_CHG_ALG_BUF_SZ 500 |
Jenny Ho | 312de09 | 2021-10-19 15:49:41 +0800 | [diff] [blame] | 33 | #define GBMS_CHG_TOPOFF_NB_LIMITS_MAX 6 |
Jenny Ho | 1911278 | 2021-11-24 13:13:36 +0800 | [diff] [blame] | 34 | #define GBMS_AACR_DATA_MAX 10 |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 35 | |
| 36 | struct gbms_chg_profile { |
| 37 | const char *owner_name; |
| 38 | |
| 39 | int temp_nb_limits; |
| 40 | s32 temp_limits[GBMS_CHG_TEMP_NB_LIMITS_MAX]; |
| 41 | int volt_nb_limits; |
| 42 | s32 volt_limits[GBMS_CHG_VOLT_NB_LIMITS_MAX]; |
Jenny Ho | 312de09 | 2021-10-19 15:49:41 +0800 | [diff] [blame] | 43 | int topoff_nb_limits; |
| 44 | s32 topoff_limits[GBMS_CHG_TOPOFF_NB_LIMITS_MAX]; |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 45 | /* Array of constant current limits */ |
AleX Pelosi | 76a3e5b | 2022-01-06 13:57:18 -0800 | [diff] [blame] | 46 | u32 *cccm_limits; |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 47 | /* used to fill table */ |
| 48 | u32 capacity_ma; |
| 49 | |
| 50 | /* behavior */ |
| 51 | u32 fv_uv_margin_dpct; |
| 52 | u32 cv_range_accuracy; |
| 53 | u32 cv_debounce_cnt; |
| 54 | u32 cv_update_interval; |
| 55 | u32 cv_tier_ov_cnt; |
| 56 | u32 cv_tier_switch_cnt; |
| 57 | /* taper step */ |
| 58 | u32 fv_uv_resolution; |
| 59 | /* experimental */ |
| 60 | u32 cv_otv_margin; |
Jenny Ho | 1911278 | 2021-11-24 13:13:36 +0800 | [diff] [blame] | 61 | |
| 62 | /* AACR feature */ |
| 63 | u32 reference_cycles[GBMS_AACR_DATA_MAX]; |
| 64 | u32 reference_fade10[GBMS_AACR_DATA_MAX]; |
| 65 | u32 aacr_nb_limits; |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 66 | }; |
| 67 | |
Jenny Ho | 6ec4e64 | 2022-10-04 08:13:51 +0800 | [diff] [blame] | 68 | #define WLC_BPP_THRESHOLD_UV 7000000 |
| 69 | #define WLC_EPP_THRESHOLD_UV 11000000 |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 70 | |
| 71 | #define FOREACH_CHG_EV_ADAPTER(S) \ |
| 72 | S(UNKNOWN), \ |
| 73 | S(USB), \ |
| 74 | S(USB_SDP), \ |
| 75 | S(USB_DCP), \ |
| 76 | S(USB_CDP), \ |
| 77 | S(USB_ACA), \ |
| 78 | S(USB_C), \ |
| 79 | S(USB_PD), \ |
| 80 | S(USB_PD_DRP), \ |
| 81 | S(USB_PD_PPS), \ |
| 82 | S(USB_BRICKID), \ |
| 83 | S(USB_HVDCP), \ |
| 84 | S(USB_HVDCP3), \ |
Prasanna Prapancham | cce2a9b | 2022-07-08 22:46:01 +0000 | [diff] [blame] | 85 | S(FLOAT), \ |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 86 | S(WLC), \ |
| 87 | S(WLC_EPP), \ |
| 88 | S(WLC_SPP), \ |
Prasanna Prapancham | cce2a9b | 2022-07-08 22:46:01 +0000 | [diff] [blame] | 89 | S(GPP), \ |
| 90 | S(10W), \ |
| 91 | S(L7), \ |
| 92 | S(DL), \ |
| 93 | S(WPC_EPP), \ |
| 94 | S(WPC_GPP), \ |
| 95 | S(WPC_10W), \ |
| 96 | S(WPC_BPP), \ |
| 97 | S(WPC_L7), \ |
| 98 | S(EXT), \ |
| 99 | S(EXT1), \ |
| 100 | S(EXT2), \ |
| 101 | S(EXT_UNKNOWN), \ |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 102 | |
| 103 | #define CHG_EV_ADAPTER_STRING(s) #s |
| 104 | #define _CHG_EV_ADAPTER_PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__ |
| 105 | |
Jenny Ho | 2c40722 | 2022-04-27 09:29:04 +0800 | [diff] [blame] | 106 | #define BATTERY_DEBUG_ATTRIBUTE(name, fn_read, fn_write) \ |
| 107 | static const struct file_operations name = { \ |
| 108 | .open = simple_open, \ |
| 109 | .llseek = no_llseek, \ |
| 110 | .read = fn_read, \ |
| 111 | .write = fn_write, \ |
| 112 | } |
| 113 | |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 114 | /* Enums will start with CHG_EV_ADAPTER_TYPE_ */ |
| 115 | #define CHG_EV_ADAPTER_ENUM(e) \ |
| 116 | _CHG_EV_ADAPTER_PRIMITIVE_CAT(CHG_EV_ADAPTER_TYPE_,e) |
| 117 | |
| 118 | enum chg_ev_adapter_type_t { |
| 119 | FOREACH_CHG_EV_ADAPTER(CHG_EV_ADAPTER_ENUM) |
| 120 | }; |
| 121 | |
| 122 | enum gbms_msc_states_t { |
| 123 | MSC_NONE = 0, |
| 124 | MSC_SEED, |
| 125 | MSC_DSG, |
| 126 | MSC_LAST, |
| 127 | MSC_VSWITCH, |
| 128 | MSC_VOVER, |
| 129 | MSC_PULLBACK, |
| 130 | MSC_FAST, |
| 131 | MSC_TYPE, |
| 132 | MSC_DLY, /* in taper */ |
| 133 | MSC_STEADY, /* in taper */ |
| 134 | MSC_TIERCNTING, /* in taper */ |
| 135 | MSC_RAISE, /* in taper */ |
| 136 | MSC_WAIT, /* in taper */ |
| 137 | MSC_RSTC, /* in taper */ |
| 138 | MSC_NEXT, /* in taper */ |
| 139 | MSC_NYET, /* in taper */ |
AleX Pelosi | 0c88ff3 | 2020-04-02 01:04:51 -0700 | [diff] [blame] | 140 | MSC_HEALTH, |
Jenny Ho | 78dc911 | 2021-05-09 09:54:16 +0800 | [diff] [blame] | 141 | MSC_HEALTH_PAUSE, |
Jenny Ho | 1c2ec2b | 2021-12-10 17:43:14 +0800 | [diff] [blame] | 142 | MSC_HEALTH_ALWAYS_ON, |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 143 | MSC_STATES_COUNT, |
| 144 | }; |
| 145 | |
| 146 | union gbms_ce_adapter_details { |
| 147 | uint32_t v; |
| 148 | struct { |
| 149 | uint8_t ad_type; |
| 150 | uint8_t pad; |
| 151 | uint8_t ad_voltage; |
| 152 | uint8_t ad_amperage; |
| 153 | }; |
| 154 | }; |
| 155 | |
| 156 | struct gbms_ce_stats { |
| 157 | uint16_t voltage_in; |
| 158 | uint16_t ssoc_in; |
| 159 | uint16_t cc_in; |
| 160 | uint16_t voltage_out; |
| 161 | uint16_t ssoc_out; |
| 162 | uint16_t cc_out; |
| 163 | }; |
| 164 | |
| 165 | struct ttf_tier_stat { |
| 166 | int16_t soc_in; |
| 167 | int cc_in; |
| 168 | int cc_total; |
AleX Pelosi | ab0e9d4 | 2020-09-29 11:13:19 -0700 | [diff] [blame] | 169 | ktime_t avg_time; |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | struct gbms_ce_tier_stats { |
| 173 | int8_t temp_idx; |
AleX Pelosi | ee22c8e | 2020-05-07 12:09:08 -0700 | [diff] [blame] | 174 | int8_t vtier_idx; |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 175 | |
| 176 | int16_t soc_in; /* 8.8 */ |
| 177 | uint16_t cc_in; |
| 178 | uint16_t cc_total; |
| 179 | |
Jenny Ho | e0f94f3 | 2020-07-20 10:57:00 +0800 | [diff] [blame] | 180 | uint32_t time_fast; |
| 181 | uint32_t time_taper; |
| 182 | uint32_t time_other; |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 183 | |
| 184 | int16_t temp_in; |
| 185 | int16_t temp_min; |
| 186 | int16_t temp_max; |
| 187 | |
| 188 | int16_t ibatt_min; |
| 189 | int16_t ibatt_max; |
| 190 | |
| 191 | uint16_t icl_min; |
| 192 | uint16_t icl_max; |
| 193 | |
| 194 | int64_t icl_sum; |
| 195 | int64_t temp_sum; |
| 196 | int64_t ibatt_sum; |
| 197 | uint32_t sample_count; |
| 198 | |
| 199 | uint16_t msc_cnt[MSC_STATES_COUNT]; |
| 200 | uint32_t msc_elap[MSC_STATES_COUNT]; |
| 201 | }; |
| 202 | |
| 203 | #define GBMS_STATS_TIER_COUNT 3 |
| 204 | #define GBMS_SOC_STATS_LEN 101 |
| 205 | |
| 206 | /* time to full */ |
| 207 | |
| 208 | /* collected in charging event */ |
| 209 | struct ttf_soc_stats { |
| 210 | int ti[GBMS_SOC_STATS_LEN]; /* charge tier at each soc */ |
| 211 | int cc[GBMS_SOC_STATS_LEN]; /* coulomb count at each soc */ |
AleX Pelosi | ab0e9d4 | 2020-09-29 11:13:19 -0700 | [diff] [blame] | 212 | ktime_t elap[GBMS_SOC_STATS_LEN]; /* time spent at soc */ |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | /* reference data for soc estimation */ |
| 216 | struct ttf_adapter_stats { |
| 217 | u32 *soc_table; |
| 218 | u32 *elap_table; |
| 219 | int table_count; |
| 220 | }; |
| 221 | |
| 222 | /* updated when the device publish the charge stats |
| 223 | * NOTE: soc_stats and tier_stats are only valid for the given chg_profile |
| 224 | * since tier, coulumb count and elap time spent at each SOC depends on the |
| 225 | * maximum amout of current that can be pushed to the battery. |
| 226 | */ |
| 227 | struct batt_ttf_stats { |
AleX Pelosi | ab0e9d4 | 2020-09-29 11:13:19 -0700 | [diff] [blame] | 228 | ktime_t ttf_fake; |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 229 | |
| 230 | struct ttf_soc_stats soc_ref; /* gold: soc->elap,cc */ |
| 231 | int ref_temp_idx; |
| 232 | int ref_watts; |
| 233 | |
| 234 | struct ttf_soc_stats soc_stats; /* rolling */ |
| 235 | struct ttf_tier_stat tier_stats[GBMS_STATS_TIER_COUNT]; |
AleX Pelosi | d031947 | 2020-02-29 12:42:59 -0800 | [diff] [blame] | 236 | |
| 237 | struct logbuffer *ttf_log; |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 238 | }; |
| 239 | |
AleX Pelosi | ee22c8e | 2020-05-07 12:09:08 -0700 | [diff] [blame] | 240 | /* |
AleX Pelosi | 0d26151 | 2020-05-07 12:17:07 -0700 | [diff] [blame] | 241 | * health based charging can be enabled from userspace with a deadline |
AleX Pelosi | ee22c8e | 2020-05-07 12:09:08 -0700 | [diff] [blame] | 242 | * |
| 243 | * initial state: |
| 244 | * deadline = 0, rest_state = CHG_HEALTH_INACTIVE |
| 245 | * |
| 246 | * deadline = -1 from userspace |
Stephane Lee | 41e87c4 | 2020-09-02 23:05:34 -0700 | [diff] [blame] | 247 | * CHG_HEALTH_* -> CHG_HEALTH_USER_DISABLED (settings disabled) |
AleX Pelosi | ee22c8e | 2020-05-07 12:09:08 -0700 | [diff] [blame] | 248 | * on deadline = 0 from userspace |
Stephane Lee | 41e87c4 | 2020-09-02 23:05:34 -0700 | [diff] [blame] | 249 | * CHG_HEALTH_* -> CHG_HEALTH_USER_DISABLED (alarm, plug or misc. disabled) |
AleX Pelosi | ee22c8e | 2020-05-07 12:09:08 -0700 | [diff] [blame] | 250 | * on deadline > 0 from userspace |
| 251 | * CHG_HEALTH_* -> CHG_HEALTH_ENABLED |
| 252 | * |
| 253 | * from CHG_HEALTH_ENABLED, msc_logic_health() can change the state to |
| 254 | * CHG_HEALTH_ENABLED <-> CHG_HEALTH_ACTIVE |
| 255 | * CHG_HEALTH_ENABLED -> CHG_HEALTH_DISABLED |
| 256 | * |
| 257 | * from CHG_HEALTH_ACTIVE, msc_logic_health() can change the state to |
| 258 | * CHG_HEALTH_ACTIVE <-> CHG_HEALTH_ENABLED |
| 259 | * CHG_HEALTH_ACTIVE -> CHG_HEALTH_DISABLED |
| 260 | * CHG_HEALTH_ACTIVE -> CHG_HEALTH_DONE |
| 261 | */ |
| 262 | enum chg_health_state { |
AleX Pelosi | a6ad6ad | 2020-10-29 13:05:27 -0700 | [diff] [blame] | 263 | CHG_HEALTH_CCLVL_DISABLED = -6, |
AleX Pelosi | 600cb12 | 2020-10-29 10:05:47 -0700 | [diff] [blame] | 264 | CHG_HEALTH_BD_DISABLED = -5, |
AleX Pelosi | ee22c8e | 2020-05-07 12:09:08 -0700 | [diff] [blame] | 265 | CHG_HEALTH_USER_DISABLED = -3, |
| 266 | CHG_HEALTH_DISABLED = -2, |
| 267 | CHG_HEALTH_DONE = -1, |
| 268 | CHG_HEALTH_INACTIVE = 0, |
| 269 | CHG_HEALTH_ENABLED, |
| 270 | CHG_HEALTH_ACTIVE, |
Jenny Ho | 78dc911 | 2021-05-09 09:54:16 +0800 | [diff] [blame] | 271 | CHG_HEALTH_PAUSE, |
AleX Pelosi | ee22c8e | 2020-05-07 12:09:08 -0700 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | /* tier index used to log the session */ |
Stephane Lee | cbb07ee | 2020-09-14 12:24:09 -0700 | [diff] [blame] | 275 | enum gbms_stats_tier_idx_t { |
Stephane Lee | 4a984a2 | 2022-01-14 15:14:07 -0800 | [diff] [blame] | 276 | GBMS_STATS_AC_TI_DISABLE_DIALOG = -6, |
AleX Pelosi | 600cb12 | 2020-10-29 10:05:47 -0700 | [diff] [blame] | 277 | GBMS_STATS_AC_TI_DEFENDER = -5, |
Stephane Lee | 41e87c4 | 2020-09-02 23:05:34 -0700 | [diff] [blame] | 278 | GBMS_STATS_AC_TI_DISABLE_SETTING_STOP = -4, |
| 279 | GBMS_STATS_AC_TI_DISABLE_MISC = -3, |
| 280 | GBMS_STATS_AC_TI_DISABLE_SETTING = -2, |
AleX Pelosi | ee22c8e | 2020-05-07 12:09:08 -0700 | [diff] [blame] | 281 | GBMS_STATS_AC_TI_INVALID = -1, |
AleX Pelosi | a6ad6ad | 2020-10-29 13:05:27 -0700 | [diff] [blame] | 282 | |
Stephane Lee | cbb07ee | 2020-09-14 12:24:09 -0700 | [diff] [blame] | 283 | /* Regular charge tiers 0 -> 9 */ |
AleX Pelosi | ee22c8e | 2020-05-07 12:09:08 -0700 | [diff] [blame] | 284 | GBMS_STATS_AC_TI_VALID = 10, |
Stephane Lee | 463e85d | 2021-08-16 14:50:36 -0700 | [diff] [blame] | 285 | GBMS_STATS_AC_TI_DISABLED = 11, |
| 286 | GBMS_STATS_AC_TI_ENABLED = 12, |
| 287 | GBMS_STATS_AC_TI_ACTIVE = 13, |
| 288 | GBMS_STATS_AC_TI_ENABLED_AON = 14, |
| 289 | GBMS_STATS_AC_TI_ACTIVE_AON = 15, |
| 290 | GBMS_STATS_AC_TI_PAUSE = 16, |
| 291 | GBMS_STATS_AC_TI_PAUSE_AON = 17, |
| 292 | GBMS_STATS_AC_TI_V2_PREDICT = 18, |
| 293 | GBMS_STATS_AC_TI_V2_PREDICT_SUCCESS = 19, |
Jenny Ho | 1c2ec2b | 2021-12-10 17:43:14 +0800 | [diff] [blame] | 294 | GBMS_STATS_AC_TI_DONE_AON = 20, |
AleX Pelosi | a6ad6ad | 2020-10-29 13:05:27 -0700 | [diff] [blame] | 295 | |
Stephane Lee | fa67823 | 2022-10-12 16:55:04 -0700 | [diff] [blame] | 296 | /* Thermal stats, reported from google_charger - reserved 50-59 */ |
Stephane Lee | e6ccecd | 2022-04-14 17:23:36 -0700 | [diff] [blame] | 297 | GBMS_STATS_TH_LVL0 = 50, |
| 298 | GBMS_STATS_TH_LVL1 = 51, |
| 299 | GBMS_STATS_TH_LVL2 = 52, |
| 300 | GBMS_STATS_TH_LVL3 = 53, |
Stephane Lee | fa67823 | 2022-10-12 16:55:04 -0700 | [diff] [blame] | 301 | GBMS_STATS_TH_LVL4 = 54, |
| 302 | GBMS_STATS_TH_LVL5 = 55, |
| 303 | GBMS_STATS_TH_LVL6 = 56, |
| 304 | GBMS_STATS_TH_LVL7 = 57, |
| 305 | GBMS_STATS_TH_LVL8 = 58, |
| 306 | GBMS_STATS_TH_LVL9 = 59, |
Stephane Lee | e6ccecd | 2022-04-14 17:23:36 -0700 | [diff] [blame] | 307 | |
AleX Pelosi | a6ad6ad | 2020-10-29 13:05:27 -0700 | [diff] [blame] | 308 | /* TODO: rename, these are not really related to AC */ |
Stephane Lee | cbb07ee | 2020-09-14 12:24:09 -0700 | [diff] [blame] | 309 | GBMS_STATS_AC_TI_FULL_CHARGE = 100, |
| 310 | GBMS_STATS_AC_TI_HIGH_SOC = 101, |
AleX Pelosi | a6ad6ad | 2020-10-29 13:05:27 -0700 | [diff] [blame] | 311 | |
| 312 | /* Defender TEMP or DWELL */ |
| 313 | GBMS_STATS_BD_TI_OVERHEAT_TEMP = 110, |
| 314 | GBMS_STATS_BD_TI_CUSTOM_LEVELS = 111, |
Stephane Lee | cacee1f | 2021-09-22 11:51:38 -0700 | [diff] [blame] | 315 | GBMS_STATS_BD_TI_TRICKLE = 112, |
Prasanna Prapancham | 320dcfe | 2022-06-27 20:20:46 +0000 | [diff] [blame] | 316 | GBMS_STATS_BD_TI_DOCK = 113, |
Stephane Lee | cacee1f | 2021-09-22 11:51:38 -0700 | [diff] [blame] | 317 | |
| 318 | GBMS_STATS_BD_TI_TRICKLE_CLEARED = 122, |
Prasanna Prapancham | 320dcfe | 2022-06-27 20:20:46 +0000 | [diff] [blame] | 319 | GBMS_STATS_BD_TI_DOCK_CLEARED = 123, |
AleX Pelosi | ee22c8e | 2020-05-07 12:09:08 -0700 | [diff] [blame] | 320 | }; |
| 321 | |
AleX Pelosi | 043ffbe | 2020-06-24 22:48:30 -0700 | [diff] [blame] | 322 | /* health state */ |
| 323 | struct batt_chg_health { |
| 324 | int rest_soc; /* entry criteria */ |
| 325 | int rest_voltage; /* entry criteria */ |
| 326 | int always_on_soc; /* entry criteria */ |
| 327 | |
| 328 | ktime_t rest_deadline; /* full by this in seconds */ |
Stephane Lee | 463e85d | 2021-08-16 14:50:36 -0700 | [diff] [blame] | 329 | ktime_t dry_run_deadline; /* full by this in seconds (prediction) */ |
AleX Pelosi | 043ffbe | 2020-06-24 22:48:30 -0700 | [diff] [blame] | 330 | int rest_rate; /* centirate once enter */ |
Jenny Ho | 6ff91bf | 2022-09-16 15:11:04 +0800 | [diff] [blame] | 331 | int rest_rate_before_trigger; |
AleX Pelosi | 043ffbe | 2020-06-24 22:48:30 -0700 | [diff] [blame] | 332 | |
| 333 | enum chg_health_state rest_state; |
| 334 | int rest_cc_max; |
| 335 | int rest_fv_uv; |
Jenny Ho | d74a8a4 | 2021-10-28 12:58:15 +0800 | [diff] [blame] | 336 | ktime_t active_time; |
AleX Pelosi | 043ffbe | 2020-06-24 22:48:30 -0700 | [diff] [blame] | 337 | }; |
| 338 | |
Jenny Ho | 6f7ec52 | 2020-05-19 09:04:53 +0800 | [diff] [blame] | 339 | #define CHG_HEALTH_REST_IS_ACTIVE(rest) \ |
| 340 | ((rest)->rest_state == CHG_HEALTH_ACTIVE) |
| 341 | |
Jenny Ho | 78dc911 | 2021-05-09 09:54:16 +0800 | [diff] [blame] | 342 | #define CHG_HEALTH_REST_IS_PAUSE(rest) \ |
| 343 | ((rest)->rest_state == CHG_HEALTH_PAUSE) |
| 344 | |
Jenny Ho | 1c2ec2b | 2021-12-10 17:43:14 +0800 | [diff] [blame] | 345 | #define CHG_HEALTH_REST_IS_AON(rest, ssoc) \ |
| 346 | (((rest)->rest_state == CHG_HEALTH_ACTIVE) ? \ |
| 347 | (((rest)->always_on_soc != -1) ? \ |
| 348 | (ssoc >= (rest)->always_on_soc) : 0) : 0) |
| 349 | |
Jenny Ho | 6f7ec52 | 2020-05-19 09:04:53 +0800 | [diff] [blame] | 350 | #define CHG_HEALTH_REST_SOC(rest) (((rest)->always_on_soc != -1) ? \ |
| 351 | (rest)->always_on_soc : (rest)->rest_soc) |
| 352 | |
AleX Pelosi | a6ad6ad | 2020-10-29 13:05:27 -0700 | [diff] [blame] | 353 | /* reset on every charge session */ |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 354 | struct gbms_charging_event { |
| 355 | union gbms_ce_adapter_details adapter_details; |
| 356 | |
| 357 | /* profile used for this charge event */ |
| 358 | const struct gbms_chg_profile *chg_profile; |
| 359 | /* charge event and tier tracking */ |
| 360 | struct gbms_ce_stats charging_stats; |
| 361 | struct gbms_ce_tier_stats tier_stats[GBMS_STATS_TIER_COUNT]; |
AleX Pelosi | 0c88ff3 | 2020-04-02 01:04:51 -0700 | [diff] [blame] | 362 | |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 363 | /* soc tracking for time to full */ |
| 364 | struct ttf_soc_stats soc_stats; |
| 365 | int last_soc; |
| 366 | |
AleX Pelosi | ab0e9d4 | 2020-09-29 11:13:19 -0700 | [diff] [blame] | 367 | ktime_t first_update; |
| 368 | ktime_t last_update; |
Stephane Lee | cacee1f | 2021-09-22 11:51:38 -0700 | [diff] [blame] | 369 | bool bd_clear_trickle; |
AleX Pelosi | ee22c8e | 2020-05-07 12:09:08 -0700 | [diff] [blame] | 370 | |
| 371 | /* health based charging */ |
Jenny Ho | 6f7ec52 | 2020-05-19 09:04:53 +0800 | [diff] [blame] | 372 | struct batt_chg_health ce_health; /* updated on close */ |
| 373 | struct gbms_ce_tier_stats health_stats; /* updated in HC */ |
Jenny Ho | 78dc911 | 2021-05-09 09:54:16 +0800 | [diff] [blame] | 374 | struct gbms_ce_tier_stats health_pause_stats; /* updated in HCP */ |
Stephane Lee | 463e85d | 2021-08-16 14:50:36 -0700 | [diff] [blame] | 375 | /* updated on sysfs write */ |
| 376 | struct gbms_ce_tier_stats health_dryrun_stats; |
Stephane Lee | cbb07ee | 2020-09-14 12:24:09 -0700 | [diff] [blame] | 377 | |
AleX Pelosi | a6ad6ad | 2020-10-29 13:05:27 -0700 | [diff] [blame] | 378 | /* other stats */ |
Stephane Lee | cbb07ee | 2020-09-14 12:24:09 -0700 | [diff] [blame] | 379 | struct gbms_ce_tier_stats full_charge_stats; |
| 380 | struct gbms_ce_tier_stats high_soc_stats; |
AleX Pelosi | a6ad6ad | 2020-10-29 13:05:27 -0700 | [diff] [blame] | 381 | |
| 382 | struct gbms_ce_tier_stats overheat_stats; |
| 383 | struct gbms_ce_tier_stats cc_lvl_stats; |
Stephane Lee | cacee1f | 2021-09-22 11:51:38 -0700 | [diff] [blame] | 384 | struct gbms_ce_tier_stats trickle_stats; |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 385 | }; |
| 386 | |
Jenny Ho | b97a707 | 2022-05-01 21:05:24 +0800 | [diff] [blame] | 387 | #define GBMS_CCCM_LIMITS_SET(profile, ti, vi) \ |
Jenny Ho | b63ed59 | 2022-07-21 10:01:24 +0000 | [diff] [blame] | 388 | profile->cccm_limits[((ti) * profile->volt_nb_limits) + (vi)] |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 389 | |
Jenny Ho | b97a707 | 2022-05-01 21:05:24 +0800 | [diff] [blame] | 390 | #define GBMS_CCCM_LIMITS(profile, ti, vi) \ |
Jenny Ho | b63ed59 | 2022-07-21 10:01:24 +0000 | [diff] [blame] | 391 | (((ti) >= 0 && (vi) >= 0) ? profile->cccm_limits[((ti) * profile->volt_nb_limits) + (vi)] : 0) |
Jenny Ho | b97a707 | 2022-05-01 21:05:24 +0800 | [diff] [blame] | 392 | |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 393 | /* newgen charging */ |
AleX Pelosi | a6ad6ad | 2020-10-29 13:05:27 -0700 | [diff] [blame] | 394 | #define GBMS_CS_FLAG_BUCK_EN BIT(0) |
| 395 | #define GBMS_CS_FLAG_DONE BIT(1) |
| 396 | #define GBMS_CS_FLAG_CC BIT(2) |
| 397 | #define GBMS_CS_FLAG_CV BIT(3) |
| 398 | #define GBMS_CS_FLAG_ILIM BIT(4) |
| 399 | #define GBMS_CS_FLAG_CCLVL BIT(5) |
| 400 | #define GBMS_CS_FLAG_NOCOMP BIT(6) |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 401 | |
| 402 | union gbms_charger_state { |
| 403 | uint64_t v; |
| 404 | struct { |
| 405 | uint8_t flags; |
| 406 | uint8_t pad; |
| 407 | uint8_t chg_status; |
| 408 | uint8_t chg_type; |
| 409 | uint16_t vchrg; |
| 410 | uint16_t icl; |
| 411 | } f; |
| 412 | }; |
| 413 | |
| 414 | int gbms_init_chg_profile_internal(struct gbms_chg_profile *profile, |
| 415 | struct device_node *node, const char *owner_name); |
| 416 | #define gbms_init_chg_profile(p, n) \ |
| 417 | gbms_init_chg_profile_internal(p, n, KBUILD_MODNAME) |
| 418 | |
Jenny Ho | 2e58348 | 2021-12-01 18:09:40 +0800 | [diff] [blame] | 419 | void gbms_init_chg_table(struct gbms_chg_profile *profile, |
| 420 | struct device_node *node, u32 capacity); |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 421 | |
| 422 | void gbms_free_chg_profile(struct gbms_chg_profile *profile); |
| 423 | |
Jenny Ho | 68183e8 | 2021-12-06 17:39:05 +0800 | [diff] [blame] | 424 | void gbms_dump_raw_profile(char *buff, size_t len, const struct gbms_chg_profile *profile, int scale); |
| 425 | #define gbms_dump_chg_profile(buff, len, profile) gbms_dump_raw_profile(buff, len, profile, 1000) |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 426 | |
| 427 | /* newgen charging: charge profile */ |
| 428 | int gbms_msc_temp_idx(const struct gbms_chg_profile *profile, int temp); |
| 429 | int gbms_msc_voltage_idx(const struct gbms_chg_profile *profile, int vbatt); |
| 430 | int gbms_msc_round_fv_uv(const struct gbms_chg_profile *profile, |
| 431 | int vtier, int fv_uv); |
| 432 | |
| 433 | /* newgen charging: charger flags */ |
| 434 | uint8_t gbms_gen_chg_flags(int chg_status, int chg_type); |
| 435 | /* newgen charging: read/gen charger state */ |
| 436 | int gbms_read_charger_state(union gbms_charger_state *chg_state, |
| 437 | struct power_supply *chg_psy); |
Jenny Ho | 1911278 | 2021-11-24 13:13:36 +0800 | [diff] [blame] | 438 | /* calculate aacr reference capacity */ |
AleX Pelosi | c10eb8b | 2021-12-14 13:20:21 -0800 | [diff] [blame] | 439 | int gbms_aacr_fade10(const struct gbms_chg_profile *profile, int cycles); |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 440 | |
Jenny Ho | 08b8a84 | 2022-01-19 16:30:54 +0800 | [diff] [blame] | 441 | /* logbuffer and syslog */ |
| 442 | __printf(5,6) |
| 443 | void gbms_logbuffer_prlog(struct logbuffer *log, int level, int debug_no_logbuffer, |
| 444 | int debug_printk_prlog, const char *f, ...); |
| 445 | |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 446 | /* debug/print */ |
| 447 | const char *gbms_chg_type_s(int chg_type); |
| 448 | const char *gbms_chg_status_s(int chg_status); |
| 449 | const char *gbms_chg_ev_adapter_s(int adapter); |
| 450 | |
| 451 | /* Votables */ |
| 452 | #define VOTABLE_MSC_CHG_DISABLE "MSC_CHG_DISABLE" |
| 453 | #define VOTABLE_MSC_PWR_DISABLE "MSC_PWR_DISABLE" |
| 454 | #define VOTABLE_MSC_INTERVAL "MSC_INTERVAL" |
| 455 | #define VOTABLE_MSC_FCC "MSC_FCC" |
| 456 | #define VOTABLE_MSC_FV "MSC_FV" |
yihsiangpeng | 305623d | 2021-05-06 15:07:05 +0800 | [diff] [blame] | 457 | #define VOTABLE_FAN_LEVEL "FAN_LEVEL" |
Jack Wu | bf61d9f | 2021-06-21 23:02:22 +0800 | [diff] [blame] | 458 | #define VOTABLE_DEAD_BATTERY "DEAD_BATTERY" |
Jenny Ho | 701a0ea | 2021-12-08 17:22:05 +0800 | [diff] [blame] | 459 | #define VOTABLE_TEMP_DRYRUN "MSC_TEMP_DRYRUN" |
Stephane Lee | fa67823 | 2022-10-12 16:55:04 -0700 | [diff] [blame] | 460 | #define VOTABLE_MDIS "CHG_MDIS" |
yihsiangpeng | 305623d | 2021-05-06 15:07:05 +0800 | [diff] [blame] | 461 | |
AleX Pelosi | 1c2d9de | 2022-01-20 18:24:19 -0800 | [diff] [blame] | 462 | #define VOTABLE_CSI_STATUS "CSI_STATUS" |
| 463 | #define VOTABLE_CSI_TYPE "CSI_TYPE" |
| 464 | |
Prasanna Prapancham | 1920330 | 2022-09-09 20:58:11 +0000 | [diff] [blame] | 465 | #define VOTABLE_DC_CHG_AVAIL "DC_AVAIL" |
| 466 | #define REASON_DC_DRV "DC_DRV" |
| 467 | #define REASON_MDIS "MDIS" |
| 468 | |
yihsiangpeng | 305623d | 2021-05-06 15:07:05 +0800 | [diff] [blame] | 469 | #define FAN_LVL_UNKNOWN -1 |
| 470 | #define FAN_LVL_NOT_CARE 0 |
| 471 | #define FAN_LVL_LOW 1 |
| 472 | #define FAN_LVL_MED 2 |
| 473 | #define FAN_LVL_HIGH 3 |
| 474 | #define FAN_LVL_ALARM 4 |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 475 | |
| 476 | /* Binned cycle count */ |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 477 | #define GBMS_CCBIN_CSTR_SIZE (GBMS_CCBIN_BUCKET_COUNT * 6 + 2) |
| 478 | |
| 479 | int gbms_cycle_count_sscan_bc(u16 *ccount, int bcnt, const char *buff); |
| 480 | int gbms_cycle_count_cstr_bc(char *buff, size_t size, |
| 481 | const u16 *ccount, int bcnt); |
| 482 | |
| 483 | #define gbms_cycle_count_sscan(cc, buff) \ |
| 484 | gbms_cycle_count_sscan_bc(cc, GBMS_CCBIN_BUCKET_COUNT, buff) |
| 485 | |
| 486 | #define gbms_cycle_count_cstr(buff, size, cc) \ |
| 487 | gbms_cycle_count_cstr_bc(buff, size, cc, GBMS_CCBIN_BUCKET_COUNT) |
| 488 | |
| 489 | |
| 490 | /* Time to full */ |
| 491 | int ttf_soc_cstr(char *buff, int size, const struct ttf_soc_stats *soc_stats, |
| 492 | int start, int end); |
| 493 | |
AleX Pelosi | ab0e9d4 | 2020-09-29 11:13:19 -0700 | [diff] [blame] | 494 | int ttf_soc_estimate(ktime_t *res, |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 495 | const struct batt_ttf_stats *stats, |
| 496 | const struct gbms_charging_event *ce_data, |
| 497 | qnum_t soc, qnum_t last); |
| 498 | |
| 499 | void ttf_soc_init(struct ttf_soc_stats *dst); |
| 500 | |
AleX Pelosi | 4a9035f | 2020-02-28 19:09:57 -0800 | [diff] [blame] | 501 | int ttf_tier_cstr(char *buff, int size, const struct ttf_tier_stat *t_stat); |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 502 | |
AleX Pelosi | ab0e9d4 | 2020-09-29 11:13:19 -0700 | [diff] [blame] | 503 | int ttf_tier_estimate(ktime_t *res, |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 504 | const struct batt_ttf_stats *ttf_stats, |
| 505 | int temp_idx, int vbatt_idx, |
| 506 | int capacity, int full_capacity); |
| 507 | |
| 508 | int ttf_stats_init(struct batt_ttf_stats *stats, |
| 509 | struct device *device, |
| 510 | int capacity_ma); |
| 511 | |
| 512 | void ttf_stats_update(struct batt_ttf_stats *stats, |
| 513 | struct gbms_charging_event *ce_data, |
| 514 | bool force); |
| 515 | |
| 516 | int ttf_stats_cstr(char *buff, int size, const struct batt_ttf_stats *stats, |
| 517 | bool verbose); |
| 518 | |
| 519 | int ttf_stats_sscan(struct batt_ttf_stats *stats, |
| 520 | const char *buff, size_t size); |
| 521 | |
| 522 | struct batt_ttf_stats *ttf_stats_dup(struct batt_ttf_stats *dst, |
| 523 | const struct batt_ttf_stats *src); |
| 524 | |
AleX Pelosi | d031947 | 2020-02-29 12:42:59 -0800 | [diff] [blame] | 525 | void ttf_log(const struct batt_ttf_stats *stats, const char *fmt, ...); |
| 526 | |
AleX Pelosi | 4a9035f | 2020-02-28 19:09:57 -0800 | [diff] [blame] | 527 | ssize_t ttf_dump_details(char *buf, int max_size, |
| 528 | const struct batt_ttf_stats *ttf_stats, |
| 529 | int last_soc); |
| 530 | |
Jenny Ho | 915dc48 | 2022-03-21 09:13:57 +0800 | [diff] [blame] | 531 | int ttf_pwr_vtier_idx(const struct batt_ttf_stats *stats, int soc); |
| 532 | |
| 533 | int ttf_ref_cc(const struct batt_ttf_stats *stats, int soc); |
| 534 | |
| 535 | int ttf_pwr_ibatt(const struct gbms_ce_tier_stats *ts); |
| 536 | |
Jenny Ho | 1ef6000 | 2022-07-24 18:26:51 +0000 | [diff] [blame] | 537 | void ttf_tier_reset(struct batt_ttf_stats *stats); |
| 538 | |
Jenny Ho | a1ad407 | 2022-01-26 10:46:22 +0800 | [diff] [blame] | 539 | int gbms_read_aacr_limits(struct gbms_chg_profile *profile, |
| 540 | struct device_node *node); |
| 541 | |
AleX Pelosi | 4adb2a1 | 2022-04-26 13:16:20 -0700 | [diff] [blame] | 542 | bool chg_state_is_disconnected(const union gbms_charger_state *chg_state); |
Jenny Ho | 4f2ad70 | 2022-03-01 10:56:19 +0800 | [diff] [blame] | 543 | |
Prasanna Prapancham | 320dcfe | 2022-06-27 20:20:46 +0000 | [diff] [blame] | 544 | /* Voltage tier stats */ |
| 545 | void gbms_tier_stats_init(struct gbms_ce_tier_stats *stats, int8_t idx); |
| 546 | |
| 547 | void gbms_chg_stats_tier(struct gbms_ce_tier_stats *tier, |
| 548 | int msc_state, ktime_t elap); |
| 549 | |
| 550 | void gbms_stats_update_tier(int temp_idx, int ibatt_ma, int temp, ktime_t elap, |
| 551 | int cc, union gbms_charger_state *chg_state, |
| 552 | enum gbms_msc_states_t msc_state, int soc_in, |
| 553 | struct gbms_ce_tier_stats *tier); |
| 554 | |
| 555 | int gbms_tier_stats_cstr(char *buff, int size, |
| 556 | const struct gbms_ce_tier_stats *tier_stat, |
| 557 | bool verbose); |
| 558 | |
| 559 | void gbms_log_cstr_handler(struct logbuffer *log, char *buf, int len); |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 564 | /* |
| 565 | * Charger modes |
| 566 | * |
| 567 | */ |
| 568 | |
| 569 | enum gbms_charger_modes { |
AleX Pelosi | ea674a7 | 2020-11-02 11:52:51 -0800 | [diff] [blame] | 570 | GBMS_CHGR_MODE_CHGR_DC = 0x20, |
| 571 | |
| 572 | GBMS_USB_BUCK_ON = 0x30, |
| 573 | GBMS_USB_OTG_ON = 0x31, |
| 574 | GBMS_USB_OTG_FRS_ON = 0x32, |
yihsiangpeng | 8ae00b6 | 2021-02-01 19:12:31 +0800 | [diff] [blame] | 575 | |
| 576 | GBMS_CHGR_MODE_WLC_TX = 0x40, |
Jack Wu | 71efd60 | 2022-07-07 16:22:31 +0800 | [diff] [blame] | 577 | |
Jack Wu | 15abe93 | 2022-11-14 20:11:24 +0800 | [diff] [blame] | 578 | GBMS_POGO_VIN = 0x50, |
| 579 | GBMS_POGO_VOUT = 0x51, |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 580 | }; |
| 581 | |
| 582 | #define GBMS_MODE_VOTABLE "CHARGER_MODE" |
| 583 | |
AleX Pelosi | 43bec42 | 2022-04-27 21:59:19 -0700 | [diff] [blame] | 584 | /* Battery Health */ |
| 585 | enum bhi_algo { |
| 586 | BHI_ALGO_DISABLED = 0, |
AleX Pelosi | b3a1a55 | 2022-05-03 17:00:11 -0700 | [diff] [blame] | 587 | |
AleX Pelosi | c1cd475 | 2022-05-04 02:15:02 -0700 | [diff] [blame] | 588 | BHI_ALGO_CYCLE_COUNT = 1, /* bare, just use cycle count */ |
| 589 | BHI_ALGO_ACHI = 2, /* cap avg from history, no resistance */ |
| 590 | BHI_ALGO_ACHI_B = 3, /* same as ACHI + bounds check */ |
| 591 | BHI_ALGO_ACHI_RAVG = 4, /* same as ACHI and google_resistance */ |
| 592 | BHI_ALGO_ACHI_RAVG_B = 5, /* same as ACHI_RAVG + bounds check */ |
AleX Pelosi | 43bec42 | 2022-04-27 21:59:19 -0700 | [diff] [blame] | 593 | |
AleX Pelosi | c1cd475 | 2022-05-04 02:15:02 -0700 | [diff] [blame] | 594 | /* TODO: |
| 595 | * BHI_ALGO_ACHI_QRES = 4, cap avg from history, qual resistance |
| 596 | * BHI_ALGO_ACHI_QRES_B = 21, same ACHI_QRES + bounds check |
| 597 | * BHI_ALGO_GCAP_RAVG = 40, google_capacity, google_resistance |
| 598 | * BHI_ALGO_GCAP_RAVG_B = 41, same as GCAP_RAVG + bounds check |
| 599 | */ |
| 600 | |
| 601 | BHI_ALGO_MIX_N_MATCH = 6, |
Jenny Ho | d4bd5bc | 2022-08-26 16:08:38 +0000 | [diff] [blame] | 602 | BHI_ALGO_DEBUG = 7, |
Jenny Ho | ef8e525 | 2022-10-20 12:03:05 +0800 | [diff] [blame] | 603 | BHI_ALGO_INDI = 8, /* individual conditions check */ |
AleX Pelosi | 43bec42 | 2022-04-27 21:59:19 -0700 | [diff] [blame] | 604 | BHI_ALGO_MAX, |
| 605 | }; |
| 606 | |
AleX Pelosi | 1c2d9de | 2022-01-20 18:24:19 -0800 | [diff] [blame] | 607 | enum bhi_status { |
| 608 | BH_UNKNOWN = -1, |
| 609 | BH_NOMINAL, |
| 610 | BH_MARGINAL, |
| 611 | BH_NEEDS_REPLACEMENT, |
| 612 | BH_FAILED, |
| 613 | }; |
| 614 | |
Jenny Ho | d4bd5bc | 2022-08-26 16:08:38 +0000 | [diff] [blame] | 615 | struct bhi_weight { |
| 616 | int w_ci; |
| 617 | int w_ii; |
| 618 | int w_sd; |
| 619 | }; |
| 620 | |
AleX Pelosi | 43bec42 | 2022-04-27 21:59:19 -0700 | [diff] [blame] | 621 | /* Charging Speed */ |
AleX Pelosi | 1c2d9de | 2022-01-20 18:24:19 -0800 | [diff] [blame] | 622 | enum csi_type { |
| 623 | CSI_TYPE_UNKNOWN = -1, |
AleX Pelosi | 4adb2a1 | 2022-04-26 13:16:20 -0700 | [diff] [blame] | 624 | |
AleX Pelosi | 1c2d9de | 2022-01-20 18:24:19 -0800 | [diff] [blame] | 625 | CSI_TYPE_None = 0, // Disconnected |
| 626 | CSI_TYPE_Fault = 1, // Internal Failures |
AleX Pelosi | 1da39c1 | 2022-04-26 15:44:44 -0700 | [diff] [blame] | 627 | CSI_TYPE_JEITA = 2, // HW limits (will have HOT or COLD) |
AleX Pelosi | 1c2d9de | 2022-01-20 18:24:19 -0800 | [diff] [blame] | 628 | CSI_TYPE_LongLife = 3, // DefenderConditions |
| 629 | CSI_TYPE_Adaptive = 4, // AdaptiveCharging |
AleX Pelosi | 1da39c1 | 2022-04-26 15:44:44 -0700 | [diff] [blame] | 630 | CSI_TYPE_Normal = 5, // All Good |
AleX Pelosi | 1c2d9de | 2022-01-20 18:24:19 -0800 | [diff] [blame] | 631 | }; |
| 632 | |
| 633 | enum csi_status { |
| 634 | CSI_STATUS_UNKNOWN = -1, |
AleX Pelosi | 4adb2a1 | 2022-04-26 13:16:20 -0700 | [diff] [blame] | 635 | |
AleX Pelosi | 1da39c1 | 2022-04-26 15:44:44 -0700 | [diff] [blame] | 636 | CSI_STATUS_Health_Cold = 10, // battery temperature not nominal |
| 637 | CSI_STATUS_Health_Hot = 11, // battery temperature not nominal |
| 638 | CSI_STATUS_System_Thermals = 20,// Thermal engine |
| 639 | CSI_STATUS_System_Load = 21, // Load might eventually become thermals |
| 640 | CSI_STATUS_Adapter_Auth = 30, // During authentication |
| 641 | CSI_STATUS_Adapter_Power = 31, // Low power adapter |
| 642 | CSI_STATUS_Adapter_Quality = 32,// Adapter or cable (low input voltage) |
Jenny Ho | 4f2ad70 | 2022-03-01 10:56:19 +0800 | [diff] [blame] | 643 | CSI_STATUS_Defender_Temp = 40, // TEMP Defend |
| 644 | CSI_STATUS_Defender_Dwell = 41, // DWELL Defend |
| 645 | CSI_STATUS_Defender_Trickle = 42, |
| 646 | CSI_STATUS_Defender_Dock = 43, // Dock Defend |
AleX Pelosi | 1da39c1 | 2022-04-26 15:44:44 -0700 | [diff] [blame] | 647 | CSI_STATUS_NotCharging = 100, // There will be a more specific reason |
| 648 | CSI_STATUS_Charging = 200, // All good |
AleX Pelosi | 1c2d9de | 2022-01-20 18:24:19 -0800 | [diff] [blame] | 649 | }; |
| 650 | |
Jack Wu | d7fe209 | 2022-07-14 21:21:19 +0800 | [diff] [blame] | 651 | #define to_cooling_device(_dev) \ |
| 652 | container_of(_dev, struct thermal_cooling_device, device) |
| 653 | |
| 654 | #define DEBUG_ATTRIBUTE_WO(name) \ |
| 655 | static const struct file_operations name ## _fops = { \ |
| 656 | .open = simple_open, \ |
| 657 | .llseek = no_llseek, \ |
| 658 | .write = name ## _store, \ |
| 659 | } |
AleX Pelosi | 43bec42 | 2022-04-27 21:59:19 -0700 | [diff] [blame] | 660 | |
| 661 | |
Ken Tsou | 8acade1 | 2020-07-09 03:17:35 +0800 | [diff] [blame] | 662 | #endif /* __GOOGLE_BMS_H_ */ |