summaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2014-08-04 17:52:53 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-08-09 00:20:06 +0000
commit0815df9cbf1104a2c7fabdd4197358d54cdc8922 (patch)
treec0f1d79fd3e24eb6b4d10741e34565879baff3f1 /board
parent566de98ca6b0d6a579a2dae84ecaac40c703abf7 (diff)
downloadchrome-ec-0815df9cbf1104a2c7fabdd4197358d54cdc8922.tar.gz
samus: ryu: set input current limit based on PD negotiation
Set input current limit based on the max current from the PD negotiation. For samus, this information is passed to the EC as a host command. For ryu, the max current is set directly following a negotiation. CONFIG_CHARGER_INPUT_CURRENT is now just the default limit, but after a successful PD negotiation, the limit can be raised. Note, for now the input current limit for samus is set to 2/3 of the value negotiated for. This is due to hardware problems measuring input current on p2b boards. BUG=chrome-os-partner:28532, chrome-os-partner:24461 BRANCH=none TEST=tested on a samus. Verified input current limit using "charger" console command from EC. Input current limit after a reboot is 512. When zinger is plugged in, it jumps to the appropriate value (currently 1280mA), and when the negotiation is changed using the "pd 0 dev 5" command on the PD console, the input current limit is adjusted to match (2000mA). Change-Id: Iab9186a0f9814655e3240217a9baf4a38f15f84d Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/211023 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'board')
-rw-r--r--board/firefly/usb_pd_policy.c10
-rw-r--r--board/fruitpie/usb_pd_policy.c22
-rw-r--r--board/plankton/usb_pd_policy.c10
-rw-r--r--board/ryu/board.h2
-rw-r--r--board/ryu/usb_pd_policy.c22
-rw-r--r--board/samus/board.h8
-rw-r--r--board/samus_pd/usb_pd_policy.c24
7 files changed, 72 insertions, 26 deletions
diff --git a/board/firefly/usb_pd_policy.c b/board/firefly/usb_pd_policy.c
index 7ddf6f65ed..dab977fc29 100644
--- a/board/firefly/usb_pd_policy.c
+++ b/board/firefly/usb_pd_policy.c
@@ -60,8 +60,14 @@ int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo)
/* request all the power ... */
ma = 10 * (src_caps[i] & 0x3FF);
*rdo = RDO_FIXED(i + 1, ma, ma, 0);
- ccprintf("Request [%d] %d V %d mA\n", i, set_mv/1000, ma);
- return EC_SUCCESS;
+ ccprintf("Request [%d] %dV %dmA\n", i, set_mv/1000, ma);
+ return ma;
+}
+
+void pd_set_input_current_limit(uint32_t max_ma)
+{
+ /* No battery, nothing to do */
+ return;
}
void pd_set_max_voltage(unsigned mv)
diff --git a/board/fruitpie/usb_pd_policy.c b/board/fruitpie/usb_pd_policy.c
index e8886aabe8..3292a80a77 100644
--- a/board/fruitpie/usb_pd_policy.c
+++ b/board/fruitpie/usb_pd_policy.c
@@ -3,6 +3,7 @@
* found in the LICENSE file.
*/
+#include "charger.h"
#include "common.h"
#include "console.h"
#include "gpio.h"
@@ -37,6 +38,7 @@ int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo)
int i;
int sel_mv;
int max_uw = 0;
+ int max_ma;
int max_i = -1;
/* Get max power */
@@ -61,16 +63,26 @@ int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo)
/* request all the power ... */
if ((src_caps[max_i] & PDO_TYPE_MASK) == PDO_TYPE_BATTERY) {
int uw = 250000 * (src_caps[max_i] & 0x3FF);
+ max_ma = uw / sel_mv;
*rdo = RDO_BATT(max_i + 1, uw/2, uw, 0);
- ccprintf("Request [%d] %dV %d/%d mW\n",
- max_i, sel_mv/1000, uw/1000, uw/1000);
+ ccprintf("Request [%d] %dV %dmW\n",
+ max_i, sel_mv/1000, uw/1000);
} else {
int ma = 10 * (src_caps[max_i] & 0x3FF);
+ max_ma = ma;
*rdo = RDO_FIXED(max_i + 1, ma / 2, ma, 0);
- ccprintf("Request [%d] %dV %d/%d mA\n",
- max_i, sel_mv/1000, max_i, ma/2, ma);
+ ccprintf("Request [%d] %dV %dmA\n",
+ max_i, sel_mv/1000, ma);
}
- return EC_SUCCESS;
+ return max_ma;
+}
+
+void pd_set_input_current_limit(uint32_t max_ma)
+{
+ int rv = charger_set_input_current(MAX(max_ma,
+ CONFIG_CHARGER_INPUT_CURRENT));
+ if (rv < 0)
+ CPRINTS("Failed to set input current limit for PD");
}
void pd_set_max_voltage(unsigned mv)
diff --git a/board/plankton/usb_pd_policy.c b/board/plankton/usb_pd_policy.c
index c0d58e236b..c2ac2fd155 100644
--- a/board/plankton/usb_pd_policy.c
+++ b/board/plankton/usb_pd_policy.c
@@ -77,8 +77,14 @@ int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo)
/* request all the power ... */
ma = 10 * (src_caps[i] & 0x3FF);
*rdo = RDO_FIXED(i + 1, ma, ma, 0);
- ccprintf("Request [%d] %d V %d mA\n", i, set_mv/1000, ma);
- return EC_SUCCESS;
+ ccprintf("Request [%d] %dV %dmA\n", i, set_mv/1000, ma);
+ return ma;
+}
+
+void pd_set_input_current_limit(uint32_t max_ma)
+{
+ /* No battery, nothing to do */
+ return;
}
void pd_set_max_voltage(unsigned mv)
diff --git a/board/ryu/board.h b/board/ryu/board.h
index 2d837fa3f8..a59db2f93f 100644
--- a/board/ryu/board.h
+++ b/board/ryu/board.h
@@ -44,7 +44,7 @@
#define CONFIG_CHARGER_ILIM_PIN_DISABLED
#define CONFIG_CHARGER_SENSE_RESISTOR 5
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
-#define CONFIG_CHARGER_INPUT_CURRENT 1024
+#define CONFIG_CHARGER_INPUT_CURRENT 512
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHIPSET_TEGRA
#define CONFIG_PMIC_FW_LONG_PRESS_TIMER
diff --git a/board/ryu/usb_pd_policy.c b/board/ryu/usb_pd_policy.c
index fe8247de8d..f202b31e24 100644
--- a/board/ryu/usb_pd_policy.c
+++ b/board/ryu/usb_pd_policy.c
@@ -3,6 +3,7 @@
* found in the LICENSE file.
*/
+#include "charger.h"
#include "common.h"
#include "console.h"
#include "gpio.h"
@@ -38,6 +39,7 @@ int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo)
int i;
int sel_mv;
int max_uw = 0;
+ int max_ma;
int max_i = -1;
/* Get max power */
@@ -62,16 +64,26 @@ int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo)
/* request all the power ... */
if ((src_caps[max_i] & PDO_TYPE_MASK) == PDO_TYPE_BATTERY) {
int uw = 250000 * (src_caps[max_i] & 0x3FF);
+ max_ma = uw / sel_mv;
*rdo = RDO_BATT(max_i + 1, uw/2, uw, 0);
- ccprintf("Request [%d] %dV %d/%d mW\n",
- max_i, sel_mv/1000, uw/1000, uw/1000);
+ ccprintf("Request [%d] %dV %dmW\n",
+ max_i, sel_mv/1000, uw/1000);
} else {
int ma = 10 * (src_caps[max_i] & 0x3FF);
+ max_ma = ma;
*rdo = RDO_FIXED(max_i + 1, ma / 2, ma, 0);
- ccprintf("Request [%d] %dV %d/%d mA\n",
- max_i, sel_mv/1000, max_i, ma/2, ma);
+ ccprintf("Request [%d] %dV %dmA\n",
+ max_i, sel_mv/1000, ma);
}
- return EC_SUCCESS;
+ return max_ma;
+}
+
+void pd_set_input_current_limit(uint32_t max_ma)
+{
+ int rv = charger_set_input_current(MAX(max_ma,
+ CONFIG_CHARGER_INPUT_CURRENT));
+ if (rv < 0)
+ CPRINTS("Failed to set input current limit for PD");
}
void pd_set_max_voltage(unsigned mv)
diff --git a/board/samus/board.h b/board/samus/board.h
index d6b41f408e..eb13854008 100644
--- a/board/samus/board.h
+++ b/board/samus/board.h
@@ -38,11 +38,9 @@
#define CONFIG_CHARGER_V2
#define CONFIG_CHARGER_BQ24773
#define CONFIG_CHARGER_ILIM_PIN_DISABLED
-/* FIXME(crosbug.com/p/28721): determine correct values for these */
-#define CONFIG_CHARGER_SENSE_RESISTOR 5
-#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
-/* FIXME(crosbug.com/p/24461): determine correct values for this */
-#define CONFIG_CHARGER_INPUT_CURRENT 2048
+#define CONFIG_CHARGER_SENSE_RESISTOR 5
+#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
+#define CONFIG_CHARGER_INPUT_CURRENT 512
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_FANS 2
#define CONFIG_PECI_TJMAX 100
diff --git a/board/samus_pd/usb_pd_policy.c b/board/samus_pd/usb_pd_policy.c
index 115a7812a8..4edbed4f79 100644
--- a/board/samus_pd/usb_pd_policy.c
+++ b/board/samus_pd/usb_pd_policy.c
@@ -36,11 +36,15 @@ static unsigned max_mv = -1; /* no cap */
/* Battery state of charge percentage */
static int batt_soc;
+/* PD MCU status for host response */
+static struct ec_response_pd_status pd_status;
+
int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo)
{
int i;
int sel_mv;
int max_uw = 0;
+ int max_ma;
int max_i = -1;
/* Get max power */
@@ -65,16 +69,18 @@ int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo)
/* request all the power ... */
if ((src_caps[max_i] & PDO_TYPE_MASK) == PDO_TYPE_BATTERY) {
int uw = 250000 * (src_caps[max_i] & 0x3FF);
+ max_ma = uw / sel_mv;
*rdo = RDO_BATT(max_i + 1, uw/2, uw, 0);
- ccprintf("Request [%d] %dV %d/%d mW\n",
- max_i, sel_mv/1000, uw/1000, uw/1000);
+ ccprintf("Request [%d] %dV %dmW\n",
+ max_i, sel_mv/1000, uw/1000);
} else {
int ma = 10 * (src_caps[max_i] & 0x3FF);
+ max_ma = ma;
*rdo = RDO_FIXED(max_i + 1, ma / 2, ma, 0);
- ccprintf("Request [%d] %dV %d/%d mA\n",
- max_i, sel_mv/1000, max_i, ma/2, ma);
+ ccprintf("Request [%d] %dV %dmA\n",
+ max_i, sel_mv/1000, ma);
}
- return EC_SUCCESS;
+ return max_ma;
}
void pd_set_max_voltage(unsigned mv)
@@ -136,6 +142,12 @@ static void pd_send_ec_int(void)
gpio_set_level(GPIO_EC_INT_L, 1);
}
+void pd_set_input_current_limit(uint32_t max_ma)
+{
+ pd_status.curr_lim_ma = max_ma;
+ pd_send_ec_int();
+}
+
int pd_board_checks(void)
{
return EC_SUCCESS;
@@ -214,7 +226,7 @@ static int ec_status_host_cmd(struct host_cmd_handler_args *args)
batt_soc = p->batt_soc;
- r->status = 0;
+ *r = pd_status;
args->response_size = sizeof(*r);