From 72357cd1edf885e559dbb715b33cfb861a0a3265 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Wed, 28 May 2014 18:10:25 -0700 Subject: samus: Allow samus to charge w/o battery or with dead battery Use a EC to PD host command to notify the PD MCU when a battery is present and charged enough that it is ok to negotiate for a higher power. The PD MCU will not negotiate until the host command is received, which allows the system to be powered without a battery or with a dead battery with 5V. BUG=chrome-os-partner:28611 BRANCH=none TEST=Tested on a samus: 1) Tested the normal case of battery charged and plugged in. When charger is plugged in, the device immediately starts negotiating for 20V and starts charging. 2) Tested with no battery. Plug in a charger, samus boots and stays alive. VBUS measured at 5V. When a battery is plugged in, device negotiates for 20V and starts charging. 3) Tested dead battery by taking a battery with no charge, and plugging in zinger. Everything boots, but PD does not negotiate for power. Then when battery reaches 1%, PD negotiates and zinger switches to 20V without causing a reboot. Change-Id: Iaa451403674e86cddbd3fe80e9503584910be576 Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/201958 Reviewed-by: Vincent Palatin --- include/charge_state.h | 2 ++ include/config.h | 14 +++++++++----- include/ec_commands.h | 19 +++++++++++++++++++ include/host_command.h | 6 ++++++ include/usb_pd.h | 7 +++++++ 5 files changed, 43 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/charge_state.h b/include/charge_state.h index 0da544422f..c23e70c260 100644 --- a/include/charge_state.h +++ b/include/charge_state.h @@ -50,6 +50,8 @@ enum charge_state { #define CHARGE_FLAG_FORCE_IDLE (1 << 0) /* External (AC) power is present */ #define CHARGE_FLAG_EXTERNAL_POWER (1 << 1) +/* Battery is responsive */ +#define CHARGE_FLAG_BATT_RESPONSIVE (1 << 2) /* Debugging constants, in the same order as enum charge_state. This string * table was moved here to sync with enum above. diff --git a/include/config.h b/include/config.h index 464ad50953..43f7cfdbca 100644 --- a/include/config.h +++ b/include/config.h @@ -503,9 +503,6 @@ /*****************************************************************************/ -/* Support EC acting as host master for other MCUs. */ -#undef CONFIG_HOST_CMD_MASTER - /* * Support the host asking the EC about the status of the most recent host * command. @@ -866,12 +863,19 @@ #undef CONFIG_UART_TX_DMA /*****************************************************************************/ +/* USB PD config */ + +/* USB PD MCU slave address for host commands */ +#define CONFIG_USB_PD_I2C_SLAVE_ADDR 0x3c + +/* TODO(crosbug.com/p/29499): Determine threshold for power negotiation */ +/* USB PD minimum battery charge to negotiate for more power */ +#define CONFIG_USB_PD_MIN_BATT_CHARGE 1 /* USB PD transmit uses SPI master */ #undef CONFIG_USB_PD_TX_USES_SPI_MASTER -/* USB PD MCU slave address for host commands */ -#define CONFIG_USB_PD_I2C_SLAVE_ADDR 0x3c +/*****************************************************************************/ /* Support simple control of power to the device's USB ports */ #undef CONFIG_USB_PORT_POWER_DUMB diff --git a/include/ec_commands.h b/include/ec_commands.h index 1526084986..5edd754df3 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -2476,6 +2476,25 @@ struct ec_params_reboot_ec { #endif /* !__ACPI__ */ +/*****************************************************************************/ +/* + * PD commands + * + * These commands are for PD MCU communication. + */ + +/* EC to PD MCU exchange status command */ +#define EC_CMD_PD_EXCHANGE_STATUS 0x100 + +/* Status of EC being sent to PD */ +struct ec_params_pd_status { + int8_t batt_soc; /* battery state of charge */ +} __packed; + +/* Status of PD being sent back to EC */ +struct ec_response_pd_status { +} __packed; + /*****************************************************************************/ /* * Deprecated constants. These constants have been renamed for clarity. The diff --git a/include/host_command.h b/include/host_command.h index 1fbf0b6554..231ef9a6b8 100644 --- a/include/host_command.h +++ b/include/host_command.h @@ -207,6 +207,12 @@ void host_packet_receive(struct host_packet *pkt); */ void host_throttle_cpu(int throttle); + +/** + * Signal host command task to send status to PD MCU. + */ +void host_command_pd_send_status(void); + /** * Send host command to PD MCU. * diff --git a/include/usb_pd.h b/include/usb_pd.h index 89229079a4..e8f9168aa7 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -185,6 +185,13 @@ void pd_request_source_voltage(int mv); */ int pd_board_checks(void); +/** + * Query if power negotiation is allowed. + * + * @return true if negotation is allowed, false otherwise. + */ +int pd_power_negotiation_allowed(void); + /* * Handle Vendor Defined Message with our vendor ID. * -- cgit v1.2.1