diff options
author | Jett Rink <jettrink@chromium.org> | 2018-04-20 10:08:44 -0600 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-04-26 17:00:45 -0700 |
commit | a34e253d28d8ac4d787856ca9f4c790b4a5c2e27 (patch) | |
tree | 5547f0baa64c029503b5c36c584ba6546c0b35e2 | |
parent | 043ee28da36f45eeda1015a65827ff5feca00b5d (diff) | |
download | chrome-ec-a34e253d28d8ac4d787856ca9f4c790b4a5c2e27.tar.gz |
octopus: move common usb/battery code into baseboard
Also implement a few remaining usb function for bip
BRANCH=none
BUG=b:75972988,b:76218141,b:74132235,b:78344554
TEST=verified yorp still functions
Change-Id: I201408b5db689ac4a5bcab0011bc38698271b851
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1024279
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
-rw-r--r-- | baseboard/octopus/baseboard.c | 73 | ||||
-rw-r--r-- | baseboard/octopus/baseboard_battery.h | 44 | ||||
-rw-r--r-- | baseboard/octopus/battery.c | 273 | ||||
-rw-r--r-- | baseboard/octopus/build.mk | 2 | ||||
-rw-r--r-- | baseboard/octopus/usb_pd_policy.c | 407 | ||||
-rw-r--r-- | board/bip/battery.c | 81 | ||||
-rw-r--r-- | board/bip/board.c | 41 | ||||
-rw-r--r-- | board/bip/board.h | 11 | ||||
-rw-r--r-- | board/bip/gpio.inc | 1 | ||||
-rw-r--r-- | board/bip/usb_pd_policy.c | 346 | ||||
-rw-r--r-- | board/yorp/battery.c | 314 | ||||
-rw-r--r-- | board/yorp/board.c | 63 | ||||
-rw-r--r-- | board/yorp/board.h | 8 | ||||
-rw-r--r-- | board/yorp/usb_pd_policy.c | 393 | ||||
-rw-r--r-- | util/build.mk | 6 |
15 files changed, 915 insertions, 1148 deletions
diff --git a/baseboard/octopus/baseboard.c b/baseboard/octopus/baseboard.c index aeae096cc3..55d9f635fb 100644 --- a/baseboard/octopus/baseboard.c +++ b/baseboard/octopus/baseboard.c @@ -4,3 +4,76 @@ */ /* Octopus family-specific configuration */ + +#include "common.h" +#include "console.h" +#include "charge_manager.h" +#include "charge_state.h" +#include "usbc_ppc.h" +#include "util.h" + +#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args) +#define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ## args) + +int board_set_active_charge_port(int port) +{ + int is_valid_port = (port >= 0 && + port < CONFIG_USB_PD_PORT_COUNT); + int i; + + if (!is_valid_port && port != CHARGE_PORT_NONE) + return EC_ERROR_INVAL; + + + if (port == CHARGE_PORT_NONE) { + CPRINTSUSB("Disabling all charger ports"); + + /* Disable all ports. */ + for (i = 0; i < ppc_cnt; i++) { + /* + * Do not return early if one fails otherwise we can + * get into a boot loop assertion failure. + */ + if (ppc_vbus_sink_enable(i, 0)) + CPRINTSUSB("Disabling C%d as sink failed.", i); + } + + return EC_SUCCESS; + } + + /* Check if the port is sourcing VBUS. */ + if (ppc_is_sourcing_vbus(port)) { + CPRINTFUSB("Skip enable C%d", port); + return EC_ERROR_INVAL; + } + + CPRINTSUSB("New charge port: C%d", port); + + /* + * Turn off the other ports' sink path FETs, before enabling the + * requested charge port. + */ + for (i = 0; i < ppc_cnt; i++) { + if (i == port) + continue; + + if (ppc_vbus_sink_enable(i, 0)) + CPRINTSUSB("C%d: sink path disable failed.", i); + } + + /* Enable requested charge port. */ + if (ppc_vbus_sink_enable(port, 1)) { + CPRINTSUSB("C%d: sink path enable failed.", port); + return EC_ERROR_UNKNOWN; + } + + return EC_SUCCESS; +} + +void board_set_charge_limit(int port, int supplier, int charge_ma, + int max_ma, int charge_mv) +{ + charge_set_input_current_limit(MAX(charge_ma, + CONFIG_CHARGER_INPUT_CURRENT), + charge_mv); +} diff --git a/baseboard/octopus/baseboard_battery.h b/baseboard/octopus/baseboard_battery.h new file mode 100644 index 0000000000..53e3a4df65 --- /dev/null +++ b/baseboard/octopus/baseboard_battery.h @@ -0,0 +1,44 @@ +/* Copyright 2018 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* Octopus baseboard battery configuration */ + +#ifndef __CROS_EC_BASEBOARD_BATTERY_H +#define __CROS_EC_BASEBOARD_BATTERY_H + +#include "battery.h" + +/* Number of writes needed to invoke battery cutoff command */ +#define SHIP_MODE_WRITES 2 + +struct ship_mode_info { + const uint8_t reg_addr; + const uint16_t reg_data[SHIP_MODE_WRITES]; +}; + +struct fet_info { + const int mfgacc_support; + const uint8_t reg_addr; + const uint16_t reg_mask; + const uint16_t disconnect_val; +}; + +struct fuel_gauge_info { + const char *manuf_name; + const char *device_name; + const uint8_t override_nil; + const struct ship_mode_info ship_mode; + const struct fet_info fet; +}; +struct board_batt_params { + const struct fuel_gauge_info fuel_gauge; + const struct battery_info batt_info; +}; + +/* Forward declare variant specific data used by common octopus code */ +extern const struct board_batt_params board_battery_info[]; +extern const enum battery_type DEFAULT_BATTERY_TYPE; + +#endif /* __CROS_EC_BASEBOARD_BATTERY_H */ diff --git a/baseboard/octopus/battery.c b/baseboard/octopus/battery.c new file mode 100644 index 0000000000..99d357e553 --- /dev/null +++ b/baseboard/octopus/battery.c @@ -0,0 +1,273 @@ +/* Copyright 2018 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Battery pack vendor provided charging profile + */ + +#include "battery.h" +#include "baseboard_battery.h" +#include "battery_smart.h" +#include "charge_state.h" +#include "common.h" +#include "console.h" +#include "gpio.h" +#include "hooks.h" +#include "util.h" + +#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args) + + +static enum battery_present batt_pres_prev = BP_NOT_SURE; + +/* Get type of the battery connected on the board */ +static int board_get_battery_type(void) +{ + char manu_name[32], device_name[32]; + int i; + static enum battery_type board_battery_type = BATTERY_TYPE_COUNT; + + /* + * If board_battery_type is not the default value, then can return here + * as there is no need to query the fuel gauge. + */ + if (board_battery_type != BATTERY_TYPE_COUNT) + return board_battery_type; + + /* Get the manufacture name. If can't read then just exit */ + if (battery_manufacturer_name(manu_name, sizeof(manu_name))) + return board_battery_type; + + /* + * Compare the manufacturer name read from the fuel gauge to the + * manufacture names defined in the board_battery_info table above. If + * a device name has been specified in the board_battery_info table, + * then both the manufacture and device name must match. + */ + for (i = 0; i < BATTERY_TYPE_COUNT; i++) { + const struct fuel_gauge_info * const fuel_gauge = + &board_battery_info[i].fuel_gauge; + + if (strcasecmp(manu_name, fuel_gauge->manuf_name)) + continue; + + if (fuel_gauge->device_name == NULL) { + board_battery_type = i; + break; + } + + if (battery_device_name(device_name, sizeof(device_name))) + continue; + + if (strcasecmp(device_name, fuel_gauge->device_name)) + continue; + + CPRINTS("found batt:%s", fuel_gauge->manuf_name); + board_battery_type = i; + + break; + } + + return board_battery_type; +} + +/* + * Initialize the battery type for the board. + * + * Very first battery board_battery_info is called by the charger driver to + * initialize the charger parameters hence initialize the battery type for the + * board as soon as the I2C is initialized. + */ +static void board_init_battery_type(void) +{ + if (board_get_battery_type() == BATTERY_TYPE_COUNT) + CPRINTS("battery not found"); +} +DECLARE_HOOK(HOOK_INIT, board_init_battery_type, HOOK_PRIO_INIT_I2C + 1); + +static inline const struct board_batt_params *board_get_batt_params(void) +{ + int type = board_get_battery_type(); + + return &board_battery_info[type == BATTERY_TYPE_COUNT ? + DEFAULT_BATTERY_TYPE : type]; +} + +const struct battery_info *battery_get_info(void) +{ + return &board_get_batt_params()->batt_info; +} + +int board_cut_off_battery(void) +{ + int rv; + int cmd; + int data; + int type = board_get_battery_type(); + + /* If battery type is unknown can't send ship mode command */ + if (type == BATTERY_TYPE_COUNT) + return EC_RES_ERROR; + + /* Ship mode command must be sent twice to take effect */ + cmd = board_battery_info[type].fuel_gauge.ship_mode.reg_addr; + data = board_battery_info[type].fuel_gauge.ship_mode.reg_data[0]; + rv = sb_write(cmd, data); + if (rv != EC_SUCCESS) + return EC_RES_ERROR; + + data = board_battery_info[type].fuel_gauge.ship_mode.reg_data[1]; + rv = sb_write(cmd, data); + + return rv ? EC_RES_ERROR : EC_RES_SUCCESS; +} + +int charger_profile_override(struct charge_state_data *curr) +{ + int type = board_get_battery_type(); + + /* + * Some batteries, when fully discharged, may request 0 voltage/current + * which can then inadvertently disable the charger leading to the + * battery not waking up. For this type of battery, marked by + * override_nil being set, if SOC is 0 and requested voltage/current is + * 0, then use precharge current and max voltage instead. + */ + if (type != BATTERY_TYPE_COUNT && + board_battery_info[type].fuel_gauge.override_nil) { + int v = board_battery_info[type].batt_info.voltage_max; + int i = board_battery_info[type].batt_info.precharge_current; + + if (curr->requested_voltage == 0 && + curr->requested_current == 0 && + curr->batt.state_of_charge == 0) { + /* + * Battery is dead, override with precharge current and + * max voltage setting for the battery. + */ + curr->requested_voltage = v; + curr->requested_current = i; + } + } + + return 0; +} + +enum battery_present battery_hw_present(void) +{ + /* The GPIO is low when the battery is physically present */ + return gpio_get_level(GPIO_EC_BATT_PRES_L) ? BP_NO : BP_YES; +} + +static int battery_init(void) +{ + int batt_status; + + return battery_status(&batt_status) ? 0 : + !!(batt_status & STATUS_INITIALIZED); +} + +/* + * This function checks the charge/discharge FET status bits. Each battery type + * supported provides the register address, mask, and disconnect value for these + * 2 FET status bits. If the FET status matches the disconnected value, then + * BATTERY_DISCONNECTED is returned. This function is required to handle the + * cases when the fuel gauge is awake and will return a non-zero state of + * charge, but is not able yet to provide power (i.e. discharge FET is not + * active). By returning BATTERY_DISCONNECTED the AP will not be powered up + * until either the external charger is able to provided enough power, or + * the battery is able to provide power and thus prevent a brownout when the + * AP is powered on by the EC. + */ +static int battery_check_disconnect(void) +{ + int rv; + int reg; + uint8_t data[6]; + int type = board_get_battery_type(); + + /* If battery type is not known, can't check CHG/DCHG FETs */ + if (type == BATTERY_TYPE_COUNT) { + /* Still don't know, so return here */ + return BATTERY_DISCONNECT_ERROR; + } + + /* Read the status of charge/discharge FETs */ + if (board_battery_info[type].fuel_gauge.fet.mfgacc_support == 1) { + rv = sb_read_mfgacc(PARAM_OPERATION_STATUS, + SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data)); + /* Get the lowest 16bits of the OperationStatus() data */ + reg = data[2] | data[3] << 8; + } else + rv = sb_read(board_battery_info[type].fuel_gauge.fet.reg_addr, + ®); + + if (rv) + return BATTERY_DISCONNECT_ERROR; + + CPRINTS("Battery FET: reg 0x%04x mask 0x%04x disc 0x%04x", reg, + board_battery_info[type].fuel_gauge.fet.reg_mask, + board_battery_info[type].fuel_gauge.fet.disconnect_val); + reg &= board_battery_info[type].fuel_gauge.fet.reg_mask; + if (reg == board_battery_info[type].fuel_gauge.fet.disconnect_val) + return BATTERY_DISCONNECTED; + + return BATTERY_NOT_DISCONNECTED; +} + +/* + * Physical detection of battery. + */ +static enum battery_present battery_check_present_status(void) +{ + enum battery_present batt_pres; + int batt_disconnect_status; + + /* Get the physical hardware status */ + batt_pres = battery_hw_present(); + + /* + * If the battery is not physically connected, then no need to perform + * any more checks. + */ + if (batt_pres != BP_YES) + return batt_pres; + + /* + * If the battery is present now and was present last time we checked, + * return early. + */ + if (batt_pres == batt_pres_prev) + return batt_pres; + + /* + * Check battery disconnect status. If we are unable to read battery + * disconnect status, then return BP_NOT_SURE. Battery could be in ship + * mode and might require pre-charge current to wake it up. BP_NO is not + * returned here because charger state machine will not provide + * pre-charge current assuming that battery is not present. + */ + batt_disconnect_status = battery_check_disconnect(); + if (batt_disconnect_status == BATTERY_DISCONNECT_ERROR) + return BP_NOT_SURE; + + /* + * Ensure that battery is: + * 1. Not in cutoff + * 2. Not disconnected + * 3. Initialized + */ + if (battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL || + batt_disconnect_status != BATTERY_NOT_DISCONNECTED || + battery_init() == 0) { + batt_pres = BP_NO; + } + + return batt_pres; +} + +enum battery_present battery_is_present(void) +{ + batt_pres_prev = battery_check_present_status(); + return batt_pres_prev; +} diff --git a/baseboard/octopus/build.mk b/baseboard/octopus/build.mk index 24e4cced5f..5a5942a0c6 100644 --- a/baseboard/octopus/build.mk +++ b/baseboard/octopus/build.mk @@ -7,3 +7,5 @@ # baseboard-y=baseboard.o +baseboard-$(CONFIG_BATTERY_SMART)+=battery.o +baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o diff --git a/baseboard/octopus/usb_pd_policy.c b/baseboard/octopus/usb_pd_policy.c new file mode 100644 index 0000000000..6c90a53d56 --- /dev/null +++ b/baseboard/octopus/usb_pd_policy.c @@ -0,0 +1,407 @@ +/* Copyright 2018 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* Shared USB-C policy for octopus boards */ + +#include "charge_manager.h" +#include "common.h" +#include "compile_time_macros.h" +#include "console.h" +#include "ec_commands.h" +#include "gpio.h" +#include "system.h" +#include "usb_mux.h" +#include "usb_pd.h" +#include "usbc_ppc.h" +#include "util.h" + +#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) +#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) + +#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ + PDO_FIXED_COMM_CAP) + +const uint32_t pd_src_pdo[] = { + PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS), +}; +const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); +const uint32_t pd_src_pdo_max[] = { + PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), +}; +const int pd_src_pdo_max_cnt = ARRAY_SIZE(pd_src_pdo_max); + +const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), + PDO_BATT(4750, 21000, 15000), + PDO_VAR(4750, 21000, 3000), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); + +int pd_board_checks(void) +{ + return EC_SUCCESS; +} + +int pd_check_data_swap(int port, int data_role) +{ + /* + * Allow data swap if we are a UFP, otherwise don't allow. + * + * When we are still in the Read-Only firmware, avoid swapping roles + * so we don't jump in RW as a SNK/DFP and potentially confuse the + * power supply by sending a soft-reset with wrong data role. + */ + return (data_role == PD_ROLE_UFP) && + (system_get_image_copy() != SYSTEM_IMAGE_RO) ? 1 : 0; +} + +void pd_check_dr_role(int port, int dr_role, int flags) +{ + /* If UFP, try to switch to DFP */ + if ((flags & PD_FLAGS_PARTNER_DR_DATA) && + dr_role == PD_ROLE_UFP && + system_get_image_copy() != SYSTEM_IMAGE_RO) + pd_request_data_swap(port); +} + +int pd_check_power_swap(int port) +{ + /* + * Allow power swap as long as we are acting as a dual role device, + * otherwise assume our role is fixed (not in S0 or console command + * to fix our role). + */ + return pd_get_dual_role() == PD_DRP_TOGGLE_ON ? 1 : 0; +} + +void pd_check_pr_role(int port, int pr_role, int flags) +{ + /* + * If partner is dual-role power and dualrole toggling is on, consider + * if a power swap is necessary. + */ + if ((flags & PD_FLAGS_PARTNER_DR_POWER) && + pd_get_dual_role() == PD_DRP_TOGGLE_ON) { + /* + * If we are a sink and partner is not externally powered, then + * swap to become a source. If we are source and partner is + * externally powered, swap to become a sink. + */ + int partner_extpower = flags & PD_FLAGS_PARTNER_EXTPOWER; + + if ((!partner_extpower && pr_role == PD_ROLE_SINK) || + (partner_extpower && pr_role == PD_ROLE_SOURCE)) + pd_request_power_swap(port); + } +} + +int pd_check_vconn_swap(int port) +{ + /* Only allow vconn swap if pp5000_A rail is enabled */ + return gpio_get_level(GPIO_EN_PP5000); +} + +void pd_execute_data_swap(int port, int data_role) +{ + /* Do nothing */ +} + +int pd_is_valid_input_voltage(int mv) +{ + return 1; +} + +void pd_power_supply_reset(int port) +{ + int prev_en; + + prev_en = ppc_is_sourcing_vbus(port); + + /* Disable VBUS. */ + ppc_vbus_source_enable(port, 0); + + /* Enable discharge if we were previously sourcing 5V */ + if (prev_en) + pd_set_vbus_discharge(port, 1); + +#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT + /* Give back the current quota we are no longer using */ + charge_manager_source_port(port, 0); +#endif /* defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT) */ + + /* Notify host of power info change. */ + pd_send_host_event(PD_EVENT_POWER_CHANGE); +} + +int pd_set_power_supply_ready(int port) +{ + int rv; + + /* Disable charging. */ + rv = ppc_vbus_sink_enable(port, 0); + if (rv) + return rv; + + pd_set_vbus_discharge(port, 0); + + /* Provide Vbus. */ + rv = ppc_vbus_source_enable(port, 1); + if (rv) + return rv; + +#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT + /* Ensure we advertise the proper available current quota */ + charge_manager_source_port(port, 1); +#endif /* defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT) */ + + /* Notify host of power info change. */ + pd_send_host_event(PD_EVENT_POWER_CHANGE); + + return EC_SUCCESS; +} + +void pd_transition_voltage(int idx) +{ + /* No-operation: we are always 5V */ +} + +#ifdef CONFIG_USB_PD_VBUS_DETECT_PPC +int pd_snk_is_vbus_provided(int port) +{ + return ppc_is_vbus_present(port); +} +#endif + +void typec_set_source_current_limit(int port, int rp) +{ + ppc_set_vbus_source_current_limit(port, rp); +} + +int board_vbus_source_enabled(int port) +{ + return ppc_is_sourcing_vbus(port); +} + + +/* ----------------- Vendor Defined Messages ------------------ */ +const struct svdm_response svdm_rsp = { + .identity = NULL, + .svids = NULL, + .modes = NULL, +}; + +int pd_custom_vdm(int port, int cnt, uint32_t *payload, + uint32_t **rpayload) +{ + int cmd = PD_VDO_CMD(payload[0]); + uint16_t dev_id = 0; + int is_rw, is_latest; + + /* make sure we have some payload */ + if (cnt == 0) + return 0; + + switch (cmd) { + case VDO_CMD_VERSION: + /* guarantee last byte of payload is null character */ + *(payload + cnt - 1) = 0; + CPRINTF("version: %s\n", (char *)(payload+1)); + break; + case VDO_CMD_READ_INFO: + case VDO_CMD_SEND_INFO: + /* copy hash */ + if (cnt == 7) { + dev_id = VDO_INFO_HW_DEV_ID(payload[6]); + is_rw = VDO_INFO_IS_RW(payload[6]); + + is_latest = pd_dev_store_rw_hash(port, + dev_id, + payload + 1, + is_rw ? + SYSTEM_IMAGE_RW : + SYSTEM_IMAGE_RO); + /* + * Send update host event unless our RW hash is + * already known to be the latest update RW. + */ + if (!is_rw || !is_latest) + pd_send_host_event(PD_EVENT_UPDATE_DEVICE); + + CPRINTF("DevId:%d.%d SW:%d RW:%d\n", + HW_DEV_ID_MAJ(dev_id), + HW_DEV_ID_MIN(dev_id), + VDO_INFO_SW_DBG_VER(payload[6]), + is_rw); + } else if (cnt == 6) { + /* really old devices don't have last byte */ + pd_dev_store_rw_hash(port, dev_id, payload + 1, + SYSTEM_IMAGE_UNKNOWN); + } + break; + case VDO_CMD_CURRENT: + CPRINTF("Current: %dmA\n", payload[1]); + break; + case VDO_CMD_FLIP: + usb_mux_flip(port); + break; +#ifdef CONFIG_USB_PD_LOGGING + case VDO_CMD_GET_LOG: + pd_log_recv_vdm(port, cnt, payload); + break; +#endif /* CONFIG_USB_PD_LOGGING */ + } + + return 0; +} + +#ifdef CONFIG_USB_PD_ALT_MODE_DFP +static int dp_flags[CONFIG_USB_PD_PORT_COUNT]; +static uint32_t dp_status[CONFIG_USB_PD_PORT_COUNT]; + +static void svdm_safe_dp_mode(int port) +{ + /* make DP interface safe until configure */ + dp_flags[port] = 0; + dp_status[port] = 0; + usb_mux_set(port, TYPEC_MUX_NONE, + USB_SWITCH_CONNECT, pd_get_polarity(port)); +} + +static int svdm_enter_dp_mode(int port, uint32_t mode_caps) +{ + /* Only enter mode if device is DFP_D capable */ + if (mode_caps & MODE_DP_SNK) { + svdm_safe_dp_mode(port); + return 0; + } + + return -1; +} + +static int svdm_dp_status(int port, uint32_t *payload) +{ + int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); + + payload[0] = VDO(USB_SID_DISPLAYPORT, 1, + CMD_DP_STATUS | VDO_OPOS(opos)); + payload[1] = VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */ + 0, /* HPD level ... not applicable */ + 0, /* exit DP? ... no */ + 0, /* usb mode? ... no */ + 0, /* multi-function ... no */ + (!!(dp_flags[port] & DP_FLAGS_DP_ON)), + 0, /* power low? ... no */ + (!!(dp_flags[port] & DP_FLAGS_DP_ON))); + return 2; +}; + +static int svdm_dp_config(int port, uint32_t *payload) +{ + int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); + int mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]); + int pin_mode = pd_dfp_dp_get_pin_mode(port, dp_status[port]); + + if (!pin_mode) + return 0; + + usb_mux_set(port, mf_pref ? TYPEC_MUX_DOCK : TYPEC_MUX_DP, + USB_SWITCH_CONNECT, pd_get_polarity(port)); + + payload[0] = VDO(USB_SID_DISPLAYPORT, 1, + CMD_DP_CONFIG | VDO_OPOS(opos)); + payload[1] = VDO_DP_CFG(pin_mode, /* pin mode */ + 1, /* DPv1.3 signaling */ + 2); /* UFP connected */ + return 2; +}; + + +static void svdm_dp_post_config(int port) +{ + const struct usb_mux *mux = &usb_muxes[port]; + + dp_flags[port] |= DP_FLAGS_DP_ON; + if (!(dp_flags[port] & DP_FLAGS_HPD_HI_PENDING)) + return; + mux->hpd_update(port, 1, 0); +} + +static int svdm_dp_attention(int port, uint32_t *payload) +{ + int lvl = PD_VDO_DPSTS_HPD_LVL(payload[1]); + int irq = PD_VDO_DPSTS_HPD_IRQ(payload[1]); + const struct usb_mux *mux = &usb_muxes[port]; + + dp_status[port] = payload[1]; + if (!(dp_flags[port] & DP_FLAGS_DP_ON)) { + if (lvl) + dp_flags[port] |= DP_FLAGS_HPD_HI_PENDING; + return 1; + } + mux->hpd_update(port, lvl, irq); + + /* ack */ + return 1; +} + +static void svdm_exit_dp_mode(int port) +{ + const struct usb_mux *mux = &usb_muxes[port]; + + svdm_safe_dp_mode(port); + mux->hpd_update(port, 0, 0); +} + +static int svdm_enter_gfu_mode(int port, uint32_t mode_caps) +{ + /* Always enter GFU mode */ + return 0; +} + +static void svdm_exit_gfu_mode(int port) +{ +} + +static int svdm_gfu_status(int port, uint32_t *payload) +{ + /* + * This is called after enter mode is successful, send unstructured + * VDM to read info. + */ + pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_READ_INFO, NULL, 0); + return 0; +} + +static int svdm_gfu_config(int port, uint32_t *payload) +{ + return 0; +} + +static int svdm_gfu_attention(int port, uint32_t *payload) +{ + return 0; +} + +const struct svdm_amode_fx supported_modes[] = { + { + .svid = USB_SID_DISPLAYPORT, + .enter = &svdm_enter_dp_mode, + .status = &svdm_dp_status, + .config = &svdm_dp_config, + .post_config = &svdm_dp_post_config, + .attention = &svdm_dp_attention, + .exit = &svdm_exit_dp_mode, + }, + { + .svid = USB_VID_GOOGLE, + .enter = &svdm_enter_gfu_mode, + .status = &svdm_gfu_status, + .config = &svdm_gfu_config, + .attention = &svdm_gfu_attention, + .exit = &svdm_exit_gfu_mode, + } +}; +const int supported_modes_cnt = ARRAY_SIZE(supported_modes); +#endif /* CONFIG_USB_PD_ALT_MODE_DFP */ diff --git a/board/bip/battery.c b/board/bip/battery.c index 5806901cf2..550c7b2a24 100644 --- a/board/bip/battery.c +++ b/board/bip/battery.c @@ -4,29 +4,62 @@ * * Battery pack vendor provided charging profile */ -#include "battery.h" -#include "battery_smart.h" -/* TODO(b/74353771): Once CL:978619 lands. Pull common code in baseboard. */ -/* TODO(b/74353771): Ensure settings here are correct */ -static const struct battery_info info = { - .voltage_max = 13200, /* mV */ - .voltage_normal = 11550, - .voltage_min = 9000, - .precharge_current = 256, /* mA */ - .start_charging_min_c = 0, - .start_charging_max_c = 50, - .charging_min_c = 0, - .charging_max_c = 60, - .discharging_min_c = -20, - .discharging_max_c = 75, +#include "common.h" +#include "baseboard_battery.h" +#include "util.h" + +/* + * Battery info for all bip battery types. Note that the fields + * start_charging_min/max and charging_min/max are not used for the charger. + * The effective temperature limits are given by discharging_min/max_c. + * + * Fuel Gauge (FG) parameters which are used for determining if the battery + * is connected, the appropriate ship mode (battery cutoff) command, and the + * charge/discharge FETs status. + * + * Ship mode (battery cutoff) requires 2 writes to the appropriate smart battery + * register. For some batteries, the charge/discharge FET bits are set when + * charging/discharging is active, in other types, these bits set mean that + * charging/discharging is disabled. Therefore, in addition to the mask for + * these bits, a disconnect value must be specified. Note that for TI fuel + * gauge, the charge/discharge FET status is found in Operation Status (0x54), + * but a read of Manufacturer Access (0x00) will return the lower 16 bits of + * Operation status which contains the FET status bits. + * + * The assumption for battery types supported is that the charge/discharge FET + * status can be read with a sb_read() command and therefore, only the register + * address, mask, and disconnect value need to be provided. + */ +const struct board_batt_params board_battery_info[] = { + /* Panasonic AP1505L Battery Information */ + [BATTERY_PANASONIC] = { + .fuel_gauge = { + .manuf_name = "PANASONIC", + .ship_mode = { + .reg_addr = 0x3A, + .reg_data = { 0xC574, 0xC574 }, + }, + .fet = { + .reg_addr = 0x0, + .reg_mask = 0x4000, + .disconnect_val = 0x0, + } + }, + .batt_info = { + .voltage_max = 13200, + .voltage_normal = 11550, /* mV */ + .voltage_min = 9000, /* mV */ + .precharge_current = 256, /* mA */ + .start_charging_min_c = 0, + .start_charging_max_c = 50, + .charging_min_c = 0, + .charging_max_c = 60, + .discharging_min_c = 0, + .discharging_max_c = 60, + }, + }, }; -const struct battery_info *battery_get_info(void) -{ - return &info; -} -int board_cut_off_battery(void) -{ - /* TODO(b/74353771): Ensure settings here are correct */ - return EC_RES_ERROR; -} +BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT); + +const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_PANASONIC; diff --git a/board/bip/board.c b/board/bip/board.c index 7a29ac0fcb..4c81ac17f0 100644 --- a/board/bip/board.c +++ b/board/bip/board.c @@ -216,33 +216,42 @@ enum adc_channel board_get_vbus_adc(int port) */ void board_reset_pd_mcu(void) { - /* TODO(b/76218141): Flesh out USB code */ -} - -int board_set_active_charge_port(int port) -{ - /* TODO(b/76218141): Flesh out USB code */ - return EC_SUCCESS; -} + /* + * C0: The internal TCPC on ITE EC does not have a reset signal, but + * it will get reset when the EC gets reset. + */ -void board_set_charge_limit(int port, int supplier, int charge_ma, - int max_ma, int charge_mv) -{ - /* TODO(b/76218141): Flesh out USB code */ + /* C1: Assert reset to TCPC (PS8751) for required delay (1ms) */ + gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 0); + msleep(PS8XXX_RESET_DELAY_MS); + gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 1); } void board_overcurrent_event(int port) { - /* TODO(b/76218141): Do we need to pass this signal upstream? */ - + /* TODO(b/78344554): pass this signal upstream once hardware reworked */ cprints(CC_USBPD, "p%d: overcurrent!", port); } uint16_t tcpc_get_alert_status(void) { - /* TODO(b/76218141): Flesh out USB code */ - return 0; + uint16_t status = 0; + + /* + * Since C0 TCPC is embedded within EC, we don't need the PDCMD tasks + * to query the (embedded) TCPC status since chip driver code will + * handles its own interrupts and forward the correct events to + * the PD_C0 task. See it83xx/intc.c + */ + + /* Check C1 interrupt pin to let PDCMD task know to query TCPC */ + if (!gpio_get_level(GPIO_USB_C1_PD_INT_ODL)) { + if (gpio_get_level(GPIO_USB_C1_PD_RST_ODL)) + status |= PD_STATUS_TCPC_ALERT_1; + } + + return status; } void chipset_pre_init_callback(void) diff --git a/board/bip/board.h b/board/bip/board.h index 1625fb37bc..f8dba2079f 100644 --- a/board/bip/board.h +++ b/board/bip/board.h @@ -41,8 +41,10 @@ /* Battery Configuration */ #define CONFIG_BATTERY_CUT_OFF +#define CONFIG_BATTERY_DEVICE_CHEMISTRY "LION" /* TODO(b/74427009): Ensure this works in dead battery conditions */ -#define CONFIG_BATTERY_PRESENT_GPIO GPIO_EC_BATT_PRES_L +#define CONFIG_BATTERY_HW_PRESENT_CUSTOM +#define CONFIG_BATTERY_PRESENT_CUSTOM #define CONFIG_BATTERY_SMART /* USB-C Configuration */ @@ -56,6 +58,7 @@ #define CONFIG_USB_PD_ALT_MODE #define CONFIG_USB_PD_ALT_MODE_DFP #define CONFIG_USB_PD_COMM_LOCKED +#define CONFIG_USB_PD_VBUS_DETECT_PPC #define CONFIG_USB_PD_TCPC_LOW_POWER #define CONFIG_USB_PD_TCPM_ITE83XX /* C0 & C1 TCPC: ITE EC */ #define CONFIG_USB_MUX_IT5205 /* C0 MUX: IT5205 */ @@ -152,6 +155,12 @@ enum power_signal { POWER_SIGNAL_COUNT }; +/* List of possible batteries */ +enum battery_type { + BATTERY_PANASONIC, + BATTERY_TYPE_COUNT, +}; + /* Forward declare board-specific functions */ void board_reset_pd_mcu(void); void board_pd_vconn_ctrl(int port, int cc_pin, int enabled); diff --git a/board/bip/gpio.inc b/board/bip/gpio.inc index 0c5980e873..a27f6af880 100644 --- a/board/bip/gpio.inc +++ b/board/bip/gpio.inc @@ -89,6 +89,7 @@ GPIO(USB_C0_BC12_CHG_DET_L, PIN(A, 0), GPIO_INPUT) /* C0 BC1.2 Detect */ GPIO(USB_C1_BC12_CHG_DET_L, PIN(A, 1), GPIO_INPUT) /* C1 BC1.2 Detect */ GPIO(USB_C0_BC12_VBUS_ON, PIN(J, 4), GPIO_OUT_LOW) /* C0 BC1.2 Power */ GPIO(USB_C1_BC12_VBUS_ON, PIN(J, 5), GPIO_OUT_LOW) /* C1 BC1.2 Power */ +GPIO(USB_C1_PD_RST_ODL, PIN(L, 7), GPIO_ODR_HIGH) /* C1 PD Reset */ /* Alternate functions GPIO definitions */ /* Cr50 requires no pull-ups on UART pins. */ diff --git a/board/bip/usb_pd_policy.c b/board/bip/usb_pd_policy.c index 93ad7dfa40..82922f9a4d 100644 --- a/board/bip/usb_pd_policy.c +++ b/board/bip/usb_pd_policy.c @@ -3,350 +3,6 @@ * found in the LICENSE file. */ -#include "charge_manager.h" #include "common.h" -#include "compile_time_macros.h" -#include "console.h" -#include "ec_commands.h" -#include "gpio.h" -#include "system.h" -#include "usb_mux.h" -#include "usb_pd.h" -#include "usbc_ppc.h" -#include "util.h" -#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) -#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) - -#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ - PDO_FIXED_COMM_CAP) - - -const uint32_t pd_src_pdo[] = { - PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); -const uint32_t pd_src_pdo_max[] = { - PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_max_cnt = ARRAY_SIZE(pd_src_pdo_max); - -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), - PDO_BATT(4750, 21000, 15000), - PDO_VAR(4750, 21000, 3000), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); - -int pd_board_checks(void) -{ - return EC_SUCCESS; -} - -int pd_check_data_swap(int port, int data_role) -{ - /* - * Allow data swap if we are a UFP, otherwise don't allow. - * - * When we are still in the Read-Only firmware, avoid swapping roles - * so we don't jump in RW as a SNK/DFP and potentially confuse the - * power supply by sending a soft-reset with wrong data role. - */ - return (data_role == PD_ROLE_UFP) && - (system_get_image_copy() != SYSTEM_IMAGE_RO) ? 1 : 0; -} - -void pd_check_dr_role(int port, int dr_role, int flags) -{ - /* If UFP, try to switch to DFP */ - if ((flags & PD_FLAGS_PARTNER_DR_DATA) && - dr_role == PD_ROLE_UFP && - system_get_image_copy() != SYSTEM_IMAGE_RO) - pd_request_data_swap(port); -} - -int pd_check_power_swap(int port) -{ - /* - * Allow power swap as long as we are acting as a dual role device, - * otherwise assume our role is fixed (not in S0 or console command - * to fix our role). - */ - return pd_get_dual_role() == PD_DRP_TOGGLE_ON ? 1 : 0; -} - -void pd_check_pr_role(int port, int pr_role, int flags) -{ - /* - * If partner is dual-role power and dualrole toggling is on, consider - * if a power swap is necessary. - */ - if ((flags & PD_FLAGS_PARTNER_DR_POWER) && - pd_get_dual_role() == PD_DRP_TOGGLE_ON) { - /* - * If we are a sink and partner is not externally powered, then - * swap to become a source. If we are source and partner is - * externally powered, swap to become a sink. - */ - int partner_extpower = flags & PD_FLAGS_PARTNER_EXTPOWER; - - if ((!partner_extpower && pr_role == PD_ROLE_SINK) || - (partner_extpower && pr_role == PD_ROLE_SOURCE)) - pd_request_power_swap(port); - } -} - -int pd_check_vconn_swap(int port) -{ - /* Only allow vconn swap if pp5000_A rail is enabled */ - return gpio_get_level(GPIO_EN_PP5000); -} - -/* TODO: Delete this method once CL:885462 lands */ -void pd_execute_data_swap(int port, int data_role) -{ - /* Do nothing */ -} - -int pd_is_valid_input_voltage(int mv) -{ - return 1; -} - -void pd_power_supply_reset(int port) -{ - /* TODO(b/74127309): Flesh out USB code */ -} - -int pd_set_power_supply_ready(int port) -{ - /* TODO(b/74127309): Flesh out USB code */ - - /* Notify host of power info change. */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); - - return EC_SUCCESS; -} - -void pd_transition_voltage(int idx) -{ - /* No-operation: we are always 5V */ -} - -void typec_set_source_current_limit(int port, int rp) -{ - /* TODO(b/74127309): Flesh out USB code */ -} - -int pd_snk_is_vbus_provided(int port) -{ - /* TODO(b/74127309): Flesh out USB code */ - return 0; -} - -int board_vbus_source_enabled(int port) -{ - /* TODO(b/74127309): Flesh out USB code */ - return 0; -} - -/* ----------------- Vendor Defined Messages ------------------ */ -const struct svdm_response svdm_rsp = { - .identity = NULL, - .svids = NULL, - .modes = NULL, -}; - -int pd_custom_vdm(int port, int cnt, uint32_t *payload, - uint32_t **rpayload) -{ - int cmd = PD_VDO_CMD(payload[0]); - uint16_t dev_id = 0; - int is_rw, is_latest; - - /* make sure we have some payload */ - if (cnt == 0) - return 0; - - switch (cmd) { - case VDO_CMD_VERSION: - /* guarantee last byte of payload is null character */ - *(payload + cnt - 1) = 0; - CPRINTF("version: %s\n", (char *)(payload+1)); - break; - case VDO_CMD_READ_INFO: - case VDO_CMD_SEND_INFO: - /* copy hash */ - if (cnt == 7) { - dev_id = VDO_INFO_HW_DEV_ID(payload[6]); - is_rw = VDO_INFO_IS_RW(payload[6]); - - is_latest = pd_dev_store_rw_hash(port, - dev_id, - payload + 1, - is_rw ? - SYSTEM_IMAGE_RW : - SYSTEM_IMAGE_RO); - /* - * Send update host event unless our RW hash is - * already known to be the latest update RW. - */ - if (!is_rw || !is_latest) - pd_send_host_event(PD_EVENT_UPDATE_DEVICE); - - CPRINTF("DevId:%d.%d SW:%d RW:%d\n", - HW_DEV_ID_MAJ(dev_id), - HW_DEV_ID_MIN(dev_id), - VDO_INFO_SW_DBG_VER(payload[6]), - is_rw); - } else if (cnt == 6) { - /* really old devices don't have last byte */ - pd_dev_store_rw_hash(port, dev_id, payload + 1, - SYSTEM_IMAGE_UNKNOWN); - } - break; - case VDO_CMD_CURRENT: - CPRINTF("Current: %dmA\n", payload[1]); - break; - case VDO_CMD_FLIP: - usb_mux_flip(port); - break; -#ifdef CONFIG_USB_PD_LOGGING - case VDO_CMD_GET_LOG: - pd_log_recv_vdm(port, cnt, payload); - break; -#endif /* CONFIG_USB_PD_LOGGING */ - } - - return 0; -} - -#ifdef CONFIG_USB_PD_ALT_MODE_DFP -static int dp_flags[CONFIG_USB_PD_PORT_COUNT]; -static uint32_t dp_status[CONFIG_USB_PD_PORT_COUNT]; - -static void svdm_safe_dp_mode(int port) -{ - /* make DP interface safe until configure */ - dp_flags[port] = 0; - dp_status[port] = 0; - usb_mux_set(port, TYPEC_MUX_NONE, - USB_SWITCH_CONNECT, pd_get_polarity(port)); -} - -static int svdm_enter_dp_mode(int port, uint32_t mode_caps) -{ - /* Only enter mode if device is DFP_D capable */ - if (mode_caps & MODE_DP_SNK) { - svdm_safe_dp_mode(port); - return 0; - } - - return -1; -} - -static int svdm_dp_status(int port, uint32_t *payload) -{ - int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); - - payload[0] = VDO(USB_SID_DISPLAYPORT, 1, - CMD_DP_STATUS | VDO_OPOS(opos)); - payload[1] = VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */ - 0, /* HPD level ... not applicable */ - 0, /* exit DP? ... no */ - 0, /* usb mode? ... no */ - 0, /* multi-function ... no */ - (!!(dp_flags[port] & DP_FLAGS_DP_ON)), - 0, /* power low? ... no */ - (!!(dp_flags[port] & DP_FLAGS_DP_ON))); - return 2; -}; - -static int svdm_dp_config(int port, uint32_t *payload) -{ - int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); - int mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]); - int pin_mode = pd_dfp_dp_get_pin_mode(port, dp_status[port]); - - if (!pin_mode) - return 0; - - usb_mux_set(port, mf_pref ? TYPEC_MUX_DOCK : TYPEC_MUX_DP, - USB_SWITCH_CONNECT, pd_get_polarity(port)); - - payload[0] = VDO(USB_SID_DISPLAYPORT, 1, - CMD_DP_CONFIG | VDO_OPOS(opos)); - payload[1] = VDO_DP_CFG(pin_mode, /* pin mode */ - 1, /* DPv1.3 signaling */ - 2); /* UFP connected */ - return 2; -}; - - -static void svdm_dp_post_config(int port) -{ - /* TODO(b/74127309): Flesh out USB code */ -} - -static int svdm_dp_attention(int port, uint32_t *payload) -{ - /* TODO(b/74127309): Flesh out USB code */ - return 1; /* ack */ -} - -static void svdm_exit_dp_mode(int port) -{ - /* TODO(b/74127309): Flesh out USB code */ -} - -static int svdm_enter_gfu_mode(int port, uint32_t mode_caps) -{ - /* Always enter GFU mode */ - return 0; -} - -static void svdm_exit_gfu_mode(int port) -{ -} - -static int svdm_gfu_status(int port, uint32_t *payload) -{ - /* - * This is called after enter mode is successful, send unstructured - * VDM to read info. - */ - pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_READ_INFO, NULL, 0); - return 0; -} - -static int svdm_gfu_config(int port, uint32_t *payload) -{ - return 0; -} - -static int svdm_gfu_attention(int port, uint32_t *payload) -{ - return 0; -} - -const struct svdm_amode_fx supported_modes[] = { - { - .svid = USB_SID_DISPLAYPORT, - .enter = &svdm_enter_dp_mode, - .status = &svdm_dp_status, - .config = &svdm_dp_config, - .post_config = &svdm_dp_post_config, - .attention = &svdm_dp_attention, - .exit = &svdm_exit_dp_mode, - }, - { - .svid = USB_VID_GOOGLE, - .enter = &svdm_enter_gfu_mode, - .status = &svdm_gfu_status, - .config = &svdm_gfu_config, - .attention = &svdm_gfu_attention, - .exit = &svdm_exit_gfu_mode, - } -}; -const int supported_modes_cnt = ARRAY_SIZE(supported_modes); -#endif /* CONFIG_USB_PD_ALT_MODE_DFP */ +/* TODO(b/78638238): Remove file if still unused after DVT */ diff --git a/board/yorp/battery.c b/board/yorp/battery.c index 3287578ed5..d960dd8a67 100644 --- a/board/yorp/battery.c +++ b/board/yorp/battery.c @@ -5,65 +5,20 @@ * Battery pack vendor provided charging profile */ -#include "battery.h" -#include "battery_smart.h" -#include "charge_state.h" #include "common.h" -#include "console.h" -#include "gpio.h" -#include "hooks.h" +#include "baseboard_battery.h" #include "util.h" -#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args) - -/* Number of writes needed to invoke battery cutoff command */ -#define SHIP_MODE_WRITES 2 - -enum battery_type { - BATTERY_LGC15, - BATTERY_PANASONIC, - BATTERY_SANYO, - BATTERY_TYPE_COUNT, -}; - -struct ship_mode_info { - const uint8_t reg_addr; - const uint16_t reg_data[SHIP_MODE_WRITES]; -}; - -struct fet_info { - const int mfgacc_support; - const uint8_t reg_addr; - const uint16_t reg_mask; - const uint16_t disconnect_val; -}; - -struct fuel_gauge_info { - const char *manuf_name; - const char *device_name; - const uint8_t override_nil; - const struct ship_mode_info ship_mode; - const struct fet_info fet; -}; - -struct board_batt_params { - const struct fuel_gauge_info fuel_gauge; - const struct battery_info batt_info; -}; - -#define DEFAULT_3S_BATTERY_TYPE BATTERY_LGC15 -static enum battery_present batt_pres_prev = BP_NOT_SURE; - /* - * Battery info for all Octopus battery types. Note that the fields + * Battery info for all yorp battery types. Note that the fields * start_charging_min/max and charging_min/max are not used for the charger. * The effective temperature limits are given by discharging_min/max_c. * - * Fuel Gauge (FG) parameters which are used for determing if the battery + * Fuel Gauge (FG) parameters which are used for determining if the battery * is connected, the appropriate ship mode (battery cutoff) command, and the * charge/discharge FETs status. * - * Ship mode (battery cutoff) requires 2 writes to the appropirate smart battery + * Ship mode (battery cutoff) requires 2 writes to the appropriate smart battery * register. For some batteries, the charge/discharge FET bits are set when * charging/discharging is active, in other types, these bits set mean that * charging/discharging is disabled. Therefore, in addition to the mask for @@ -73,10 +28,10 @@ static enum battery_present batt_pres_prev = BP_NOT_SURE; * Operation status which contains the FET status bits. * * The assumption for battery types supported is that the charge/discharge FET - * status can be read with a sb_read() command and therefore, only the regsister + * status can be read with a sb_read() command and therefore, only the register * address, mask, and disconnect value need to be provided. */ -static const struct board_batt_params info[] = { +const struct board_batt_params board_battery_info[] = { /* LGC AC15A8J Battery Information */ [BATTERY_LGC15] = { .fuel_gauge = { @@ -163,259 +118,6 @@ static const struct board_batt_params info[] = { }, }, }; -BUILD_ASSERT(ARRAY_SIZE(info) == BATTERY_TYPE_COUNT); - -/* Get type of the battery connected on the board */ -static int board_get_battery_type(void) -{ - char manu_name[32], device_name[32]; - int i; - static enum battery_type board_battery_type = BATTERY_TYPE_COUNT; - - /* - * If board_battery_type is not the default value, then can return here - * as there is no need to query the fuel gauge. - */ - if (board_battery_type != BATTERY_TYPE_COUNT) - return board_battery_type; - - /* Get the manufacture name. If can't read then just exit */ - if (battery_manufacturer_name(manu_name, sizeof(manu_name))) - return board_battery_type; - - /* - * Compare the manufacturer name read from the fuel gague to the - * manaufactuer names defined in the info table above. If a device name - * has been specified in the info table, then both the manufactuer and - * device name must match. - */ - for (i = 0; i < BATTERY_TYPE_COUNT; i++) { - if (strcasecmp(manu_name, - info[i].fuel_gauge.manuf_name)) - continue; - - if (info[i].fuel_gauge.device_name == NULL) { - board_battery_type = i; - break; - } - - if (battery_device_name(device_name, sizeof(device_name))) - continue; - - if (strcasecmp(device_name, info[i].fuel_gauge.device_name)) - continue; - - board_battery_type = i; - CPRINTS("found batt:%s", - info[board_battery_type].fuel_gauge.manuf_name); - break; - - } - - return board_battery_type; -} - -/* - * Initialize the battery type for the board. - * - * Very first battery info is called by the charger driver to initialize - * the charger parameters hence initialize the battery type for the board - * as soon as the I2C is initialized. - */ -static void board_init_battery_type(void) -{ - if (board_get_battery_type() == BATTERY_TYPE_COUNT) - CPRINTS("battery not found"); -} -DECLARE_HOOK(HOOK_INIT, board_init_battery_type, HOOK_PRIO_INIT_I2C + 1); - -static inline const struct board_batt_params *board_get_batt_params(void) -{ - int type = board_get_battery_type(); - - return &info[type == BATTERY_TYPE_COUNT ? - DEFAULT_3S_BATTERY_TYPE : type]; -} - -const struct battery_info *battery_get_info(void) -{ - return &board_get_batt_params()->batt_info; -} - -int board_cut_off_battery(void) -{ - int rv; - int cmd; - int data; - int type = board_get_battery_type(); - - /* If battery type is unknown can't send ship mode command */ - if (type == BATTERY_TYPE_COUNT) - return EC_RES_ERROR; - - /* Ship mode command must be sent twice to take effect */ - cmd = info[type].fuel_gauge.ship_mode.reg_addr; - data = info[type].fuel_gauge.ship_mode.reg_data[0]; - rv = sb_write(cmd, data); - if (rv != EC_SUCCESS) - return EC_RES_ERROR; - - data = info[type].fuel_gauge.ship_mode.reg_data[1]; - rv = sb_write(cmd, data); - - return rv ? EC_RES_ERROR : EC_RES_SUCCESS; -} - -int charger_profile_override(struct charge_state_data *curr) -{ - int type = board_get_battery_type(); - - /* - * Some batteries, when fully discharged, may request 0 voltage/current - * which can then inadvertently disable the charger leading to the - * battery not waking up. For this type of battery, marked by - * override_nil being set, if SOC is 0 and requested voltage/current is - * 0, then use precharge current and max voltage instead. - */ - if (type != BATTERY_TYPE_COUNT && info[type].fuel_gauge.override_nil) { - int v = info[type].batt_info.voltage_max; - int i = info[type].batt_info.precharge_current; - - if (curr->requested_voltage == 0 && - curr->requested_current == 0 && - curr->batt.state_of_charge == 0) { - /* - * Battery is dead, override with precharge current and - * max voltage setting for the battery. - */ - curr->requested_voltage = v; - curr->requested_current = i; - } - } - - return 0; -} - -enum battery_present battery_hw_present(void) -{ - /* The GPIO is low when the battery is physically present */ - return gpio_get_level(GPIO_EC_BATT_PRES_L) ? BP_NO : BP_YES; -} - -static int battery_init(void) -{ - int batt_status; - - return battery_status(&batt_status) ? 0 : - !!(batt_status & STATUS_INITIALIZED); -} - -/* - * This function checks the charge/dishcarge FET status bits. Each battery type - * supported provides the register address, mask, and disconnect value for these - * 2 FET status bits. If the FET status matches the disconnected value, then - * BATTERY_DISCONNECTED is returned. This function is required to handle the - * cases when the fuel gauge is awake and will return a non-zero state of - * charge, but is not able yet to provide power (i.e. discharge FET is not - * active). By returning BATTERY_DISCONNECTED the AP will not be powered up - * until either the external charger is able to provided enough power, or - * the battery is able to provide power and thus prevent a brownout when the - * AP is powered on by the EC. - */ -static int battery_check_disconnect(void) -{ - int rv; - int reg; - uint8_t data[6]; - int type = board_get_battery_type(); - - /* If battery type is not known, can't check CHG/DCHG FETs */ - if (type == BATTERY_TYPE_COUNT) { - /* Still don't know, so return here */ - return BATTERY_DISCONNECT_ERROR; - } - - /* Read the status of charge/discharge FETs */ - if (info[type].fuel_gauge.fet.mfgacc_support == 1) { - rv = sb_read_mfgacc(PARAM_OPERATION_STATUS, - SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data)); - /* Get the lowest 16bits of the OperationStatus() data */ - reg = data[2] | data[3] << 8; - } else - rv = sb_read(info[type].fuel_gauge.fet.reg_addr, - ®); - - if (rv) - return BATTERY_DISCONNECT_ERROR; - - CPRINTS("Battery FET: reg 0x%04x mask 0x%04x disc 0x%04x", reg, - info[type].fuel_gauge.fet.reg_mask, - info[type].fuel_gauge.fet.disconnect_val); - reg &= info[type].fuel_gauge.fet.reg_mask; - if (reg == info[type].fuel_gauge.fet.disconnect_val) - return BATTERY_DISCONNECTED; - - return BATTERY_NOT_DISCONNECTED; -} - -/* - * Physical detection of battery. - */ -static enum battery_present battery_check_present_status(void) -{ - enum battery_present batt_pres; - int batt_disconnect_status; - - /* Get the physical hardware status */ - batt_pres = battery_hw_present(); - - /* - * If the battery is not physically connected, then no need to perform - * any more checks. - */ - if (batt_pres != BP_YES) - return batt_pres; - - /* - * If the battery is present now and was present last time we checked, - * return early. - */ - if (batt_pres == batt_pres_prev) - return batt_pres; - - /* - * Check battery disconnect status. If we are unable to read battery - * disconnect status, then return BP_NOT_SURE. Battery could be in ship - * mode and might require pre-charge current to wake it up. BP_NO is not - * returned here because charger state machine will not provide - * pre-charge current assuming that battery is not present. - */ - batt_disconnect_status = battery_check_disconnect(); - if (batt_disconnect_status == BATTERY_DISCONNECT_ERROR) - return BP_NOT_SURE; - - /* - * Ensure that battery is: - * 1. Not in cutoff - * 2. Not disconnected - * 3. Initialized - */ - if (battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL || - batt_disconnect_status != BATTERY_NOT_DISCONNECTED || - battery_init() == 0) { - batt_pres = BP_NO; - } - - return batt_pres; -} - -enum battery_present battery_is_present(void) -{ - batt_pres_prev = battery_check_present_status(); - return batt_pres_prev; -} +BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT); -int board_battery_initialized(void) -{ - return battery_hw_present() == batt_pres_prev; -} +const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_PANASONIC; diff --git a/board/yorp/board.c b/board/yorp/board.c index d5608a2be4..9689f92f79 100644 --- a/board/yorp/board.c +++ b/board/yorp/board.c @@ -298,69 +298,6 @@ void board_reset_pd_mcu(void) /* ANX7447 does not have a reset pin. */ } -int board_set_active_charge_port(int port) -{ - int is_real_port = (port >= 0 && - port < CONFIG_USB_PD_PORT_COUNT); - int i; - - if (!is_real_port && port != CHARGE_PORT_NONE) - return EC_ERROR_INVAL; - - - if (port == CHARGE_PORT_NONE) { - CPRINTSUSB("Disabling all charger ports"); - - /* Disable all ports. */ - for (i = 0; i < ppc_cnt; i++) { - /* - * Do not return early if one fails otherwise we can - * get into a boot loop assertion failure. - */ - if (ppc_vbus_sink_enable(i, 0)) - CPRINTSUSB("Disabling C%d as sink failed.", i); - } - - return EC_SUCCESS; - } - - CPRINTSUSB("New charge port: C%d", port); - - /* Check if the port is sourcing VBUS. */ - if (ppc_is_sourcing_vbus(port)) { - CPRINTFUSB("Skip enable C%d", port); - return EC_ERROR_INVAL; - } - - /* - * Turn off the other ports' sink path FETs, before enabling the - * requested charge port. - */ - for (i = 0; i < ppc_cnt; i++) { - if (i == port) - continue; - - if (ppc_vbus_sink_enable(i, 0)) - CPRINTSUSB("C%d: sink path disable failed.", i); - } - - /* Enable requested charge port. */ - if (ppc_vbus_sink_enable(port, 1)) { - CPRINTSUSB("C%d: sink path enable failed.", port); - return EC_ERROR_UNKNOWN; - } - - return EC_SUCCESS; -} - -void board_set_charge_limit(int port, int supplier, int charge_ma, - int max_ma, int charge_mv) -{ - charge_set_input_current_limit(MAX(charge_ma, - CONFIG_CHARGER_INPUT_CURRENT), - charge_mv); -} - void board_tcpc_init(void) { int count = 0; diff --git a/board/yorp/board.h b/board/yorp/board.h index b2265f8c71..ccf9efcdf0 100644 --- a/board/yorp/board.h +++ b/board/yorp/board.h @@ -202,6 +202,14 @@ enum sensor_id { SENSOR_COUNT }; +/* List of possible batteries */ +enum battery_type { + BATTERY_LGC15, + BATTERY_PANASONIC, + BATTERY_SANYO, + BATTERY_TYPE_COUNT, +}; + /* Forward declare board-specific functions */ void board_reset_pd_mcu(void); int board_get_version(void); diff --git a/board/yorp/usb_pd_policy.c b/board/yorp/usb_pd_policy.c index 582381615b..82922f9a4d 100644 --- a/board/yorp/usb_pd_policy.c +++ b/board/yorp/usb_pd_policy.c @@ -3,397 +3,6 @@ * found in the LICENSE file. */ -#include "charge_manager.h" #include "common.h" -#include "compile_time_macros.h" -#include "console.h" -#include "ec_commands.h" -#include "gpio.h" -#include "system.h" -#include "usb_mux.h" -#include "usb_pd.h" -#include "usbc_ppc.h" -#include "util.h" -#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) -#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) - -#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ - PDO_FIXED_COMM_CAP) - - -const uint32_t pd_src_pdo[] = { - PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); -const uint32_t pd_src_pdo_max[] = { - PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_max_cnt = ARRAY_SIZE(pd_src_pdo_max); - -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), - PDO_BATT(4750, 21000, 15000), - PDO_VAR(4750, 21000, 3000), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); - -int pd_board_checks(void) -{ - return EC_SUCCESS; -} - -int pd_check_data_swap(int port, int data_role) -{ - /* - * Allow data swap if we are a UFP, otherwise don't allow. - * - * When we are still in the Read-Only firmware, avoid swapping roles - * so we don't jump in RW as a SNK/DFP and potentially confuse the - * power supply by sending a soft-reset with wrong data role. - */ - return (data_role == PD_ROLE_UFP) && - (system_get_image_copy() != SYSTEM_IMAGE_RO) ? 1 : 0; -} - -void pd_check_dr_role(int port, int dr_role, int flags) -{ - /* If UFP, try to switch to DFP */ - if ((flags & PD_FLAGS_PARTNER_DR_DATA) && - dr_role == PD_ROLE_UFP && - system_get_image_copy() != SYSTEM_IMAGE_RO) - pd_request_data_swap(port); -} - -int pd_check_power_swap(int port) -{ - /* - * Allow power swap as long as we are acting as a dual role device, - * otherwise assume our role is fixed (not in S0 or console command - * to fix our role). - */ - return pd_get_dual_role() == PD_DRP_TOGGLE_ON ? 1 : 0; -} - -void pd_check_pr_role(int port, int pr_role, int flags) -{ - /* - * If partner is dual-role power and dualrole toggling is on, consider - * if a power swap is necessary. - */ - if ((flags & PD_FLAGS_PARTNER_DR_POWER) && - pd_get_dual_role() == PD_DRP_TOGGLE_ON) { - /* - * If we are a sink and partner is not externally powered, then - * swap to become a source. If we are source and partner is - * externally powered, swap to become a sink. - */ - int partner_extpower = flags & PD_FLAGS_PARTNER_EXTPOWER; - - if ((!partner_extpower && pr_role == PD_ROLE_SINK) || - (partner_extpower && pr_role == PD_ROLE_SOURCE)) - pd_request_power_swap(port); - } -} - -int pd_check_vconn_swap(int port) -{ - /* Only allow vconn swap if pp5000_A rail is enabled */ - return gpio_get_level(GPIO_EN_PP5000); -} - -/* TODO: Delete this method once CL:885462 lands */ -void pd_execute_data_swap(int port, int data_role) -{ - /* Do nothing */ -} - -int pd_is_valid_input_voltage(int mv) -{ - return 1; -} - -void pd_power_supply_reset(int port) -{ - int prev_en; - - prev_en = ppc_is_sourcing_vbus(port); - - /* Disable VBUS. */ - ppc_vbus_source_enable(port, 0); - - /* Enable discharge if we were previously sourcing 5V */ - if (prev_en) - pd_set_vbus_discharge(port, 1); - -#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT - /* Give back the current quota we are no longer using */ - charge_manager_source_port(port, 0); -#endif /* defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT) */ - - /* Notify host of power info change. */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); -} - -int pd_set_power_supply_ready(int port) -{ - int rv; - - /* Disable charging. */ - rv = ppc_vbus_sink_enable(port, 0); - if (rv) - return rv; - - pd_set_vbus_discharge(port, 0); - - /* Provide Vbus. */ - rv = ppc_vbus_source_enable(port, 1); - if (rv) - return rv; - -#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT - /* Ensure we advertise the proper available current quota */ - charge_manager_source_port(port, 1); -#endif /* defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT) */ - - /* Notify host of power info change. */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); - - return EC_SUCCESS; -} - -void pd_transition_voltage(int idx) -{ - /* No-operation: we are always 5V */ -} - -void typec_set_source_current_limit(int port, int rp) -{ - ppc_set_vbus_source_current_limit(port, rp); -} - -int board_vbus_source_enabled(int port) -{ - return ppc_is_sourcing_vbus(port); -} - -/* ----------------- Vendor Defined Messages ------------------ */ -const struct svdm_response svdm_rsp = { - .identity = NULL, - .svids = NULL, - .modes = NULL, -}; - -int pd_custom_vdm(int port, int cnt, uint32_t *payload, - uint32_t **rpayload) -{ - int cmd = PD_VDO_CMD(payload[0]); - uint16_t dev_id = 0; - int is_rw, is_latest; - - /* make sure we have some payload */ - if (cnt == 0) - return 0; - - switch (cmd) { - case VDO_CMD_VERSION: - /* guarantee last byte of payload is null character */ - *(payload + cnt - 1) = 0; - CPRINTF("version: %s\n", (char *)(payload+1)); - break; - case VDO_CMD_READ_INFO: - case VDO_CMD_SEND_INFO: - /* copy hash */ - if (cnt == 7) { - dev_id = VDO_INFO_HW_DEV_ID(payload[6]); - is_rw = VDO_INFO_IS_RW(payload[6]); - - is_latest = pd_dev_store_rw_hash(port, - dev_id, - payload + 1, - is_rw ? - SYSTEM_IMAGE_RW : - SYSTEM_IMAGE_RO); - /* - * Send update host event unless our RW hash is - * already known to be the latest update RW. - */ - if (!is_rw || !is_latest) - pd_send_host_event(PD_EVENT_UPDATE_DEVICE); - - CPRINTF("DevId:%d.%d SW:%d RW:%d\n", - HW_DEV_ID_MAJ(dev_id), - HW_DEV_ID_MIN(dev_id), - VDO_INFO_SW_DBG_VER(payload[6]), - is_rw); - } else if (cnt == 6) { - /* really old devices don't have last byte */ - pd_dev_store_rw_hash(port, dev_id, payload + 1, - SYSTEM_IMAGE_UNKNOWN); - } - break; - case VDO_CMD_CURRENT: - CPRINTF("Current: %dmA\n", payload[1]); - break; - case VDO_CMD_FLIP: - usb_mux_flip(port); - break; -#ifdef CONFIG_USB_PD_LOGGING - case VDO_CMD_GET_LOG: - pd_log_recv_vdm(port, cnt, payload); - break; -#endif /* CONFIG_USB_PD_LOGGING */ - } - - return 0; -} - -#ifdef CONFIG_USB_PD_ALT_MODE_DFP -static int dp_flags[CONFIG_USB_PD_PORT_COUNT]; -static uint32_t dp_status[CONFIG_USB_PD_PORT_COUNT]; - -static void svdm_safe_dp_mode(int port) -{ - /* make DP interface safe until configure */ - dp_flags[port] = 0; - dp_status[port] = 0; - usb_mux_set(port, TYPEC_MUX_NONE, - USB_SWITCH_CONNECT, pd_get_polarity(port)); -} - -static int svdm_enter_dp_mode(int port, uint32_t mode_caps) -{ - /* Only enter mode if device is DFP_D capable */ - if (mode_caps & MODE_DP_SNK) { - svdm_safe_dp_mode(port); - return 0; - } - - return -1; -} - -static int svdm_dp_status(int port, uint32_t *payload) -{ - int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); - - payload[0] = VDO(USB_SID_DISPLAYPORT, 1, - CMD_DP_STATUS | VDO_OPOS(opos)); - payload[1] = VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */ - 0, /* HPD level ... not applicable */ - 0, /* exit DP? ... no */ - 0, /* usb mode? ... no */ - 0, /* multi-function ... no */ - (!!(dp_flags[port] & DP_FLAGS_DP_ON)), - 0, /* power low? ... no */ - (!!(dp_flags[port] & DP_FLAGS_DP_ON))); - return 2; -}; - -static int svdm_dp_config(int port, uint32_t *payload) -{ - int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); - int mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]); - int pin_mode = pd_dfp_dp_get_pin_mode(port, dp_status[port]); - - if (!pin_mode) - return 0; - - usb_mux_set(port, mf_pref ? TYPEC_MUX_DOCK : TYPEC_MUX_DP, - USB_SWITCH_CONNECT, pd_get_polarity(port)); - - payload[0] = VDO(USB_SID_DISPLAYPORT, 1, - CMD_DP_CONFIG | VDO_OPOS(opos)); - payload[1] = VDO_DP_CFG(pin_mode, /* pin mode */ - 1, /* DPv1.3 signaling */ - 2); /* UFP connected */ - return 2; -}; - - -static void svdm_dp_post_config(int port) -{ - const struct usb_mux *mux = &usb_muxes[port]; - - dp_flags[port] |= DP_FLAGS_DP_ON; - if (!(dp_flags[port] & DP_FLAGS_HPD_HI_PENDING)) - return; - mux->hpd_update(port, 1, 0); -} - -static int svdm_dp_attention(int port, uint32_t *payload) -{ - int lvl = PD_VDO_DPSTS_HPD_LVL(payload[1]); - int irq = PD_VDO_DPSTS_HPD_IRQ(payload[1]); - const struct usb_mux *mux = &usb_muxes[port]; - - dp_status[port] = payload[1]; - if (!(dp_flags[port] & DP_FLAGS_DP_ON)) { - if (lvl) - dp_flags[port] |= DP_FLAGS_HPD_HI_PENDING; - return 1; - } - mux->hpd_update(port, lvl, irq); - - /* ack */ - return 1; -} - -static void svdm_exit_dp_mode(int port) -{ - const struct usb_mux *mux = &usb_muxes[port]; - - svdm_safe_dp_mode(port); - mux->hpd_update(port, 0, 0); -} - -static int svdm_enter_gfu_mode(int port, uint32_t mode_caps) -{ - /* Always enter GFU mode */ - return 0; -} - -static void svdm_exit_gfu_mode(int port) -{ -} - -static int svdm_gfu_status(int port, uint32_t *payload) -{ - /* - * This is called after enter mode is successful, send unstructured - * VDM to read info. - */ - pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_READ_INFO, NULL, 0); - return 0; -} - -static int svdm_gfu_config(int port, uint32_t *payload) -{ - return 0; -} - -static int svdm_gfu_attention(int port, uint32_t *payload) -{ - return 0; -} - -const struct svdm_amode_fx supported_modes[] = { - { - .svid = USB_SID_DISPLAYPORT, - .enter = &svdm_enter_dp_mode, - .status = &svdm_dp_status, - .config = &svdm_dp_config, - .post_config = &svdm_dp_post_config, - .attention = &svdm_dp_attention, - .exit = &svdm_exit_dp_mode, - }, - { - .svid = USB_VID_GOOGLE, - .enter = &svdm_enter_gfu_mode, - .status = &svdm_gfu_status, - .config = &svdm_gfu_config, - .attention = &svdm_gfu_attention, - .exit = &svdm_exit_gfu_mode, - } -}; -const int supported_modes_cnt = ARRAY_SIZE(supported_modes); -#endif /* CONFIG_USB_PD_ALT_MODE_DFP */ +/* TODO(b/78638238): Remove file if still unused after DVT */ diff --git a/util/build.mk b/util/build.mk index 13e4dc55d1..81bdfa3d81 100644 --- a/util/build.mk +++ b/util/build.mk @@ -45,7 +45,11 @@ $(out)/util/genvif: BUILD_LDFLAGS+=$(out)/util/usb_pd_policy.o -flto STANDALONE_FLAGS=-ffreestanding -fno-builtin -nostdinc \ -Ibuiltin/ -D"__keep= " -DVIF_BUILD -$(out)/util/usb_pd_policy.o: board/$(BOARD)/usb_pd_policy.c + +# If baseboard is defined, include its usb_pd_policy; otherwise, +# $(BASEDIR) will alias to `board/$(BOARD)` and includes same board file twice. +$(out)/util/usb_pd_policy.o: $(BASEDIR)/usb_pd_policy.c \ + board/$(BOARD)/usb_pd_policy.c $(call quiet,c_to_vif,BUILDCC) deps-$(CONFIG_USB_POWER_DELIVERY) += $(out)/util/usb_pd_policy.o.d endif # CONFIG_USB_POWER_DELIVERY |