]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
cros_ec: Support the LDO access method used by spring
authorSimon Glass <sjg@chromium.org>
Mon, 3 Aug 2015 14:19:24 +0000 (08:19 -0600)
committerLothar Waßmann <LW@KARO-electronics.de>
Thu, 10 Sep 2015 06:17:14 +0000 (08:17 +0200)
Add a driver to support the special LDO access used by spring. This is a
custom method in the cros_ec protocol - it does not use an I2C
pass-through.

There are two implementation choices:

1. Write a special LDO driver which can talk across the EC. Duplicate all
the logic from TPS65090 for retrying when the LDO fails to come up.

2. Write a special I2C bus driver which pretends to be a TPS65090 and
transfers reads and writes using the LDO message.

Either is distasteful. The latter method is chosen since it results in less
code duplication and a fairly simple (30-line) implementation of the core
logic.

The crosec 'ldo' subcommand could be removed (since i2c md/mw will work
instead) but is retained as a convenience.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/i2c/Kconfig
drivers/i2c/Makefile
drivers/i2c/cros_ec_ldo.c [new file with mode: 0644]
drivers/misc/cros_ec.c
include/cros_ec.h

index 766a67dd226f7a01ecb48b0b364baba152eb236c..4c8ea477a825c5e6a3f35dc0246dc43ff53dad6b 100644 (file)
@@ -42,6 +42,19 @@ config I2C_CROS_EC_TUNNEL
          I2C or LPC). Some Chromebooks use this when the hardware design
          does not allow direct access to the main PMIC from the AP.
 
+config I2C_CROS_EC_LDO
+       bool "Provide access to LDOs on the Chrome OS EC"
+       depends on CROS_EC
+       ---help---
+       On many Chromebooks the main PMIC is inaccessible to the AP. This is
+       often dealt with by using an I2C pass-through interface provided by
+       the EC. On some unfortunate models (e.g. Spring) the pass-through
+       is not available, and an LDO message is available instead. This
+       option enables a driver which provides very basic access to those
+       regulators, via the EC. We implement this as an I2C bus which
+       emulates just the TPS65090 messages we know about. This is done to
+       avoid duplicating the logic in the TPS65090 regulator driver for
+       enabling/disabling an LDO.
 
 config DM_I2C_GPIO
        bool "Enable Driver Model for software emulated I2C bus driver"
index 7f01fce2e745d757d2fcb656ef883874f9f88c7c..9b45248e2e271bcf3387d61d4e75cb3bcf57bb39 100644 (file)
@@ -8,6 +8,7 @@ obj-$(CONFIG_DM_I2C) += i2c-uclass.o
 obj-$(CONFIG_DM_I2C_COMPAT) += i2c-uclass-compat.o
 obj-$(CONFIG_DM_I2C_GPIO) += i2c-gpio.o
 obj-$(CONFIG_I2C_CROS_EC_TUNNEL) += cros_ec_tunnel.o
+obj-$(CONFIG_I2C_CROS_EC_LDO) += cros_ec_ldo.o
 
 obj-$(CONFIG_SYS_I2C_ADI) += adi_i2c.o
 obj-$(CONFIG_I2C_MV) += mv_i2c.o
diff --git a/drivers/i2c/cros_ec_ldo.c b/drivers/i2c/cros_ec_ldo.c
new file mode 100644 (file)
index 0000000..b817c61
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <cros_ec.h>
+#include <errno.h>
+#include <i2c.h>
+#include <power/tps65090.h>
+
+static int cros_ec_ldo_set_bus_speed(struct udevice *dev, unsigned int speed)
+{
+       return 0;
+}
+
+static int cros_ec_ldo_xfer(struct udevice *dev, struct i2c_msg *msg,
+                           int nmsgs)
+{
+       bool is_read = nmsgs > 1;
+       int fet_id, ret;
+
+       /*
+        * Look for reads and writes of the LDO registers. In either case the
+        * first message is a write with the register number as the first byte.
+        */
+       if (!nmsgs || !msg->len || (msg->flags & I2C_M_RD)) {
+               debug("%s: Invalid message\n", __func__);
+               goto err;
+       }
+
+       fet_id = msg->buf[0] - REG_FET_BASE;
+       if (fet_id < 1 || fet_id > MAX_FET_NUM) {
+               debug("%s: Invalid FET %d\n", __func__, fet_id);
+               goto err;
+       }
+
+       if (is_read) {
+               uint8_t state;
+
+               ret = cros_ec_get_ldo(dev->parent, fet_id, &state);
+               if (!ret)
+                       msg[1].buf[0] = state ?
+                               FET_CTRL_ENFET | FET_CTRL_PGFET : 0;
+       } else {
+               bool on = msg->buf[1] & FET_CTRL_ENFET;
+
+               ret = cros_ec_set_ldo(dev->parent, fet_id, on);
+       }
+
+       return ret;
+
+err:
+       /* Indicate that the message is unimplemented */
+       return -ENOSYS;
+}
+
+static const struct dm_i2c_ops cros_ec_i2c_ops = {
+       .xfer           = cros_ec_ldo_xfer,
+       .set_bus_speed  = cros_ec_ldo_set_bus_speed,
+};
+
+static const struct udevice_id cros_ec_i2c_ids[] = {
+       { .compatible = "google,cros-ec-ldo-tunnel" },
+       { }
+};
+
+U_BOOT_DRIVER(cros_ec_ldo) = {
+       .name   = "cros_ec_ldo_tunnel",
+       .id     = UCLASS_I2C,
+       .of_match = cros_ec_i2c_ids,
+       .per_child_auto_alloc_size = sizeof(struct dm_i2c_chip),
+       .ops    = &cros_ec_i2c_ops,
+};
index ae525616095ad69ff3add4e89a20f9b0d4c179ab..6027177d5d2363b8312af277928313595d3252dc 100644 (file)
@@ -931,31 +931,32 @@ int cros_ec_write_vbnvcontext(struct cros_ec_dev *dev, const uint8_t *block)
        return 0;
 }
 
-int cros_ec_set_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t state)
+int cros_ec_set_ldo(struct udevice *dev, uint8_t index, uint8_t state)
 {
+       struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
        struct ec_params_ldo_set params;
 
        params.index = index;
        params.state = state;
 
-       if (ec_command_inptr(dev, EC_CMD_LDO_SET, 0,
-                      &params, sizeof(params),
-                      NULL, 0))
+       if (ec_command_inptr(cdev, EC_CMD_LDO_SET, 0, &params, sizeof(params),
+                            NULL, 0))
                return -1;
 
        return 0;
 }
 
-int cros_ec_get_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t *state)
+int cros_ec_get_ldo(struct udevice *dev, uint8_t index, uint8_t *state)
 {
+       struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
        struct ec_params_ldo_get params;
        struct ec_response_ldo_get *resp;
 
        params.index = index;
 
-       if (ec_command_inptr(dev, EC_CMD_LDO_GET, 0,
-                      &params, sizeof(params),
-                      (uint8_t **)&resp, sizeof(*resp)) != sizeof(*resp))
+       if (ec_command_inptr(cdev, EC_CMD_LDO_GET, 0, &params, sizeof(params),
+                            (uint8_t **)&resp, sizeof(*resp)) !=
+                            sizeof(*resp))
                return -1;
 
        *state = resp->state;
@@ -1681,9 +1682,9 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                        state = simple_strtoul(argv[3], &endp, 10);
                        if (*argv[3] == 0 || *endp != 0)
                                return CMD_RET_USAGE;
-                       ret = cros_ec_set_ldo(dev, index, state);
+                       ret = cros_ec_set_ldo(udev, index, state);
                } else {
-                       ret = cros_ec_get_ldo(dev, index, &state);
+                       ret = cros_ec_get_ldo(udev, index, &state);
                        if (!ret) {
                                printf("LDO%d: %s\n", index,
                                        state == EC_LDO_STATE_ON ?
index 41951c39b65785969079d1c16c4cd884aed95d69..0ad9d81243e08dee6b5d59ded615ce5071e871b1 100644 (file)
@@ -350,7 +350,7 @@ int cros_ec_read_build_info(struct cros_ec_dev *dev, char **strp);
  * @param state                new state of the LDO/FET : EC_LDO_STATE_ON|OFF
  * @return 0 if ok, -1 on error
  */
-int cros_ec_set_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t state);
+int cros_ec_set_ldo(struct udevice *dev, uint8_t index, uint8_t state);
 
 /**
  * Read back a LDO / FET current state.
@@ -360,7 +360,7 @@ int cros_ec_set_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t state);
  * @param state                current state of the LDO/FET : EC_LDO_STATE_ON|OFF
  * @return 0 if ok, -1 on error
  */
-int cros_ec_get_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t *state);
+int cros_ec_get_ldo(struct udevice *dev, uint8_t index, uint8_t *state);
 
 /**
  * Get access to the error reported when cros_ec_board_init() was called