summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-04-02 15:52:31 +0800
committerChromeBot <chrome-bot@google.com>2013-04-02 23:10:29 -0700
commitd0912c8d92c529208d3f90bd79714d007577c553 (patch)
treed564701d03e3741d57ba4115f038ef07acc8c36d
parentb41b1f5ba80108e27fc285ebc00fa76e75d98edd (diff)
downloadchrome-ec-d0912c8d92c529208d3f90bd79714d007577c553.tar.gz
spring: Add host command to limit external power current
This is useful for debugging and the factory. BUG=chrome-os-partner:18530 TEST=On spring, check we can set PWM duty cycle and can go back to automatic control. BRANCH=spring Original-Change-Id: I3da75f0a356cc0f21d748bf135e3b95fbd9c465b Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/47105 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> (cherry picked from commit 13c74da5ade0b98c9c024bf72e0c78c5155a8d08) Change-Id: I552a8082b37b849e6b0b19663390753fbb363d7e Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/47218 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/spring/usb_charging.c41
-rw-r--r--include/ec_commands.h11
-rw-r--r--util/ectool.c26
3 files changed, 74 insertions, 4 deletions
diff --git a/board/spring/usb_charging.c b/board/spring/usb_charging.c
index 75b57826da..10c834ee77 100644
--- a/board/spring/usb_charging.c
+++ b/board/spring/usb_charging.c
@@ -10,14 +10,16 @@
#include "chipset.h"
#include "clock.h"
#include "console.h"
-#include "hooks.h"
#include "gpio.h"
-#include "lp5562.h"
+#include "hooks.h"
+#include "host_command.h"
#include "keyboard_scan.h"
+#include "lp5562.h"
#include "pmu_tpschrome.h"
#include "registers.h"
#include "smart_battery.h"
#include "stm32_adc.h"
+#include "system.h"
#include "task.h"
#include "timer.h"
#include "tsu6721.h"
@@ -64,9 +66,17 @@
#define DELAY_USB_DP_DN_MS 20
#define DELAY_ID_MUX_MS 30
+/*
+ * Mapping from PWM duty to current:
+ * Current = A + B * PWM_Duty
+ */
+#define PWM_MAPPING_A 3012
+#define PWM_MAPPING_B (-29)
+
static int current_dev_type = TSU6721_TYPE_NONE;
static int nominal_pwm_duty;
static int current_pwm_duty;
+static int user_pwm_duty = -1;
static int pending_tsu6721_reset;
@@ -291,6 +301,13 @@ static void board_pwm_tweak(void)
vbus = adc_read_channel(ADC_CH_USB_VBUS_SNS);
if (battery_current(&current))
return;
+
+ if (user_pwm_duty >= 0) {
+ if (current_pwm_duty != user_pwm_duty)
+ board_pwm_duty_cycle(user_pwm_duty);
+ return;
+ }
+
/*
* If VBUS voltage is too low:
* - If battery is discharging, throttling more is going to draw
@@ -548,7 +565,7 @@ int board_get_usb_dev_type(void)
int board_get_usb_current_limit(void)
{
/* Approximate value by PWM duty cycle */
- return 3012 - 29 * current_pwm_duty;
+ return PWM_MAPPING_A + PWM_MAPPING_B * current_pwm_duty;
}
/*
@@ -632,3 +649,21 @@ DECLARE_CONSOLE_COMMAND(limitmode, command_current_limit_mode,
"[normal | aggressive]",
"Set current limit mode",
NULL);
+
+/*****************************************************************************/
+/* Host commands */
+
+static int ext_power_command_current_limit(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_ext_power_current_limit *p = args->params;
+
+ if (system_is_locked())
+ return EC_RES_ACCESS_DENIED;
+
+ user_pwm_duty = ((int)(p->limit) - PWM_MAPPING_A) / PWM_MAPPING_B;
+
+ return EC_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_EXT_POWER_CURRENT_LIMIT,
+ ext_power_command_current_limit,
+ EC_VER_MASK(0));
diff --git a/include/ec_commands.h b/include/ec_commands.h
index cd714cc1db..84b5d5582a 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1273,7 +1273,16 @@ struct ec_response_power_info {
#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
struct ec_params_current_limit {
- uint32_t limit;
+ uint32_t limit; /* in mA */
+} __packed;
+
+/*
+ * Set maximum external power current.
+ */
+#define EC_CMD_EXT_POWER_CURRENT_LIMIT 0xa2
+
+struct ec_params_ext_power_current_limit {
+ uint32_t limit; /* in mA */
} __packed;
/*****************************************************************************/
diff --git a/util/ectool.c b/util/ectool.c
index 3804170b8d..ff40734529 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -28,6 +28,8 @@ static inline int MIN(int a, int b) { return a < b ? a : b; }
const char help_str[] =
"Commands:\n"
+ " extpwrcurrentlimit\n"
+ " Set the maximum external power current\n"
" autofanctrl <on>\n"
" Turn on automatic fan speed control.\n"
" backlight <enabled>\n"
@@ -2026,6 +2028,29 @@ int cmd_lcd_backlight(int argc, char *argv[])
}
+int cmd_ext_power_current_limit(int argc, char *argv[])
+{
+ struct ec_params_ext_power_current_limit p;
+ int rv;
+ char *e;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <max_current_mA>\n", argv[0]);
+ return -1;
+ }
+
+ p.limit = strtol(argv[1], &e, 0);
+ if (e && *e) {
+ fprintf(stderr, "Bad value.\n");
+ return -1;
+ }
+
+ rv = ec_command(EC_CMD_EXT_POWER_CURRENT_LIMIT, 0, &p, sizeof(p),
+ NULL, 0);
+ return rv;
+}
+
+
int cmd_charge_current_limit(int argc, char *argv[])
{
struct ec_params_current_limit p;
@@ -2732,6 +2757,7 @@ struct command {
/* NULL-terminated list of commands */
const struct command commands[] = {
+ {"extpwrcurrentlimit", cmd_ext_power_current_limit},
{"autofanctrl", cmd_thermal_auto_fan_ctrl},
{"backlight", cmd_lcd_backlight},
{"battery", cmd_battery},