summaryrefslogtreecommitdiff
path: root/board/fizz/board.c
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2018-02-02 17:37:19 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-08 01:23:59 -0800
commitbb5f21ed1a773dcfa58e8482918c60521e00b538 (patch)
tree512fdb8cc22ef7d333b47fdf515f54705b5e0a1f /board/fizz/board.c
parent131b7dcc44e6b1918ce8872e1e0eeaf221920dd5 (diff)
downloadchrome-ec-bb5f21ed1a773dcfa58e8482918c60521e00b538.tar.gz
Fizz: Monitor input current (version 2.0)
Fizz has three FETs connected to three registers: PR257, PR258, PR7824. These control the thresholds of the current monitoring system. PR257 PR7824 PR258 For BJ (65W or 90W) off off off For 4.35A (87W) on off off For 3.25A (65W) off off on For 3.00A (60W) off on off The system power consumption is capped by PR259, which is stuffed differently depending on the SKU (65W v.s. 90W or U42 v.s. U22). So, we only need to monitor type-c adapters. For example: a 90W system powered by 65W type-c charger b 65W system powered by 60W type-c charger c 65W system powered by 87W type-c charger In a case such as (c), we actually do not need to monitor the current because the max is capped by PR259. AP is expected to read type-c adapter wattage from EC and control power consumption to avoid over-current or system browns out. The current monitoring system doesn't support less than 3A (e.g. 2.25A, 2.00A). These currents most likely won't be enough to power the system. However, if they're needed, EC can monitor PMON_PSYS and trigger H_PROCHOT by itself. BUG=b:72883633,b:64442692,b:72710630 BRANCH=none TEST=Boot Fizz on 60W/87W/BJ charger. Verify GPIOs are set as expected. Change-Id: Ic4c0e599f94b24b5e6c02bbf1998b0b89ecad7bf Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/900491 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'board/fizz/board.c')
-rw-r--r--board/fizz/board.c113
1 files changed, 90 insertions, 23 deletions
diff --git a/board/fizz/board.c b/board/fizz/board.c
index 2861ee5fbe..6bbaf25e70 100644
--- a/board/fizz/board.c
+++ b/board/fizz/board.c
@@ -92,21 +92,14 @@ static void adp_in_deferred(void)
if (!level) {
/* BJ is inserted but the voltage isn't effective because PU3
* is still disabled. */
- pi.voltage = 19000;
- if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
- /* If type-c voltage is higher than BJ voltage, PU3 will
- * shut down due to reverse current protection. So, we
- * need to lower the voltage first. */
- if (charge_manager_get_charger_voltage() > pi.voltage) {
- pd_set_external_voltage_limit(
- CHARGE_PORT_TYPEC0, pi.voltage);
- hook_call_deferred(&adp_in_deferred_data,
- ADP_DEBOUNCE_MS * MSEC);
- return;
- }
- /* Set it to the default. Will be updated by AP. */
+ pi.voltage = 19500;
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
+ /*
+ * It doesn't matter what we set here because we'll
+ * brown out anyway when charge_manager switches
+ * input.
+ */
pi.current = 3330;
- }
}
charge_manager_update_charge(CHARGE_SUPPLIER_DEDICATED,
DEDICATED_CHARGE_PORT, &pi);
@@ -469,16 +462,15 @@ static void board_init(void)
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
-void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
-{
- /* Turn on/off power shortage alert. Performs the same check as
- * system_can_boot_ap(). It's repeated here because charge_manager
- * hasn't updated charge_current/voltage when board_set_charge_limit
- * is called. */
- led_alert(charge_ma * charge_mv <
- CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW * 1000);
+/* Mapping to the old schematics */
+#define GPIO_U42_P GPIO_TYPE_C_60W
+#define GPIO_U22_C GPIO_TYPE_C_65W
+/*
+ * Board version 2.1 or before uses a different current monitoring circuitry.
+ */
+static void set_charge_limit(int charge_ma)
+{
/*
* We have two FETs connected to two registers: PR257 & PR258.
* These control thresholds of the over current monitoring system.
@@ -508,6 +500,81 @@ void board_set_charge_limit(int port, int supplier, int charge_ma,
}
}
+void board_set_charge_limit(int port, int supplier, int charge_ma,
+ int max_ma, int charge_mv)
+{
+ uint32_t brd_ver = 0;
+ int p87w = 0, p65w = 0, p60w = 0;
+
+ /*
+ * Turn on/off power shortage alert. Performs the same check as
+ * system_can_boot_ap(). It's repeated here because charge_manager
+ * hasn't updated charge_current/voltage when board_set_charge_limit
+ * is called.
+ */
+ led_alert(charge_ma * charge_mv <
+ CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW * 1000);
+
+ /*
+ * In terms of timing, this should always work because
+ * HOOK_PRIO_CHARGE_MANAGER_INIT is notified after HOOK_PRIO_INIT_I2C.
+ * If CBI isn't initialized or contains invalid data, we assume it's
+ * a new board.
+ */
+ if (cbi_get_board_version(&brd_ver) == EC_SUCCESS && brd_ver < 0x0202)
+ return set_charge_limit(charge_ma);
+ /*
+ * We have three FETs connected to three registers: PR257, PR258,
+ * PR7824. These control the thresholds of the current monitoring
+ * system.
+ *
+ * PR257 PR7824 PR258
+ * For BJ (65W or 90W) off off off
+ * For 4.35A (87W) on off off
+ * For 3.25A (65W) off off on
+ * For 3.00A (60W) off on off
+ *
+ * The system power consumption is capped by PR259, which is stuffed
+ * differently depending on the SKU (65W v.s. 90W or U42 v.s. U22).
+ * So, we only need to monitor type-c adapters. For example:
+ *
+ * a 90W system powered by 65W type-c charger
+ * b 65W system powered by 60W type-c charger
+ * c 65W system powered by 87W type-c charger
+ *
+ * In a case such as (c), we actually do not need to monitor the current
+ * because the max is capped by PR259.
+ *
+ * AP is expected to read type-c adapter wattage from EC and control
+ * power consumption to avoid over-current or system browns out.
+ *
+ */
+ if (supplier != CHARGE_SUPPLIER_DEDICATED) {
+ /* Apple 87W charger offers 4.3A @20V. */
+ if (charge_ma >= 4300) {
+ p87w = 1;
+ } else if (charge_ma >= 3250) {
+ p65w = 1;
+ } else if (charge_ma >= 3000) {
+ p60w = 1;
+ } else {
+ /*
+ * TODO:http://crosbug.com/p/65013352.
+ * The current monitoring system doesn't support lower
+ * current. These currents are most likely not enough to
+ * power the system. However, if they're needed, EC can
+ * monitor PMON_PSYS and trigger H_PROCHOT by itself.
+ */
+ p60w = 1;
+ CPRINTS("Current %dmA not supported", charge_ma);
+ }
+ }
+
+ gpio_set_level(GPIO_TYPE_C_87W, p87w);
+ gpio_set_level(GPIO_TYPE_C_65W, p65w);
+ gpio_set_level(GPIO_TYPE_C_60W, p60w);
+}
+
enum battery_present battery_is_present(void)
{
/* The GPIO is low when the battery is present */