summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2014-10-27 18:09:28 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-10-31 19:22:00 +0000
commite6a2d4c0440aefda9a77f449230e7f710db426a5 (patch)
tree0f01a1b0b9b3c3ed87e0d8b5c45922aae9f81c05
parentce9ae08b6889e7d7032ba66821e4c73dae20fb78 (diff)
downloadchrome-ec-e6a2d4c0440aefda9a77f449230e7f710db426a5.tar.gz
samus_pd: add more host events and host cmd to get event status
Add support for more host events and add a host command for the host to use to get which host events have fired. The EC only uses one real host command to notify the AP whenever the PD MCU needs attention so the EC_CMD_PD_HOST_EVENT_STATUS host command can be used to differentiate the possible triggers for the host event. Current events include: PD remote device needs update, type-C power info changed, and PD identity response received. Added host event for power info change, which fires whenever a charger or device is plugged into a type-C port. BUG=chrome-os-partner:32650 BRANCH=samus TEST=tested on samus by connected various peripherals to type-C ports and verifying on EC console that a host event is sent. Change-Id: Ibfc2cafe5826a0ab41aee96a68fdb561c0a2b4ab Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/225841 Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
-rw-r--r--board/samus_pd/board.c43
-rw-r--r--board/samus_pd/board.h2
-rw-r--r--board/samus_pd/usb_pd_policy.c15
-rw-r--r--include/ec_commands.h11
4 files changed, 65 insertions, 6 deletions
diff --git a/board/samus_pd/board.c b/board/samus_pd/board.c
index 736b28360e..b222c84941 100644
--- a/board/samus_pd/board.c
+++ b/board/samus_pd/board.c
@@ -35,8 +35,9 @@ static enum power_state ps;
/* Battery state of charge */
int batt_soc;
-/* PD MCU status for host response */
+/* PD MCU status and host event status for host command */
static struct ec_response_pd_status pd_status;
+static struct ec_response_host_event_status host_event_status;
/* PWM channels. Must be in the exact same order as in enum pwm_channel. */
const struct pwm_t pwm_channels[] = {
@@ -110,6 +111,9 @@ static void board_usb_charger_update(int port)
charge_manager_update(CHARGE_SUPPLIER_BC12_SDP, port, &charge);
charge_manager_update(CHARGE_SUPPLIER_OTHER, port, &charge);
}
+
+ /* notify host of power info change */
+ pd_send_host_event(PD_EVENT_POWER_CHANGE);
}
/* Pericom USB deferred tasks -- called after USB device insert / removal */
@@ -483,8 +487,13 @@ void board_set_charge_limit(int charge_ma)
}
/* Send host event up to AP */
-void pd_send_host_event(void)
+void pd_send_host_event(int mask)
{
+ /* mask must be set */
+ if (!mask)
+ return;
+
+ atomic_or(&(host_event_status.status), mask);
atomic_or(&(pd_status.status), PD_STATUS_HOST_EVENT);
pd_send_ec_int();
}
@@ -504,12 +513,22 @@ DECLARE_CONSOLE_COMMAND(ecint, command_ec_int,
static int command_pd_host_event(int argc, char **argv)
{
- pd_send_host_event();
+ int event_mask;
+ char *e;
+
+ if (argc < 2)
+ return EC_ERROR_PARAM_COUNT;
+
+ event_mask = strtoi(argv[1], &e, 10);
+ if (*e)
+ return EC_ERROR_PARAM1;
+
+ pd_send_host_event(event_mask);
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(pdevent, command_pd_host_event,
- "",
+ "event_mask",
"Send PD host event",
NULL);
@@ -533,3 +552,19 @@ static int ec_status_host_cmd(struct host_cmd_handler_args *args)
}
DECLARE_HOST_COMMAND(EC_CMD_PD_EXCHANGE_STATUS, ec_status_host_cmd,
EC_VER_MASK(0));
+
+static int host_event_status_host_cmd(struct host_cmd_handler_args *args)
+{
+ struct ec_response_pd_status *r = args->response;
+
+ /* Clear host event bit to avoid sending more unnecessary events */
+ atomic_clear(&(pd_status.status), PD_STATUS_HOST_EVENT);
+
+ /* 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));
diff --git a/board/samus_pd/board.h b/board/samus_pd/board.h
index 62805b6c07..a993cd4842 100644
--- a/board/samus_pd/board.h
+++ b/board/samus_pd/board.h
@@ -121,7 +121,7 @@ void board_set_active_charge_port(int charge_port);
void board_set_charge_limit(int charge_ma);
/* Send host event to AP */
-void pd_send_host_event(void);
+void pd_send_host_event(int mask);
#endif /* !__ASSEMBLER__ */
diff --git a/board/samus_pd/usb_pd_policy.c b/board/samus_pd/usb_pd_policy.c
index 98b187bf08..c25c05e9fc 100644
--- a/board/samus_pd/usb_pd_policy.c
+++ b/board/samus_pd/usb_pd_policy.c
@@ -9,6 +9,7 @@
#include "console.h"
#include "gpio.h"
#include "hooks.h"
+#include "host_command.h"
#include "registers.h"
#include "task.h"
#include "timer.h"
@@ -118,6 +119,9 @@ int pd_set_power_supply_ready(int port)
/* provide VBUS */
gpio_set_level(port ? GPIO_USB_C1_5V_EN : GPIO_USB_C0_5V_EN, 1);
+ /* notify host of power info change */
+ pd_send_host_event(PD_EVENT_POWER_CHANGE);
+
return EC_SUCCESS; /* we are ready */
}
@@ -125,6 +129,9 @@ void pd_power_supply_reset(int port)
{
/* Kill VBUS */
gpio_set_level(port ? GPIO_USB_C1_5V_EN : GPIO_USB_C0_5V_EN, 0);
+
+ /* notify host of power info change */
+ pd_send_host_event(PD_EVENT_POWER_CHANGE);
}
void pd_set_input_current_limit(int port, uint32_t max_ma,
@@ -134,6 +141,9 @@ void pd_set_input_current_limit(int port, uint32_t max_ma,
charge.current = max_ma;
charge.voltage = supply_voltage;
charge_manager_update(CHARGE_SUPPLIER_PD, port, &charge);
+
+ /* notify host of power info change */
+ pd_send_host_event(PD_EVENT_POWER_CHANGE);
}
void typec_set_input_current_limit(int port, uint32_t max_ma,
@@ -143,6 +153,9 @@ void typec_set_input_current_limit(int port, uint32_t max_ma,
charge.current = max_ma;
charge.voltage = supply_voltage;
charge_manager_update(CHARGE_SUPPLIER_TYPEC, port, &charge);
+
+ /* notify host of power info change */
+ pd_send_host_event(PD_EVENT_POWER_CHANGE);
}
int pd_board_checks(void)
@@ -179,7 +192,7 @@ static int pd_custom_vdm(int port, int cnt, uint32_t *payload,
/* if last word is present, it contains lots of info */
if (cnt == 7) {
/* send host event */
- pd_send_host_event();
+ pd_send_host_event(PD_EVENT_UPDATE_DEVICE);
dev_id = VDO_INFO_HW_DEV_ID(payload[6]);
CPRINTF("Dev:0x%04x SW:%d RW:%d\n", dev_id,
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 07bf6a5a43..df392d7d62 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -2699,6 +2699,17 @@ struct ec_response_pd_status {
uint32_t curr_lim_ma; /* input current limit */
} __packed;
+/* AP to PD MCU host event status command, cleared on read */
+#define EC_CMD_PD_HOST_EVENT_STATUS 0x104
+
+/* PD MCU host event status bits */
+#define PD_EVENT_UPDATE_DEVICE (1 << 0)
+#define PD_EVENT_POWER_CHANGE (1 << 1)
+#define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
+struct ec_response_host_event_status {
+ uint32_t status; /* PD MCU host event status */
+} __packed;
+
/* Set USB type-C port role and muxes */
#define EC_CMD_USB_PD_CONTROL 0x101