summaryrefslogtreecommitdiff
path: root/driver/gl3590.c
diff options
context:
space:
mode:
authorJan Dabros <jsd@semihalf.com>2020-12-29 12:46:20 +0100
committerCommit Bot <commit-bot@chromium.org>2021-01-14 14:40:18 +0000
commit4ccfbe2d22b5c7f65a182dfb5bb35fe033799a2f (patch)
tree5348c7d6f1fe2ee0b87b34e95dc92e39fa39b08e /driver/gl3590.c
parent0873122c27b50455b0618d7cf58a4e7cde4f2aef (diff)
downloadchrome-ec-4ccfbe2d22b5c7f65a182dfb5bb35fe033799a2f.tar.gz
gl3590: Add method for querying UFP connection power capabilities
GL3590's registers allow to gather information about host connection, e.g. available power. This may be used by platforms which are powered by hub's UFP. Add missing license headers. BUG=b:144776402 BRANCH=main TEST=With consecutive patch applied, verify that available input power reported by servo_v4p1 is correct. Signed-off-by: Jan Dabros <jsd@semihalf.com> Change-Id: I6a9881fe844b293800653f141c418257c6ebc4e5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2606237 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/gl3590.c')
-rw-r--r--driver/gl3590.c61
1 files changed, 56 insertions, 5 deletions
diff --git a/driver/gl3590.c b/driver/gl3590.c
index bde2971553..2faf69178a 100644
--- a/driver/gl3590.c
+++ b/driver/gl3590.c
@@ -1,9 +1,17 @@
-#include <console.h>
-#include <i2c.h>
-#include <system.h>
-#include <util.h>
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "console.h"
+#include "i2c.h"
+#include "system.h"
+#include "util.h"
+#include "pwr_defs.h"
+
+#include "gl3590.h"
-#include <gl3590.h>
+#define CPRINTF(format, args...) cprintf(CC_I2C, format, ## args)
/* GL3590 is unique in terms of i2c_read, since it doesn't support repeated
* start sequence. One need to issue two separate transactions - first is write
@@ -142,3 +150,46 @@ exit:
buf = GL3590_INT_CLEAR;
gl3590_write(hub, GL3590_INT_REG, &buf, sizeof(buf));
}
+
+enum ec_error_list gl3590_ufp_pwr(int hub, struct pwr_con_t *pwr)
+{
+ uint8_t hub_sts, hub_mode;
+ int rv = 0;
+
+ if (gl3590_read(hub, GL3590_HUB_STS_REG, &hub_sts, sizeof(hub_sts))) {
+ CPRINTF("Error reading HUB_STS %d\n", rv);
+ return EC_ERROR_BUSY;
+ }
+
+ pwr->volts = 5;
+
+ switch ((hub_sts & GL3590_HUB_STS_HOST_PWR_MASK) >>
+ GL3590_HUB_STS_HOST_PWR_SHIFT) {
+ case GL3590_DEFAULT_HOST_PWR_SRC:
+ if (gl3590_read(hub, GL3590_HUB_MODE_REG, &hub_mode,
+ sizeof(hub_mode))) {
+ CPRINTF("Error reading HUB_MODE %d\n", rv);
+ return EC_ERROR_BUSY;
+ }
+ if (hub_mode & GL3590_HUB_MODE_USB3_EN) {
+ pwr->milli_amps = 900;
+ return EC_SUCCESS;
+ } else if (hub_mode & GL3590_HUB_MODE_USB2_EN) {
+ pwr->milli_amps = 500;
+ return EC_SUCCESS;
+ } else {
+ CPRINTF("GL3590: Neither USB3 nor USB2 hubs "
+ "configured\n");
+ return EC_ERROR_HW_INTERNAL;
+ }
+ case GL3590_1_5_A_HOST_PWR_SRC:
+ pwr->milli_amps = 1500;
+ return EC_SUCCESS;
+ case GL3590_3_0_A_HOST_PWR_SRC:
+ pwr->milli_amps = 3000;
+ return EC_SUCCESS;
+ default:
+ CPRINTF("GL3590: Unkown host power source %d\n", hub_sts);
+ return EC_ERROR_UNKNOWN;
+ }
+}