diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2016-01-06 17:02:49 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-01-07 20:12:58 -0800 |
commit | 126f48aa3f31065cb0f340a68219fa7894f1b53b (patch) | |
tree | 1ab62633dfe39d3956ec549d2da86d7f02b8b444 | |
parent | c7c04e673efe535e00003fa66c83f7b19a5a0786 (diff) | |
download | chrome-ec-126f48aa3f31065cb0f340a68219fa7894f1b53b.tar.gz |
pd: Add common EC_HOST_EVENT_PD_MCU implementation
For TCPMs with an off chip TCPC, PD MCU host event status can be handled
in a common way. When a status flag is updated (ex. from
charge_manager), notify the AP through the host event, and save the
status flag for later retrieval.
BUG=chrome-os-partner:49124
BRANCH=None
TEST=Verify `cat /sys/class/power_supply/CROS_USB_PD_CHARGER1/online` on
chell reflects the actual online status of the charger. Also verify UI
charge icon tracks the online status correctly.
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I63bc70205627474590e38ffd282faedaea3bcc66
Reviewed-on: https://chromium-review.googlesource.com/320796
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
-rw-r--r-- | board/lucid/board.c | 4 | ||||
-rw-r--r-- | board/oak/board.c | 36 | ||||
-rw-r--r-- | board/strago/board.h | 2 | ||||
-rw-r--r-- | common/host_command_pd.c | 34 | ||||
-rw-r--r-- | common/usb_pd_policy.c | 6 | ||||
-rw-r--r-- | test/charge_manager.c | 5 | ||||
-rw-r--r-- | test/charge_ramp.c | 4 | ||||
-rw-r--r-- | test/test_config.h | 5 |
8 files changed, 46 insertions, 50 deletions
diff --git a/board/lucid/board.c b/board/lucid/board.c index 12bf407a36..d82467bd7e 100644 --- a/board/lucid/board.c +++ b/board/lucid/board.c @@ -153,3 +153,7 @@ enum battery_present battery_is_present(void) { return gpio_get_level(GPIO_BAT_PRESENT) ? BP_YES : BP_NO; } + +void pd_send_host_event(int mask) +{ +} diff --git a/board/oak/board.c b/board/oak/board.c index fef8387663..1b4141b4f7 100644 --- a/board/oak/board.c +++ b/board/oak/board.c @@ -47,20 +47,13 @@ #define GPIO_KB_INPUT (GPIO_INPUT | GPIO_PULL_UP | GPIO_INT_BOTH) #define GPIO_KB_OUTPUT GPIO_ODR_HIGH -/* - * PD host event status for host command - * Note: this variable must be aligned on 4-byte boundary because we pass the - * address to atomic_ functions which use assembly to access them. - */ -static struct ec_response_host_event_status host_event_status __aligned(4); - /* Dispaly port hardware can connect to port 0, 1 or neither. */ #define PD_PORT_NONE -1 void pd_mcu_interrupt(enum gpio_signal signal) { #ifdef HAS_TASK_PDCMD - /* Exchange status with PD MCU to determin interrupt cause */ + /* Exchange status with PD MCU to determine interrupt cause */ host_command_pd_send_status(0); #endif } @@ -182,18 +175,6 @@ void board_reset_pd_mcu(void) gpio_set_level(GPIO_USB_PD_RST_L, 1); } -/* Send host event up to AP */ -void pd_send_host_event(int mask) -{ - /* mask must be set */ - if (!mask) - return; - - atomic_or(&(host_event_status.status), mask); - /* interrupt the AP */ - host_set_single_event(EC_HOST_EVENT_PD_MCU); -} - /** * There is a level shift for AC_OK & LID_OPEN signal between AP & EC, * disable it (drive high) when AP is off, otherwise enable it (drive low). @@ -438,21 +419,6 @@ void board_set_ap_reset(int asserted) } } -/****************************************************************************/ -/* Host commands */ -static int host_event_status_host_cmd(struct host_cmd_handler_args *args) -{ - struct ec_response_host_event_status *r = args->response; - - /* Read and clear the host event status to return to AP */ - r->status = atomic_read_clear(&(host_event_status.status)); - - args->response_size = sizeof(*r); - return EC_RES_SUCCESS; -} -DECLARE_HOST_COMMAND(EC_CMD_PD_HOST_EVENT_STATUS, host_event_status_host_cmd, - EC_VER_MASK(0)); - #if BOARD_REV < OAK_REV4 /** * Check VBUS state and trigger USB BC1.2 charger. diff --git a/board/strago/board.h b/board/strago/board.h index bb64cc5d6e..1bf563a642 100644 --- a/board/strago/board.h +++ b/board/strago/board.h @@ -99,6 +99,8 @@ /* Modules we want to exclude */ #undef CONFIG_CMD_HASH #undef CONFIG_CMD_HOSTCMD +#undef CONFIG_CMD_I2C_SCAN +#undef CONFIG_CMD_IDLE_STATS #undef CONFIG_CMD_PD #undef CONFIG_CMD_SHMEM #undef CONFIG_CMD_TEMP_SENSOR diff --git a/common/host_command_pd.c b/common/host_command_pd.c index 70178bf933..a6883dcfd8 100644 --- a/common/host_command_pd.c +++ b/common/host_command_pd.c @@ -219,3 +219,37 @@ void pd_command_task(void) pd_exchange_status(ec_state); } } + +#ifdef USB_TCPM_WITH_OFF_CHIP_TCPC +/* + * PD host event status for host command + * Note: this variable must be aligned on 4-byte boundary because we pass the + * address to atomic_ functions which use assembly to access them. + */ +static uint32_t pd_host_event_status __aligned(4); + +static int hc_pd_host_event_status(struct host_cmd_handler_args *args) +{ + struct ec_response_host_event_status *r = args->response; + + /* Read and clear the host event status to return to AP */ + r->status = atomic_read_clear(&pd_host_event_status); + + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_PD_HOST_EVENT_STATUS, hc_pd_host_event_status, + EC_VER_MASK(0)); + +/* Send host event up to AP */ +void pd_send_host_event(int mask) +{ + /* mask must be set */ + if (!mask) + return; + + atomic_or(&pd_host_event_status, mask); + /* interrupt the AP */ + host_set_single_event(EC_HOST_EVENT_PD_MCU); +} +#endif diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c index b2bd91a512..a071f8b767 100644 --- a/common/usb_pd_policy.c +++ b/common/usb_pd_policy.c @@ -953,9 +953,3 @@ int pd_custom_flash_vdm(int port, int cnt, uint32_t *payload) } return rsize; } - -static void stub_pd_send_host_event(int mask) -{ -} -void pd_send_host_event(int mask) - __attribute__((weak, alias("stub_pd_send_host_event"))); diff --git a/test/charge_manager.c b/test/charge_manager.c index df569d957e..b60e19e0dc 100644 --- a/test/charge_manager.c +++ b/test/charge_manager.c @@ -36,11 +36,6 @@ static unsigned int charge_port_to_reject = CHARGE_PORT_NONE; static int new_power_request[CONFIG_USB_PD_PORT_COUNT]; static int power_role[CONFIG_USB_PD_PORT_COUNT]; -/* Callback function from charge_manager to send host event */ -void pd_send_host_event(int mask) -{ -} - /* Callback functions called by CM on state change */ void board_set_charge_limit(int charge_ma) { diff --git a/test/charge_ramp.c b/test/charge_ramp.c index ecb72bf142..12973f46ff 100644 --- a/test/charge_ramp.c +++ b/test/charge_ramp.c @@ -70,10 +70,6 @@ int board_get_ramp_current_limit(int supplier, int sup_curr) return 3000; } -void pd_send_host_event(int mask) -{ -} - /* Test utilities */ static void plug_charger_with_ts(int supplier_type, int port, int min_current, diff --git a/test/test_config.h b/test/test_config.h index c2887ae1cc..d7e4b7b172 100644 --- a/test/test_config.h +++ b/test/test_config.h @@ -149,5 +149,10 @@ int ncp15wb_calculate_temp(uint16_t adc); #define CONFIG_USB_PD_PORT_COUNT 2 #endif +#ifndef __ASSEMBLER__ +/* Callback function from charge_manager to send host event */ +static inline void pd_send_host_event(int mask) { } +#endif + #endif /* TEST_BUILD */ #endif /* __TEST_TEST_CONFIG_H */ |