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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
@@ -2139,6 +2139,7 @@ bool usb_online, dc_online; u8 stat; int rc, suspend = 0, input_present = 0; + int soc = 0; if (chg->fake_chg_status_on_debug_batt) { rc = smblib_get_prop_from_bms(chg, SMB5_QG_DEBUG_BATTERY, @@ -2152,6 +2153,7 @@ } } +#if 0 rc = smblib_get_prop_batt_health(chg, &pval); if (rc < 0) { smblib_err(chg, "Couldn't get batt health rc=%d\n", rc); @@ -2167,6 +2169,7 @@ val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; return 0; } +#endif /* * If SOC = 0 and we are discharging with input connected, report @@ -2174,6 +2177,7 @@ */ smblib_is_input_present(chg, &input_present); rc = smblib_get_prop_from_bms(chg, SMB5_QG_CAPACITY, &pval.intval); + soc = pval.intval; if (!rc && pval.intval == 0 && input_present) { rc = smblib_get_prop_from_bms(chg, SMB5_QG_CURRENT_NOW, &pval.intval); @@ -2240,6 +2244,9 @@ stat = stat & BATTERY_CHARGER_STATUS_MASK; if (!usb_online && !dc_online) { + val->intval = POWER_SUPPLY_STATUS_DISCHARGING; + return rc; +#if 0 switch (stat) { case TERMINATE_CHARGE: fallthrough; @@ -2251,6 +2258,7 @@ break; } return rc; +#endif } switch (stat) { @@ -2266,12 +2274,24 @@ case TERMINATE_CHARGE: fallthrough; case INHIBIT_CHARGE: - val->intval = POWER_SUPPLY_STATUS_FULL; + if (usb_online) { + if (soc > 99) { + val->intval = POWER_SUPPLY_STATUS_FULL; + } else { + val->intval = POWER_SUPPLY_STATUS_CHARGING; + } + } else { + val->intval = POWER_SUPPLY_STATUS_DISCHARGING; + } break; case DISABLE_CHARGE: fallthrough; case PAUSE_CHARGE: - val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; + if (!usb_online) { + val->intval = POWER_SUPPLY_STATUS_DISCHARGING; + } else { + val->intval = POWER_SUPPLY_STATUS_CHARGING; + } break; default: val->intval = POWER_SUPPLY_STATUS_UNKNOWN; @@ -2302,6 +2322,12 @@ return 0; } + if (usb_online && (chg->fake_batt_status == POWER_SUPPLY_STATUS_DISCHARGING + || chg->fake_batt_status == POWER_SUPPLY_STATUS_CHARGING)) { + val->intval = chg->fake_batt_status; + return 0; + } + rc = smblib_read(chg, BATTERY_CHARGER_STATUS_5_REG, &stat); if (rc < 0) { smblib_err(chg, "Couldn't read BATTERY_CHARGER_STATUS_2 rc=%d\n", @@ -2312,8 +2338,8 @@ stat &= ENABLE_TRICKLE_BIT | ENABLE_PRE_CHARGING_BIT | ENABLE_FULLON_MODE_BIT; - if (!stat) - val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; + if (!stat && !usb_online) + val->intval = POWER_SUPPLY_STATUS_DISCHARGING; return 0; } @@ -2389,22 +2415,26 @@ } } - rc = smblib_read(chg, BATTERY_CHARGER_STATUS_7_REG, &stat); + rc = smblib_get_prop_from_bms(chg, SMB5_QG_TEMP, &pval.intval); if (rc < 0) { - smblib_err(chg, "Couldn't read BATTERY_CHARGER_STATUS_2 rc=%d\n", - rc); - return rc; + pr_err("Couldn't read batt temp prop rc=%d\n", rc); + return -EINVAL; } - if (stat & BAT_TEMP_STATUS_TOO_COLD_BIT) - val->intval = POWER_SUPPLY_HEALTH_COLD; - else if (stat & BAT_TEMP_STATUS_TOO_HOT_BIT) + + pval.intval = pval.intval / 10; + if (pval.intval >= 60) { val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; - else if (stat & BAT_TEMP_STATUS_COLD_SOFT_BIT) - val->intval = POWER_SUPPLY_HEALTH_COOL; - else if (stat & BAT_TEMP_STATUS_HOT_SOFT_BIT) + } else if (pval.intval >= 58 && pval.intval < 60) { + val->intval = POWER_SUPPLY_HEALTH_HOT; + } else if (pval.intval >= 45 && pval.intval < 58) { val->intval = POWER_SUPPLY_HEALTH_WARM; - else + } else if (pval.intval >= 15 && pval.intval < 45) { val->intval = POWER_SUPPLY_HEALTH_GOOD; + } else if (pval.intval >= 0 && pval.intval < 15) { + val->intval = POWER_SUPPLY_HEALTH_COOL; + } else if (pval.intval < 0) { + val->intval = POWER_SUPPLY_HEALTH_COLD; + } done: return rc; @@ -2591,13 +2621,20 @@ int smblib_set_prop_batt_status(struct smb_charger *chg, const union power_supply_propval *val) { +#if 0 /* Faking battery full */ if (val->intval == POWER_SUPPLY_STATUS_FULL) chg->fake_batt_status = val->intval; else chg->fake_batt_status = -EINVAL; +#endif + if (val->intval < 0) { + chg->fake_batt_status = -EINVAL; + } else { + chg->fake_batt_status = val->intval; + } - power_supply_changed(chg->batt_psy); + //power_supply_changed(chg->batt_psy); return 0; } @@ -6017,6 +6054,7 @@ vote(chg->awake_votable, PL_DELAY_VOTER, true, 0); schedule_delayed_work(&chg->pl_enable_work, msecs_to_jiffies(PL_DELAY_MS)); + chg->float_retry_flag = 1; } else { /* Disable SW Thermal Regulation */ rc = smblib_set_sw_thermal_regulation(chg, false); @@ -6074,6 +6112,7 @@ smblib_err(chg, "Couldn't disable DPDM rc=%d\n", rc); smblib_update_usb_type(chg); + chg->float_retry_flag = 0; } if (chg->connector_type == QTI_POWER_SUPPLY_CONNECTOR_MICRO_USB) @@ -6100,9 +6139,32 @@ return IRQ_HANDLED; } +static void smblib_float_retry_work(struct work_struct *work) +{ + int rc = 0; + struct smb_charger *chg = container_of(work, struct smb_charger, + float_retry_work.work); + + rc = smblib_request_dpdm(chg, false); + if (rc < 0) + smblib_err(chg, "Couldn't to disable DPDM rc=%d\n", rc); + + msleep(100); + smblib_rerun_apsd_if_required(chg); + + chg->float_retry_flag = 0; + smblib_dbg(chg, PR_PARALLEL, "float detected due to slow plug \n"); +} + +#define FLOAT_RETRY_DELAY 8000 /*8s*/ static void smblib_handle_slow_plugin_timeout(struct smb_charger *chg, bool rising) { + if (rising && chg->float_retry_flag) + schedule_delayed_work(&chg->float_retry_work, msecs_to_jiffies(FLOAT_RETRY_DELAY)); + else if (!rising) + cancel_delayed_work_sync(&chg->float_retry_work); + smblib_dbg(chg, PR_INTERRUPT, "IRQ: slow-plugin-timeout %s\n", rising ? "rising" : "falling"); } @@ -8833,6 +8895,7 @@ INIT_DELAYED_WORK(&chg->lpd_ra_open_work, smblib_lpd_ra_open_work); INIT_DELAYED_WORK(&chg->lpd_detach_work, smblib_lpd_detach_work); INIT_DELAYED_WORK(&chg->raise_qc3_vbus_work, smblib_raise_qc3_vbus_work); + INIT_DELAYED_WORK(&chg->float_retry_work, smblib_float_retry_work); INIT_DELAYED_WORK(&chg->thermal_regulation_work, smblib_thermal_regulation_work); INIT_DELAYED_WORK(&chg->usbov_dbc_work, smblib_usbov_dbc_work); @@ -8892,6 +8955,7 @@ chg->dr_mode = TYPEC_PORT_DRP; chg->raise_vbus_to_detect = false; chg->qc2_unsupported = false; + chg->float_retry_flag = 1; apsd_result = smblib_update_usb_type(chg); switch (chg->mode) { @@ -9016,6 +9080,7 @@ cancel_delayed_work_sync(&chg->lpd_ra_open_work); cancel_delayed_work_sync(&chg->lpd_detach_work); cancel_delayed_work_sync(&chg->raise_qc3_vbus_work); + cancel_delayed_work_sync(&chg->float_retry_work); cancel_delayed_work_sync(&chg->thermal_regulation_work); cancel_delayed_work_sync(&chg->usbov_dbc_work); cancel_delayed_work_sync(&chg->role_reversal_check);
@@ -522,6 +522,7 @@ struct delayed_work pr_lock_clear_work; struct delayed_work role_reversal_check; struct delayed_work raise_qc3_vbus_work; + struct delayed_work float_retry_work; struct alarm lpd_recheck_timer; struct alarm moisture_protection_alarm; @@ -690,6 +691,7 @@ bool support_ffc; bool qc2_unsupported; int dpdm_qc3p0_flag; + int float_retry_flag; }; int smblib_read(struct smb_charger *chg, u16 addr, u8 *val);
@@ -671,8 +671,13 @@ start_usb_peripheral(pd); typec_set_data_role(pd->typec_port, TYPEC_DEVICE); typec_set_pwr_role(pd->typec_port, TYPEC_SINK); - typec_set_pwr_opmode(pd->typec_port, - pd->typec_mode - QTI_POWER_SUPPLY_TYPEC_SOURCE_DEFAULT); + if (pd->typec_mode <= QTI_POWER_SUPPLY_TYPEC_NONE) { + typec_set_pwr_opmode(pd->typec_port, TYPEC_PWR_MODE_USB); + } else if (pd->typec_mode < QTI_POWER_SUPPLY_TYPEC_SOURCE_DEFAULT) { + typec_set_pwr_opmode(pd->typec_port, pd->typec_mode - QTI_POWER_SUPPLY_TYPEC_NONE); + } else { + typec_set_pwr_opmode(pd->typec_port, pd->typec_mode - QTI_POWER_SUPPLY_TYPEC_SOURCE_DEFAULT); + } if (!pd->partner) { memset(&pd->partner_identity, 0, sizeof(pd->partner_identity)); pd->partner_desc.usb_pd = false; @@ -2833,8 +2838,13 @@ typec_set_pwr_role(pd->typec_port, TYPEC_SINK); if (!pd->partner) { - typec_set_pwr_opmode(pd->typec_port, - pd->typec_mode - QTI_POWER_SUPPLY_TYPEC_SOURCE_DEFAULT); + if (pd->typec_mode <= QTI_POWER_SUPPLY_TYPEC_NONE) { + typec_set_pwr_opmode(pd->typec_port, TYPEC_PWR_MODE_USB); + } else if (pd->typec_mode < QTI_POWER_SUPPLY_TYPEC_SOURCE_DEFAULT) { + typec_set_pwr_opmode(pd->typec_port, pd->typec_mode - QTI_POWER_SUPPLY_TYPEC_NONE); + } else { + typec_set_pwr_opmode(pd->typec_port, pd->typec_mode - QTI_POWER_SUPPLY_TYPEC_SOURCE_DEFAULT); + } memset(&pd->partner_identity, 0, sizeof(pd->partner_identity)); pd->partner_desc.usb_pd = false; pd->partner_desc.accessory = TYPEC_ACCESSORY_NONE; @@ -4011,8 +4021,7 @@ } if (val.intval == POWER_SUPPLY_TYPE_USB || - val.intval == POWER_SUPPLY_TYPE_USB_CDP || - val.intval == QTI_POWER_SUPPLY_TYPE_USB_FLOAT) { + val.intval == POWER_SUPPLY_TYPE_USB_CDP) { usbpd_dbg(&pd->dev, "typec mode:%d type:%d\n", typec_mode, val.intval); pd->typec_mode = typec_mode; @@ -4066,8 +4075,7 @@ } if (val.intval == POWER_SUPPLY_TYPE_USB || - val.intval == POWER_SUPPLY_TYPE_USB_CDP || - val.intval == QTI_POWER_SUPPLY_TYPE_USB_FLOAT) + val.intval == POWER_SUPPLY_TYPE_USB_CDP) queue_work(pd->wq, &pd->start_periph_work); } return;
|