summaryrefslogtreecommitdiff
path: root/board/samus_pd/board.c
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2014-10-27 11:47:45 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-10-28 01:46:38 +0000
commit5f4ea79bb19df9e0595f2011663587fe6ae736cd (patch)
tree582f76c12c86636dd03b4b57c4a755ba882ced27 /board/samus_pd/board.c
parentbf88b804ee831791378588e42c08a7c01f83ee40 (diff)
downloadchrome-ec-5f4ea79bb19df9e0595f2011663587fe6ae736cd.tar.gz
samus: use resulting current limit from charge manager
Send the current limit chosen by charge manager to the EC so that it can set the current limit appropriately. Note, before this change, only the PD negotiated current limit was sent to EC. BUG=none BRANCH=samus TEST=use a non-PD type-C charger and verify current limit gets set appropriately on EC. Change-Id: Ic4bfce052ec8150cad07d35e2cb2fcbfd3d3e6c8 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/225667 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'board/samus_pd/board.c')
-rw-r--r--board/samus_pd/board.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/board/samus_pd/board.c b/board/samus_pd/board.c
index 74b0bf9b19..d57ce4704f 100644
--- a/board/samus_pd/board.c
+++ b/board/samus_pd/board.c
@@ -12,6 +12,7 @@
#include "console.h"
#include "gpio.h"
#include "hooks.h"
+#include "host_command.h"
#include "i2c.h"
#include "pi3usb9281.h"
#include "power.h"
@@ -34,6 +35,9 @@ static enum power_state ps;
/* Battery state of charge */
int batt_soc;
+/* PD MCU status for host response */
+static struct ec_response_pd_status pd_status;
+
/* PWM channels. Must be in the exact same order as in enum pwm_channel. */
const struct pwm_t pwm_channels[] = {
{STM32_TIM(15), STM32_TIM_CH(2), 0, GPIO_ILIM_ADJ_PWM, GPIO_ALT_F1},
@@ -392,6 +396,20 @@ enum battery_present battery_is_present(void)
return BP_NOT_SURE;
}
+static void pd_send_ec_int(void)
+{
+ gpio_set_level(GPIO_EC_INT, 1);
+
+ /*
+ * Delay long enough to guarantee EC see's the change. Slowest
+ * EC clock speed is 250kHz in deep sleep -> 4us, and add 1us
+ * for buffer.
+ */
+ usleep(5);
+
+ gpio_set_level(GPIO_EC_INT, 0);
+}
+
/**
* Set active charge port -- only one port can be active at a time.
*
@@ -423,5 +441,61 @@ void board_set_charge_limit(int charge_ma)
pwm_duty = 100;
pwm_set_duty(PWM_CH_ILIM, pwm_duty);
+
+ pd_status.curr_lim_ma = charge_ma;
+ pd_send_ec_int();
+
CPRINTS("Set ilim duty %d", pwm_duty);
}
+
+/* Send host event up to AP */
+void pd_send_host_event(void)
+{
+ atomic_or(&(pd_status.status), PD_STATUS_HOST_EVENT);
+ pd_send_ec_int();
+}
+
+/****************************************************************************/
+/* Console commands */
+static int command_ec_int(int argc, char **argv)
+{
+ pd_send_ec_int();
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(ecint, command_ec_int,
+ "",
+ "Toggle EC interrupt line",
+ NULL);
+
+static int command_pd_host_event(int argc, char **argv)
+{
+ pd_send_host_event();
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(pdevent, command_pd_host_event,
+ "",
+ "Send PD host event",
+ NULL);
+
+/****************************************************************************/
+/* Host commands */
+static int ec_status_host_cmd(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_pd_status *p = args->params;
+ struct ec_response_pd_status *r = args->response;
+
+ board_update_battery_soc(p->batt_soc);
+
+ *r = pd_status;
+
+ /* Clear host event */
+ atomic_clear(&(pd_status.status), PD_STATUS_HOST_EVENT);
+
+ args->response_size = sizeof(*r);
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_PD_EXCHANGE_STATUS, ec_status_host_cmd,
+ EC_VER_MASK(0));