|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | #include "battery_smart.h" |
| 7 | +#include "charge_manager.h" |
7 | 8 | #include "charger.h" |
8 | 9 | #include "console.h" |
9 | 10 | #include "driver/charger/isl9241.h" |
@@ -252,6 +253,73 @@ ZTEST_F(isl9241_driver, test_dump_registers) |
252 | 253 | } |
253 | 254 | } |
254 | 255 |
|
| 256 | +/* |
| 257 | + * An NVDC -> bypass entry that aborted while waiting for VSYS left |
| 258 | + * CONTROL1.BGATE_OFF set, so the battery stayed disconnected on AC. |
| 259 | + */ |
| 260 | +ZTEST_F(isl9241_driver, test_bypass_abort_releases_bgate) |
| 261 | +{ |
| 262 | + struct i2c_common_emul_data *common_data = |
| 263 | + isl9241_emul_get_i2c_common_data(fixture->isl9241_emul); |
| 264 | + uint16_t control1; |
| 265 | + |
| 266 | + if (!IS_ENABLED(CONFIG_PLATFORM_EC_CHARGER_BYPASS_MODE)) |
| 267 | + ztest_test_skip(); |
| 268 | + |
| 269 | + /* Make NVDC -> bypass abort while it waits for VSYS. */ |
| 270 | + i2c_common_emul_set_read_fail_reg(common_data, |
| 271 | + ISL9241_REG_VSYS_ADC_RESULTS); |
| 272 | + charger_enable_bypass_mode(CHARGER_SOLO, true); |
| 273 | + i2c_common_emul_set_read_fail_reg(common_data, |
| 274 | + I2C_COMMON_EMUL_NO_FAIL_REG); |
| 275 | + |
| 276 | + control1 = isl9241_emul_peek(fixture->isl9241_emul, |
| 277 | + ISL9241_REG_CONTROL1); |
| 278 | + zassert_false(control1 & ISL9241_CONTROL1_BGATE_OFF, |
| 279 | + "BGATE still forced off after aborted entry: 0x%04x", |
| 280 | + control1); |
| 281 | +} |
| 282 | + |
| 283 | +/* Same as above, but the entry aborted because VSYS never reached target. */ |
| 284 | +ZTEST_F(isl9241_driver, test_bypass_timeout_releases_bgate) |
| 285 | +{ |
| 286 | + struct charge_port_info charge = { .current = 3000, .voltage = 20000 }; |
| 287 | + struct charge_port_info none = { 0 }; |
| 288 | + uint16_t control0, control1; |
| 289 | + |
| 290 | + if (!IS_ENABLED(CONFIG_PLATFORM_EC_CHARGER_BYPASS_MODE)) |
| 291 | + ztest_test_skip(); |
| 292 | + |
| 293 | + /* VSYS stays at 0 while the target follows the 20 V supply. */ |
| 294 | + k_msleep(1000); |
| 295 | + charge_manager_update_charge(CHARGE_SUPPLIER_TYPEC, USBC_PORT_C0, |
| 296 | + &charge); |
| 297 | + /* Port 0 is dual-role, so it charges only as the override port. */ |
| 298 | + zassert_ok(charge_manager_set_override(USBC_PORT_C0)); |
| 299 | + k_msleep(500); |
| 300 | + zassert_equal(charge_manager_get_charger_voltage(), charge.voltage, |
| 301 | + "port %d supplier %d", |
| 302 | + charge_manager_get_active_charge_port(), |
| 303 | + charge_manager_get_supplier()); |
| 304 | + isl9241_emul_set_vsys(fixture->isl9241_emul, 0); |
| 305 | + |
| 306 | + charger_enable_bypass_mode(CHARGER_SOLO, true); |
| 307 | + charge_manager_set_override(OVERRIDE_OFF); |
| 308 | + charge_manager_update_charge(CHARGE_SUPPLIER_TYPEC, USBC_PORT_C0, |
| 309 | + &none); |
| 310 | + k_msleep(500); |
| 311 | + |
| 312 | + control0 = isl9241_emul_peek(fixture->isl9241_emul, |
| 313 | + ISL9241_REG_CONTROL0); |
| 314 | + control1 = isl9241_emul_peek(fixture->isl9241_emul, |
| 315 | + ISL9241_REG_CONTROL1); |
| 316 | + zassert_false(control0 & ISL9241_CONTROL0_EN_BYPASS_GATE, |
| 317 | + "Bypass entry did not abort: 0x%04x", control0); |
| 318 | + zassert_false(control1 & ISL9241_CONTROL1_BGATE_OFF, |
| 319 | + "BGATE still forced off after aborted entry: 0x%04x", |
| 320 | + control1); |
| 321 | +} |
| 322 | + |
255 | 323 | ZTEST(isl9241_driver, test_prochot_dump) |
256 | 324 | { |
257 | 325 | /* |
|
0 commit comments