summaryrefslogtreecommitdiff
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
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>
-rw-r--r--driver/gl3590.c61
-rw-r--r--driver/gl3590.h24
-rw-r--r--include/pwr_defs.h25
3 files changed, 105 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;
+ }
+}
diff --git a/driver/gl3590.h b/driver/gl3590.h
index ef018d0685..991796c306 100644
--- a/driver/gl3590.h
+++ b/driver/gl3590.h
@@ -1,16 +1,40 @@
+/* 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 "pwr_defs.h"
+
/* Registers definitions */
+#define GL3590_HUB_MODE_REG 0x0
+#define GL3590_HUB_MODE_USB2_EN 0x2
+#define GL3590_HUB_MODE_USB3_EN 0x4
#define GL3590_INT_REG 0x1
#define GL3590_INT_PENDING 0x1
#define GL3590_INT_CLEAR 0x1
#define GL3590_RESPONSE_REG 0x2
#define GL3590_RESPONSE_REG_SYNC_MASK 0x80
+#define GL3590_HUB_STS_REG 0xA
+#define GL3590_HUB_STS_HOST_PWR_MASK 0x30
+#define GL3590_HUB_STS_HOST_PWR_SHIFT 4
+#define GL3590_DEFAULT_HOST_PWR_SRC 0x0
+#define GL3590_1_5_A_HOST_PWR_SRC 0x1
+#define GL3590_3_0_A_HOST_PWR_SRC 0x2
#define GL3590_I2C_ADDR0 0x50
+/* Read GL3590 I2C register */
int gl3590_read(int hub, uint8_t reg, uint8_t *data, int count);
+
+/* Write to GL3590 I2C register */
int gl3590_write(int hub, uint8_t reg, uint8_t *data, int count);
+
+/* Generic handler for GL3590 IRQ, can be registered/invoked by platform */
void gl3590_irq_handler(int hub);
+/* Get power capabilities of UFP host connection */
+enum ec_error_list gl3590_ufp_pwr(int hub, struct pwr_con_t *pwr);
+
/* Generic USB HUB I2C interface */
struct uhub_i2c_iface_t {
int i2c_host_port;
diff --git a/include/pwr_defs.h b/include/pwr_defs.h
new file mode 100644
index 0000000000..c01e602397
--- /dev/null
+++ b/include/pwr_defs.h
@@ -0,0 +1,25 @@
+/* Copyright 2021 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.
+ */
+
+#ifndef __CROS_EC_PWR_DEFS_H
+#define __CROS_EC_PWR_DEFS_H
+
+#include "system.h"
+
+struct pwr_con_t {
+ uint16_t volts;
+ uint16_t milli_amps;
+};
+
+/*
+ * Return power (in milliwatts) corresponding to input power connection
+ * struct entry.
+ */
+inline int pwr_con_to_milliwatts(struct pwr_con_t *pwr)
+{
+ return (pwr->volts * pwr->milli_amps);
+}
+
+#endif