Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2018 The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __SMB5_CHARGER_H |
| 14 | #define __SMB5_CHARGER_H |
| 15 | #include <linux/types.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/irqreturn.h> |
| 18 | #include <linux/regulator/driver.h> |
| 19 | #include <linux/regulator/consumer.h> |
| 20 | #include <linux/extcon.h> |
| 21 | #include "storm-watch.h" |
| 22 | |
| 23 | enum print_reason { |
| 24 | PR_INTERRUPT = BIT(0), |
| 25 | PR_REGISTER = BIT(1), |
| 26 | PR_MISC = BIT(2), |
| 27 | PR_PARALLEL = BIT(3), |
| 28 | PR_OTG = BIT(4), |
| 29 | }; |
| 30 | |
| 31 | #define DEFAULT_VOTER "DEFAULT_VOTER" |
| 32 | #define USER_VOTER "USER_VOTER" |
| 33 | #define PD_VOTER "PD_VOTER" |
| 34 | #define DCP_VOTER "DCP_VOTER" |
| 35 | #define QC_VOTER "QC_VOTER" |
| 36 | #define PL_USBIN_USBIN_VOTER "PL_USBIN_USBIN_VOTER" |
| 37 | #define USB_PSY_VOTER "USB_PSY_VOTER" |
| 38 | #define PL_TAPER_WORK_RUNNING_VOTER "PL_TAPER_WORK_RUNNING_VOTER" |
| 39 | #define PL_QNOVO_VOTER "PL_QNOVO_VOTER" |
| 40 | #define USBIN_V_VOTER "USBIN_V_VOTER" |
| 41 | #define CHG_STATE_VOTER "CHG_STATE_VOTER" |
| 42 | #define TYPEC_SRC_VOTER "TYPEC_SRC_VOTER" |
| 43 | #define TAPER_END_VOTER "TAPER_END_VOTER" |
| 44 | #define THERMAL_DAEMON_VOTER "THERMAL_DAEMON_VOTER" |
| 45 | #define CC_DETACHED_VOTER "CC_DETACHED_VOTER" |
| 46 | #define APSD_VOTER "APSD_VOTER" |
| 47 | #define PD_DISALLOWED_INDIRECT_VOTER "PD_DISALLOWED_INDIRECT_VOTER" |
| 48 | #define VBUS_CC_SHORT_VOTER "VBUS_CC_SHORT_VOTER" |
| 49 | #define PD_INACTIVE_VOTER "PD_INACTIVE_VOTER" |
| 50 | #define BOOST_BACK_VOTER "BOOST_BACK_VOTER" |
| 51 | #define USBIN_USBIN_BOOST_VOTER "USBIN_USBIN_BOOST_VOTER" |
| 52 | #define MICRO_USB_VOTER "MICRO_USB_VOTER" |
| 53 | #define DEBUG_BOARD_VOTER "DEBUG_BOARD_VOTER" |
| 54 | #define PD_SUSPEND_SUPPORTED_VOTER "PD_SUSPEND_SUPPORTED_VOTER" |
| 55 | #define PL_DELAY_VOTER "PL_DELAY_VOTER" |
| 56 | #define CTM_VOTER "CTM_VOTER" |
| 57 | #define SW_QC3_VOTER "SW_QC3_VOTER" |
| 58 | #define AICL_RERUN_VOTER "AICL_RERUN_VOTER" |
Harry Yang | f7b8990 | 2018-03-13 22:37:53 -0700 | [diff] [blame] | 59 | #define SW_ICL_MAX_VOTER "SW_ICL_MAX_VOTER" |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 60 | #define QNOVO_VOTER "QNOVO_VOTER" |
| 61 | #define BATT_PROFILE_VOTER "BATT_PROFILE_VOTER" |
| 62 | #define OTG_DELAY_VOTER "OTG_DELAY_VOTER" |
| 63 | #define USBIN_I_VOTER "USBIN_I_VOTER" |
| 64 | #define WEAK_CHARGER_VOTER "WEAK_CHARGER_VOTER" |
| 65 | #define OTG_VOTER "OTG_VOTER" |
| 66 | #define PL_FCC_LOW_VOTER "PL_FCC_LOW_VOTER" |
| 67 | #define WBC_VOTER "WBC_VOTER" |
| 68 | #define HW_LIMIT_VOTER "HW_LIMIT_VOTER" |
Anirudh Ghayal | dfdb841 | 2018-04-21 10:37:18 +0530 | [diff] [blame] | 69 | #define FORCE_RECHARGE_VOTER "FORCE_RECHARGE_VOTER" |
Ashay Jaiswal | e0b3c47 | 2018-06-20 23:39:41 +0530 | [diff] [blame] | 70 | #define AICL_THRESHOLD_VOTER "AICL_THRESHOLD_VOTER" |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 71 | |
| 72 | #define BOOST_BACK_STORM_COUNT 3 |
| 73 | #define WEAK_CHG_STORM_COUNT 8 |
| 74 | |
Anirudh Ghayal | 1380d31 | 2018-02-23 00:01:43 +0530 | [diff] [blame] | 75 | #define VBAT_TO_VRAW_ADC(v) div_u64((u64)v * 1000000UL, 194637UL) |
| 76 | |
Anirudh Ghayal | 4d5cddc | 2018-06-28 15:19:39 +0530 | [diff] [blame] | 77 | #define SDP_100_MA 100000 |
| 78 | #define SDP_CURRENT_UA 500000 |
| 79 | #define CDP_CURRENT_UA 1500000 |
| 80 | #define DCP_CURRENT_UA 1500000 |
| 81 | #define HVDCP_CURRENT_UA 3000000 |
| 82 | #define TYPEC_DEFAULT_CURRENT_UA 900000 |
| 83 | #define TYPEC_MEDIUM_CURRENT_UA 1500000 |
| 84 | #define TYPEC_HIGH_CURRENT_UA 3000000 |
Guru Das Srinagesh | 3ca1437 | 2018-06-01 11:30:56 -0700 | [diff] [blame] | 85 | #define ADC_CHG_TERM_MASK 32767 |
Anirudh Ghayal | 4d5cddc | 2018-06-28 15:19:39 +0530 | [diff] [blame] | 86 | |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 87 | enum smb_mode { |
| 88 | PARALLEL_MASTER = 0, |
| 89 | PARALLEL_SLAVE, |
| 90 | NUM_MODES, |
| 91 | }; |
| 92 | |
Harry Yang | 6afaea2 | 2018-03-26 19:11:07 -0700 | [diff] [blame] | 93 | enum sink_src_mode { |
| 94 | SINK_MODE, |
| 95 | SRC_MODE, |
| 96 | UNATTACHED_MODE, |
| 97 | }; |
| 98 | |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 99 | enum { |
| 100 | BOOST_BACK_WA = BIT(0), |
Ashay Jaiswal | e0b3c47 | 2018-06-20 23:39:41 +0530 | [diff] [blame] | 101 | WEAK_ADAPTER_WA = BIT(1), |
| 102 | }; |
| 103 | |
| 104 | enum { |
| 105 | RERUN_AICL = BIT(0), |
| 106 | RESTART_AICL = BIT(1), |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | enum smb_irq_index { |
| 110 | /* CHGR */ |
| 111 | CHGR_ERROR_IRQ = 0, |
| 112 | CHG_STATE_CHANGE_IRQ, |
| 113 | STEP_CHG_STATE_CHANGE_IRQ, |
| 114 | STEP_CHG_SOC_UPDATE_FAIL_IRQ, |
| 115 | STEP_CHG_SOC_UPDATE_REQ_IRQ, |
| 116 | FG_FVCAL_QUALIFIED_IRQ, |
| 117 | VPH_ALARM_IRQ, |
| 118 | VPH_DROP_PRECHG_IRQ, |
| 119 | /* DCDC */ |
| 120 | OTG_FAIL_IRQ, |
| 121 | OTG_OC_DISABLE_SW_IRQ, |
| 122 | OTG_OC_HICCUP_IRQ, |
| 123 | BSM_ACTIVE_IRQ, |
| 124 | HIGH_DUTY_CYCLE_IRQ, |
| 125 | INPUT_CURRENT_LIMITING_IRQ, |
| 126 | CONCURRENT_MODE_DISABLE_IRQ, |
| 127 | SWITCHER_POWER_OK_IRQ, |
| 128 | /* BATIF */ |
| 129 | BAT_TEMP_IRQ, |
| 130 | ALL_CHNL_CONV_DONE_IRQ, |
| 131 | BAT_OV_IRQ, |
| 132 | BAT_LOW_IRQ, |
| 133 | BAT_THERM_OR_ID_MISSING_IRQ, |
| 134 | BAT_TERMINAL_MISSING_IRQ, |
| 135 | BUCK_OC_IRQ, |
| 136 | VPH_OV_IRQ, |
| 137 | /* USB */ |
| 138 | USBIN_COLLAPSE_IRQ, |
| 139 | USBIN_VASHDN_IRQ, |
| 140 | USBIN_UV_IRQ, |
| 141 | USBIN_OV_IRQ, |
| 142 | USBIN_PLUGIN_IRQ, |
| 143 | USBIN_REVI_CHANGE_IRQ, |
| 144 | USBIN_SRC_CHANGE_IRQ, |
| 145 | USBIN_ICL_CHANGE_IRQ, |
| 146 | /* DC */ |
| 147 | DCIN_VASHDN_IRQ, |
| 148 | DCIN_UV_IRQ, |
| 149 | DCIN_OV_IRQ, |
| 150 | DCIN_PLUGIN_IRQ, |
| 151 | DCIN_REVI_IRQ, |
| 152 | DCIN_PON_IRQ, |
| 153 | DCIN_EN_IRQ, |
| 154 | /* TYPEC */ |
| 155 | TYPEC_OR_RID_DETECTION_CHANGE_IRQ, |
| 156 | TYPEC_VPD_DETECT_IRQ, |
| 157 | TYPEC_CC_STATE_CHANGE_IRQ, |
| 158 | TYPEC_VCONN_OC_IRQ, |
| 159 | TYPEC_VBUS_CHANGE_IRQ, |
| 160 | TYPEC_ATTACH_DETACH_IRQ, |
| 161 | TYPEC_LEGACY_CABLE_DETECT_IRQ, |
| 162 | TYPEC_TRY_SNK_SRC_DETECT_IRQ, |
| 163 | /* MISC */ |
| 164 | WDOG_SNARL_IRQ, |
| 165 | WDOG_BARK_IRQ, |
| 166 | AICL_FAIL_IRQ, |
| 167 | AICL_DONE_IRQ, |
| 168 | SMB_EN_IRQ, |
| 169 | IMP_TRIGGER_IRQ, |
| 170 | TEMP_CHANGE_IRQ, |
| 171 | TEMP_CHANGE_SMB_IRQ, |
Ashay Jaiswal | 09feab8 | 2018-02-12 12:33:18 +0530 | [diff] [blame] | 172 | /* FLASH */ |
| 173 | VREG_OK_IRQ, |
| 174 | ILIM_S2_IRQ, |
| 175 | ILIM_S1_IRQ, |
| 176 | VOUT_DOWN_IRQ, |
| 177 | VOUT_UP_IRQ, |
| 178 | FLASH_STATE_CHANGE_IRQ, |
| 179 | TORCH_REQ_IRQ, |
| 180 | FLASH_EN_IRQ, |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 181 | /* END */ |
| 182 | SMB_IRQ_MAX, |
| 183 | }; |
| 184 | |
| 185 | enum float_options { |
| 186 | FLOAT_DCP = 1, |
| 187 | FLOAT_SDP = 2, |
| 188 | DISABLE_CHARGING = 3, |
| 189 | SUSPEND_INPUT = 4, |
| 190 | }; |
| 191 | |
Guru Das Srinagesh | 3ca1437 | 2018-06-01 11:30:56 -0700 | [diff] [blame] | 192 | enum chg_term_config_src { |
| 193 | ITERM_SRC_UNSPECIFIED, |
| 194 | ITERM_SRC_ADC, |
| 195 | ITERM_SRC_ANALOG |
| 196 | }; |
| 197 | |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 198 | struct smb_irq_info { |
| 199 | const char *name; |
| 200 | const irq_handler_t handler; |
| 201 | const bool wake; |
| 202 | const struct storm_watch storm_data; |
| 203 | struct smb_irq_data *irq_data; |
| 204 | int irq; |
| 205 | }; |
| 206 | |
| 207 | static const unsigned int smblib_extcon_cable[] = { |
| 208 | EXTCON_USB, |
| 209 | EXTCON_USB_HOST, |
| 210 | EXTCON_NONE, |
| 211 | }; |
| 212 | |
| 213 | /* EXTCON_USB and EXTCON_USB_HOST are mutually exclusive */ |
| 214 | static const u32 smblib_extcon_exclusive[] = {0x3, 0}; |
| 215 | |
| 216 | struct smb_regulator { |
| 217 | struct regulator_dev *rdev; |
| 218 | struct regulator_desc rdesc; |
| 219 | }; |
| 220 | |
| 221 | struct smb_irq_data { |
| 222 | void *parent_data; |
| 223 | const char *name; |
| 224 | struct storm_watch storm_data; |
| 225 | }; |
| 226 | |
| 227 | struct smb_chg_param { |
| 228 | const char *name; |
| 229 | u16 reg; |
| 230 | int min_u; |
| 231 | int max_u; |
| 232 | int step_u; |
| 233 | int (*get_proc)(struct smb_chg_param *param, |
| 234 | u8 val_raw); |
| 235 | int (*set_proc)(struct smb_chg_param *param, |
| 236 | int val_u, |
| 237 | u8 *val_raw); |
| 238 | }; |
| 239 | |
Ashay Jaiswal | a9e1091 | 2018-02-02 14:03:35 +0530 | [diff] [blame] | 240 | struct buck_boost_freq { |
| 241 | int freq_khz; |
| 242 | u8 val; |
| 243 | }; |
| 244 | |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 245 | struct smb_chg_freq { |
| 246 | unsigned int freq_5V; |
| 247 | unsigned int freq_6V_8V; |
| 248 | unsigned int freq_9V; |
| 249 | unsigned int freq_12V; |
| 250 | unsigned int freq_removal; |
| 251 | unsigned int freq_below_otg_threshold; |
| 252 | unsigned int freq_above_otg_threshold; |
| 253 | }; |
| 254 | |
| 255 | struct smb_params { |
| 256 | struct smb_chg_param fcc; |
| 257 | struct smb_chg_param fv; |
| 258 | struct smb_chg_param usb_icl; |
Harry Yang | f7b8990 | 2018-03-13 22:37:53 -0700 | [diff] [blame] | 259 | struct smb_chg_param icl_max_stat; |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 260 | struct smb_chg_param icl_stat; |
| 261 | struct smb_chg_param otg_cl; |
| 262 | struct smb_chg_param jeita_cc_comp_hot; |
| 263 | struct smb_chg_param jeita_cc_comp_cold; |
| 264 | struct smb_chg_param freq_switcher; |
Ashay Jaiswal | e0b3c47 | 2018-06-20 23:39:41 +0530 | [diff] [blame] | 265 | struct smb_chg_param aicl_5v_threshold; |
| 266 | struct smb_chg_param aicl_cont_threshold; |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 267 | }; |
| 268 | |
| 269 | struct parallel_params { |
| 270 | struct power_supply *psy; |
| 271 | }; |
| 272 | |
| 273 | struct smb_iio { |
| 274 | struct iio_channel *temp_chan; |
| 275 | struct iio_channel *temp_max_chan; |
| 276 | struct iio_channel *usbin_i_chan; |
| 277 | struct iio_channel *usbin_v_chan; |
| 278 | struct iio_channel *batt_i_chan; |
| 279 | struct iio_channel *connector_temp_chan; |
| 280 | struct iio_channel *connector_temp_thr1_chan; |
| 281 | struct iio_channel *connector_temp_thr2_chan; |
| 282 | struct iio_channel *connector_temp_thr3_chan; |
| 283 | }; |
| 284 | |
| 285 | struct smb_charger { |
| 286 | struct device *dev; |
| 287 | char *name; |
| 288 | struct regmap *regmap; |
| 289 | struct smb_irq_info *irq_info; |
| 290 | struct smb_params param; |
| 291 | struct smb_iio iio; |
| 292 | int *debug_mask; |
Harry Yang | 6afaea2 | 2018-03-26 19:11:07 -0700 | [diff] [blame] | 293 | int *pd_disabled; |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 294 | enum smb_mode mode; |
| 295 | struct smb_chg_freq chg_freq; |
| 296 | int smb_version; |
| 297 | int otg_delay_ms; |
| 298 | int *weak_chg_icl_ua; |
Ashay Jaiswal | 2068826 | 2018-04-25 11:45:34 +0530 | [diff] [blame] | 299 | struct qpnp_vadc_chip *vadc_dev; |
Ashay Jaiswal | f2ca709 | 2018-05-22 21:33:15 +0530 | [diff] [blame] | 300 | bool pd_not_supported; |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 301 | |
| 302 | /* locks */ |
| 303 | struct mutex lock; |
| 304 | struct mutex ps_change_lock; |
Anirudh Ghayal | 75f8f81 | 2018-07-09 16:48:47 +0530 | [diff] [blame] | 305 | struct mutex vadc_lock; |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 306 | |
| 307 | /* power supplies */ |
| 308 | struct power_supply *batt_psy; |
| 309 | struct power_supply *usb_psy; |
| 310 | struct power_supply *dc_psy; |
| 311 | struct power_supply *bms_psy; |
| 312 | struct power_supply *usb_main_psy; |
| 313 | struct power_supply *usb_port_psy; |
| 314 | enum power_supply_type real_charger_type; |
| 315 | |
| 316 | /* notifiers */ |
| 317 | struct notifier_block nb; |
| 318 | |
| 319 | /* parallel charging */ |
| 320 | struct parallel_params pl; |
| 321 | |
| 322 | /* regulators */ |
| 323 | struct smb_regulator *vbus_vreg; |
| 324 | struct smb_regulator *vconn_vreg; |
| 325 | struct regulator *dpdm_reg; |
| 326 | |
| 327 | /* votables */ |
| 328 | struct votable *dc_suspend_votable; |
| 329 | struct votable *fcc_votable; |
| 330 | struct votable *fv_votable; |
| 331 | struct votable *usb_icl_votable; |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 332 | struct votable *awake_votable; |
| 333 | struct votable *pl_disable_votable; |
| 334 | struct votable *chg_disable_votable; |
| 335 | struct votable *pl_enable_votable_indirect; |
| 336 | struct votable *usb_irq_enable_votable; |
| 337 | |
| 338 | /* work */ |
| 339 | struct work_struct bms_update_work; |
| 340 | struct work_struct pl_update_work; |
Ashay Jaiswal | f05bd55 | 2018-04-12 18:11:00 +0530 | [diff] [blame] | 341 | struct work_struct jeita_update_work; |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 342 | struct delayed_work ps_change_timeout_work; |
| 343 | struct delayed_work clear_hdc_work; |
| 344 | struct delayed_work icl_change_work; |
| 345 | struct delayed_work pl_enable_work; |
| 346 | struct delayed_work uusb_otg_work; |
| 347 | struct delayed_work bb_removal_work; |
| 348 | |
Harry Yang | 6afaea2 | 2018-03-26 19:11:07 -0700 | [diff] [blame] | 349 | /* pd */ |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 350 | int voltage_min_uv; |
| 351 | int voltage_max_uv; |
| 352 | int pd_active; |
Harry Yang | 6afaea2 | 2018-03-26 19:11:07 -0700 | [diff] [blame] | 353 | bool pd_hard_reset; |
| 354 | bool pr_swap_in_progress; |
| 355 | bool early_usb_attach; |
| 356 | bool ok_to_pd; |
| 357 | bool typec_legacy; |
| 358 | |
| 359 | /* cached status */ |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 360 | bool system_suspend_supported; |
| 361 | int boost_threshold_ua; |
| 362 | int system_temp_level; |
| 363 | int thermal_levels; |
| 364 | int *thermal_mitigation; |
| 365 | int dcp_icl_ua; |
| 366 | int fake_capacity; |
| 367 | int fake_batt_status; |
| 368 | bool step_chg_enabled; |
| 369 | bool sw_jeita_enabled; |
| 370 | bool is_hdc; |
| 371 | bool chg_done; |
Ashay Jaiswal | a9e1091 | 2018-02-02 14:03:35 +0530 | [diff] [blame] | 372 | int connector_type; |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 373 | bool otg_en; |
| 374 | bool suspend_input_on_debug_batt; |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 375 | int default_icl_ua; |
| 376 | int otg_cl_ua; |
| 377 | bool uusb_apsd_rerun_done; |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 378 | int fake_input_current_limited; |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 379 | int typec_mode; |
| 380 | int usb_icl_change_irq_enabled; |
| 381 | u32 jeita_status; |
| 382 | u8 float_cfg; |
| 383 | bool use_extcon; |
| 384 | bool otg_present; |
Ashay Jaiswal | a9e1091 | 2018-02-02 14:03:35 +0530 | [diff] [blame] | 385 | int hw_max_icl_ua; |
Anirudh Ghayal | 1380d31 | 2018-02-23 00:01:43 +0530 | [diff] [blame] | 386 | int auto_recharge_soc; |
Ashay Jaiswal | f05bd55 | 2018-04-12 18:11:00 +0530 | [diff] [blame] | 387 | bool jeita_configured; |
Harry Yang | 6afaea2 | 2018-03-26 19:11:07 -0700 | [diff] [blame] | 388 | enum sink_src_mode sink_src_mode; |
Ashay Jaiswal | 0de6fb9 | 2018-06-12 17:23:45 +0530 | [diff] [blame] | 389 | bool hw_die_temp_mitigation; |
| 390 | bool hw_connector_mitigation; |
| 391 | int connector_pull_up; |
Ashay Jaiswal | e0b3c47 | 2018-06-20 23:39:41 +0530 | [diff] [blame] | 392 | int aicl_5v_threshold_mv; |
| 393 | int default_aicl_5v_threshold_mv; |
| 394 | int aicl_cont_threshold_mv; |
| 395 | int default_aicl_cont_threshold_mv; |
| 396 | bool aicl_max_reached; |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 397 | |
| 398 | /* workaround flag */ |
| 399 | u32 wa_flags; |
| 400 | int boost_current_ua; |
| 401 | |
| 402 | /* extcon for VBUS / ID notification to USB for uUSB */ |
| 403 | struct extcon_dev *extcon; |
| 404 | |
| 405 | /* battery profile */ |
| 406 | int batt_profile_fcc_ua; |
| 407 | int batt_profile_fv_uv; |
| 408 | |
| 409 | int usb_icl_delta_ua; |
| 410 | int pulse_cnt; |
| 411 | |
| 412 | int die_health; |
Ashay Jaiswal | 09feab8 | 2018-02-12 12:33:18 +0530 | [diff] [blame] | 413 | |
| 414 | /* flash */ |
| 415 | u32 flash_derating_soc; |
| 416 | u32 flash_disable_soc; |
| 417 | u32 headroom_mode; |
| 418 | bool flash_init_done; |
| 419 | bool flash_active; |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 420 | }; |
| 421 | |
| 422 | int smblib_read(struct smb_charger *chg, u16 addr, u8 *val); |
| 423 | int smblib_masked_write(struct smb_charger *chg, u16 addr, u8 mask, u8 val); |
| 424 | int smblib_write(struct smb_charger *chg, u16 addr, u8 val); |
Anirudh Ghayal | 1380d31 | 2018-02-23 00:01:43 +0530 | [diff] [blame] | 425 | int smblib_batch_write(struct smb_charger *chg, u16 addr, u8 *val, int count); |
| 426 | int smblib_batch_read(struct smb_charger *chg, u16 addr, u8 *val, int count); |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 427 | |
| 428 | int smblib_get_charge_param(struct smb_charger *chg, |
| 429 | struct smb_chg_param *param, int *val_u); |
| 430 | int smblib_get_usb_suspend(struct smb_charger *chg, int *suspend); |
Ashay Jaiswal | e0b3c47 | 2018-06-20 23:39:41 +0530 | [diff] [blame] | 431 | int smblib_get_aicl_cont_threshold(struct smb_chg_param *param, u8 val_raw); |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 432 | int smblib_enable_charging(struct smb_charger *chg, bool enable); |
| 433 | int smblib_set_charge_param(struct smb_charger *chg, |
| 434 | struct smb_chg_param *param, int val_u); |
| 435 | int smblib_set_usb_suspend(struct smb_charger *chg, bool suspend); |
| 436 | int smblib_set_dc_suspend(struct smb_charger *chg, bool suspend); |
| 437 | |
| 438 | int smblib_mapping_soc_from_field_value(struct smb_chg_param *param, |
| 439 | int val_u, u8 *val_raw); |
| 440 | int smblib_mapping_cc_delta_to_field_value(struct smb_chg_param *param, |
| 441 | u8 val_raw); |
| 442 | int smblib_mapping_cc_delta_from_field_value(struct smb_chg_param *param, |
| 443 | int val_u, u8 *val_raw); |
| 444 | int smblib_set_chg_freq(struct smb_chg_param *param, |
| 445 | int val_u, u8 *val_raw); |
Ashay Jaiswal | a9e1091 | 2018-02-02 14:03:35 +0530 | [diff] [blame] | 446 | int smblib_set_prop_boost_current(struct smb_charger *chg, |
| 447 | const union power_supply_propval *val); |
Ashay Jaiswal | e0b3c47 | 2018-06-20 23:39:41 +0530 | [diff] [blame] | 448 | int smblib_set_aicl_cont_threshold(struct smb_chg_param *param, |
| 449 | int val_u, u8 *val_raw); |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 450 | int smblib_vbus_regulator_enable(struct regulator_dev *rdev); |
| 451 | int smblib_vbus_regulator_disable(struct regulator_dev *rdev); |
| 452 | int smblib_vbus_regulator_is_enabled(struct regulator_dev *rdev); |
| 453 | |
| 454 | int smblib_vconn_regulator_enable(struct regulator_dev *rdev); |
| 455 | int smblib_vconn_regulator_disable(struct regulator_dev *rdev); |
| 456 | int smblib_vconn_regulator_is_enabled(struct regulator_dev *rdev); |
| 457 | |
| 458 | irqreturn_t default_irq_handler(int irq, void *data); |
| 459 | irqreturn_t chg_state_change_irq_handler(int irq, void *data); |
| 460 | irqreturn_t batt_temp_changed_irq_handler(int irq, void *data); |
| 461 | irqreturn_t batt_psy_changed_irq_handler(int irq, void *data); |
| 462 | irqreturn_t usbin_uv_irq_handler(int irq, void *data); |
| 463 | irqreturn_t usb_plugin_irq_handler(int irq, void *data); |
| 464 | irqreturn_t usb_source_change_irq_handler(int irq, void *data); |
| 465 | irqreturn_t icl_change_irq_handler(int irq, void *data); |
| 466 | irqreturn_t typec_state_change_irq_handler(int irq, void *data); |
Harry Yang | 6afaea2 | 2018-03-26 19:11:07 -0700 | [diff] [blame] | 467 | irqreturn_t typec_attach_detach_irq_handler(int irq, void *data); |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 468 | irqreturn_t dc_plugin_irq_handler(int irq, void *data); |
| 469 | irqreturn_t high_duty_cycle_irq_handler(int irq, void *data); |
| 470 | irqreturn_t switcher_power_ok_irq_handler(int irq, void *data); |
| 471 | irqreturn_t wdog_bark_irq_handler(int irq, void *data); |
Ashay Jaiswal | a9e1091 | 2018-02-02 14:03:35 +0530 | [diff] [blame] | 472 | irqreturn_t typec_or_rid_detection_change_irq_handler(int irq, void *data); |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 473 | |
| 474 | int smblib_get_prop_input_suspend(struct smb_charger *chg, |
| 475 | union power_supply_propval *val); |
| 476 | int smblib_get_prop_batt_present(struct smb_charger *chg, |
| 477 | union power_supply_propval *val); |
| 478 | int smblib_get_prop_batt_capacity(struct smb_charger *chg, |
| 479 | union power_supply_propval *val); |
| 480 | int smblib_get_prop_batt_status(struct smb_charger *chg, |
| 481 | union power_supply_propval *val); |
| 482 | int smblib_get_prop_batt_charge_type(struct smb_charger *chg, |
| 483 | union power_supply_propval *val); |
| 484 | int smblib_get_prop_batt_charge_done(struct smb_charger *chg, |
| 485 | union power_supply_propval *val); |
| 486 | int smblib_get_prop_batt_health(struct smb_charger *chg, |
| 487 | union power_supply_propval *val); |
| 488 | int smblib_get_prop_system_temp_level(struct smb_charger *chg, |
| 489 | union power_supply_propval *val); |
| 490 | int smblib_get_prop_system_temp_level_max(struct smb_charger *chg, |
| 491 | union power_supply_propval *val); |
| 492 | int smblib_get_prop_input_current_limited(struct smb_charger *chg, |
| 493 | union power_supply_propval *val); |
| 494 | int smblib_get_prop_batt_voltage_now(struct smb_charger *chg, |
| 495 | union power_supply_propval *val); |
| 496 | int smblib_get_prop_batt_current_now(struct smb_charger *chg, |
| 497 | union power_supply_propval *val); |
Guru Das Srinagesh | 3ca1437 | 2018-06-01 11:30:56 -0700 | [diff] [blame] | 498 | int smblib_get_prop_batt_iterm(struct smb_charger *chg, |
| 499 | union power_supply_propval *val); |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 500 | int smblib_get_prop_batt_temp(struct smb_charger *chg, |
| 501 | union power_supply_propval *val); |
| 502 | int smblib_get_prop_batt_charge_counter(struct smb_charger *chg, |
| 503 | union power_supply_propval *val); |
Subbaraman Narayanamurthy | c4feb89 | 2018-05-07 18:43:45 -0700 | [diff] [blame] | 504 | int smblib_get_prop_batt_cycle_count(struct smb_charger *chg, |
| 505 | union power_supply_propval *val); |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 506 | int smblib_set_prop_input_suspend(struct smb_charger *chg, |
| 507 | const union power_supply_propval *val); |
| 508 | int smblib_set_prop_batt_capacity(struct smb_charger *chg, |
| 509 | const union power_supply_propval *val); |
| 510 | int smblib_set_prop_batt_status(struct smb_charger *chg, |
| 511 | const union power_supply_propval *val); |
| 512 | int smblib_set_prop_system_temp_level(struct smb_charger *chg, |
| 513 | const union power_supply_propval *val); |
| 514 | int smblib_set_prop_input_current_limited(struct smb_charger *chg, |
| 515 | const union power_supply_propval *val); |
| 516 | |
| 517 | int smblib_get_prop_dc_present(struct smb_charger *chg, |
| 518 | union power_supply_propval *val); |
| 519 | int smblib_get_prop_dc_online(struct smb_charger *chg, |
| 520 | union power_supply_propval *val); |
| 521 | int smblib_get_prop_dc_current_max(struct smb_charger *chg, |
| 522 | union power_supply_propval *val); |
| 523 | int smblib_set_prop_dc_current_max(struct smb_charger *chg, |
| 524 | const union power_supply_propval *val); |
| 525 | int smblib_get_prop_usb_present(struct smb_charger *chg, |
| 526 | union power_supply_propval *val); |
| 527 | int smblib_get_prop_usb_online(struct smb_charger *chg, |
| 528 | union power_supply_propval *val); |
| 529 | int smblib_get_prop_usb_suspend(struct smb_charger *chg, |
| 530 | union power_supply_propval *val); |
| 531 | int smblib_get_prop_usb_voltage_max(struct smb_charger *chg, |
| 532 | union power_supply_propval *val); |
Umang Agrawal | 9fb865a | 2018-06-25 16:24:00 +0530 | [diff] [blame] | 533 | int smblib_get_prop_usb_voltage_max_design(struct smb_charger *chg, |
| 534 | union power_supply_propval *val); |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 535 | int smblib_get_prop_typec_cc_orientation(struct smb_charger *chg, |
| 536 | union power_supply_propval *val); |
| 537 | int smblib_get_prop_typec_power_role(struct smb_charger *chg, |
| 538 | union power_supply_propval *val); |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 539 | int smblib_get_prop_input_current_settled(struct smb_charger *chg, |
| 540 | union power_supply_propval *val); |
| 541 | int smblib_get_prop_input_voltage_settled(struct smb_charger *chg, |
| 542 | union power_supply_propval *val); |
| 543 | int smblib_get_prop_pd_in_hard_reset(struct smb_charger *chg, |
| 544 | union power_supply_propval *val); |
| 545 | int smblib_get_pe_start(struct smb_charger *chg, |
| 546 | union power_supply_propval *val); |
| 547 | int smblib_get_prop_die_health(struct smb_charger *chg, |
| 548 | union power_supply_propval *val); |
| 549 | int smblib_set_prop_pd_current_max(struct smb_charger *chg, |
| 550 | const union power_supply_propval *val); |
| 551 | int smblib_set_prop_sdp_current_max(struct smb_charger *chg, |
| 552 | const union power_supply_propval *val); |
| 553 | int smblib_set_prop_pd_voltage_max(struct smb_charger *chg, |
| 554 | const union power_supply_propval *val); |
| 555 | int smblib_set_prop_pd_voltage_min(struct smb_charger *chg, |
| 556 | const union power_supply_propval *val); |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 557 | int smblib_set_prop_typec_power_role(struct smb_charger *chg, |
| 558 | const union power_supply_propval *val); |
| 559 | int smblib_set_prop_pd_active(struct smb_charger *chg, |
| 560 | const union power_supply_propval *val); |
| 561 | int smblib_set_prop_pd_in_hard_reset(struct smb_charger *chg, |
| 562 | const union power_supply_propval *val); |
| 563 | int smblib_set_prop_ship_mode(struct smb_charger *chg, |
| 564 | const union power_supply_propval *val); |
| 565 | void smblib_suspend_on_debug_battery(struct smb_charger *chg); |
| 566 | int smblib_rerun_apsd_if_required(struct smb_charger *chg); |
| 567 | int smblib_get_prop_fcc_delta(struct smb_charger *chg, |
| 568 | union power_supply_propval *val); |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 569 | int smblib_dp_dm(struct smb_charger *chg, int val); |
| 570 | int smblib_disable_hw_jeita(struct smb_charger *chg, bool disable); |
Ashay Jaiswal | e0b3c47 | 2018-06-20 23:39:41 +0530 | [diff] [blame] | 571 | int smblib_run_aicl(struct smb_charger *chg, int type); |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 572 | int smblib_set_icl_current(struct smb_charger *chg, int icl_ua); |
| 573 | int smblib_get_icl_current(struct smb_charger *chg, int *icl_ua); |
| 574 | int smblib_get_charge_current(struct smb_charger *chg, int *total_current_ua); |
| 575 | int smblib_get_prop_pr_swap_in_progress(struct smb_charger *chg, |
| 576 | union power_supply_propval *val); |
| 577 | int smblib_set_prop_pr_swap_in_progress(struct smb_charger *chg, |
| 578 | const union power_supply_propval *val); |
| 579 | int smblib_stat_sw_override_cfg(struct smb_charger *chg, bool override); |
Ashay Jaiswal | a55b7ed | 2018-03-23 17:23:48 +0530 | [diff] [blame] | 580 | int smblib_configure_wdog(struct smb_charger *chg, bool enable); |
Ashay Jaiswal | 4d334f4 | 2018-04-25 10:58:49 +0530 | [diff] [blame] | 581 | int smblib_force_vbus_voltage(struct smb_charger *chg, u8 val); |
Ashay Jaiswal | c96380de | 2018-05-16 12:02:36 +0530 | [diff] [blame] | 582 | int smblib_configure_hvdcp_apsd(struct smb_charger *chg, bool enable); |
Ashay Jaiswal | cbdf2e8 | 2018-05-27 23:59:01 +0530 | [diff] [blame] | 583 | int smblib_icl_override(struct smb_charger *chg, bool override); |
Harry Yang | 4b7db0f | 2017-11-27 10:50:44 -0800 | [diff] [blame] | 584 | |
| 585 | int smblib_init(struct smb_charger *chg); |
| 586 | int smblib_deinit(struct smb_charger *chg); |
| 587 | #endif /* __SMB5_CHARGER_H */ |