i2c: cros_ec_tunnel: Add support for enabling pass-thru protection
authorNicolas Boichat <drinkcat@google.com>
Wed, 18 May 2016 07:57:27 +0000 (15:57 +0800)
committerchrome-bot <chrome-bot@chromium.org>
Thu, 26 May 2016 10:22:32 +0000 (03:22 -0700)
Makes it possible to call EC commands to restricts I2C passthru,
for example after ANX7688 firmware has been updated.

BRANCH=none
BUG=chrome-os-partner:52434
BUG=chrome-os-partner:52431
TEST=Build and boot elm

Change-Id: I9171f835f17059d50a4fb1b7456f8c7895d2cbd4
Signed-off-by: Nicolas Boichat <drinkcat@google.com>
Reviewed-on: https://chromium-review.googlesource.com/345811
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
src/drivers/bus/i2c/cros_ec_tunnel.c
src/drivers/bus/i2c/cros_ec_tunnel.h

index ce15f52..9643655 100644 (file)
@@ -182,6 +182,48 @@ static int i2c_transfer(I2cOps *me, I2cSeg *segments, int seg_count)
        return 0;
 }
 
+int cros_ec_tunnel_i2c_protect(CrosECTunnelI2c *bus)
+{
+       struct ec_params_i2c_passthru_protect params = {
+               .subcmd = EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE,
+               .port = bus->remote_bus
+       };
+       int result;
+
+       result = ec_command(bus->ec, EC_CMD_I2C_PASSTHRU_PROTECT, 0,
+                           &params, sizeof(params),
+                           NULL, 0);
+
+       if (result < 0)
+               return result;
+
+       return 0;
+}
+
+int cros_ec_tunnel_i2c_protect_status(CrosECTunnelI2c *bus, int *status)
+{
+       struct ec_params_i2c_passthru_protect params = {
+               .subcmd = EC_CMD_I2C_PASSTHRU_PROTECT_STATUS,
+               .port = bus->remote_bus
+       };
+       struct ec_response_i2c_passthru_protect response;
+       int result;
+
+       result = ec_command(bus->ec, EC_CMD_I2C_PASSTHRU_PROTECT, 0,
+                           &params, sizeof(params),
+                           &response, sizeof(response));
+
+       if (result < 0)
+               return result;
+
+       if (result < sizeof(response))
+               return -1;
+
+       *status = response.status;
+
+       return 0;
+}
+
 CrosECTunnelI2c *new_cros_ec_tunnel_i2c(CrosEc *ec,
                                        uint16_t remote_bus) {
        CrosECTunnelI2c *bus = xzalloc(sizeof(*bus));
index b4a58f9..2b1ac5f 100644 (file)
@@ -36,4 +36,12 @@ typedef struct CrosECTunnelI2c {
 CrosECTunnelI2c *new_cros_ec_tunnel_i2c(CrosEc *ec,
                                        uint16_t remote_bus);
 
+/* -----------------------------------------------------------------------
+ * Protect the I2C bus, or query the protection status (exact nature of the
+ * bus protection is board-specific, implemented in EC, ranging from no-op
+ * to blocking all accesses on the given bus).
+ */
+int cros_ec_tunnel_i2c_protect(CrosECTunnelI2c *bus);
+int cros_ec_tunnel_i2c_protect_status(CrosECTunnelI2c *bus, int *status);
+
 #endif