All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 15/55] cros_ec: Support the LDO access method used by spring
Date: Thu,  2 Jul 2015 18:15:52 -0600	[thread overview]
Message-ID: <1435882592-487-16-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1435882592-487-1-git-send-email-sjg@chromium.org>

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       | 13 ++++++++
 drivers/i2c/Makefile      |  1 +
 drivers/i2c/cros_ec_ldo.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/cros_ec.c    | 21 +++++++------
 include/cros_ec.h         |  4 +--
 5 files changed, 104 insertions(+), 12 deletions(-)
 create mode 100644 drivers/i2c/cros_ec_ldo.c

diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index e861b53..9a62ddd 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -29,6 +29,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"
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 7f01fce..9b45248 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -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
index 0000000..b817c61
--- /dev/null
+++ b/drivers/i2c/cros_ec_ldo.c
@@ -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,
+};
diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index ae52561..6027177 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -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 ?
diff --git a/include/cros_ec.h b/include/cros_ec.h
index 41951c3..0ad9d81 100644
--- a/include/cros_ec.h
+++ b/include/cros_ec.h
@@ -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
-- 
2.4.3.573.g4eafbef

  parent reply	other threads:[~2015-07-03  0:15 UTC|newest]

Thread overview: 139+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-03  0:15 [U-Boot] [PATCH 00/55] dm: exynos: Driver model improvements leading to spring support Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 01/55] dm: core: Support finding a device by phandle Simon Glass
2015-07-27 23:28   ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 02/55] dm: i2c: Add a message debug function Simon Glass
2015-07-03  6:52   ` Heiko Schocher denx
2015-07-27 23:28     ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 03/55] dm: i2c: Correct comment nits in dm_i2c_reg_read/write() Simon Glass
2015-07-03  6:53   ` Heiko Schocher denx
2015-07-27 23:28     ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 04/55] dm: i2c: Move definitions to the top of the header file Simon Glass
2015-07-03  6:55   ` Heiko Schocher denx
2015-07-27 23:28     ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 05/55] dm: i2c: Add a function to transfer messages Simon Glass
2015-07-03  6:58   ` Heiko Schocher denx
2015-07-27 23:28     ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 06/55] dm: i2c: Add support for multiplexed I2C buses Simon Glass
2015-07-05  6:10   ` Heiko Schocher
2015-07-06 16:38     ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 07/55] exynos: i2c: Correct bug in pinmux selection Simon Glass
2015-07-05  6:15   ` Heiko Schocher
2015-07-06 15:27     ` Simon Glass
2015-07-07  1:36       ` Minkyu Kang
2015-07-08  2:38         ` Simon Glass
2015-07-10  1:43           ` Minkyu Kang
2015-07-10  1:46             ` Simon Glass
2015-07-10  8:56               ` Przemyslaw Marczak
2015-07-10 12:14               ` Minkyu Kang
2015-07-07  6:51   ` Przemyslaw Marczak
2015-07-03  0:15 ` [U-Boot] [PATCH 08/55] i2c: Add a mux for GPIO-based I2C bus arbitration Simon Glass
2015-07-05  6:43   ` Heiko Schocher
2015-07-06 16:38     ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 09/55] exynos: i2c: Fix code style with ReadWriteByte() Simon Glass
2015-07-05  6:45   ` Heiko Schocher
2015-07-27 23:29     ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 10/55] exynos: i2c: Tidy up the driver model code Simon Glass
2015-07-06  5:40   ` Heiko Schocher
2015-07-27 23:28     ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 11/55] exynos: dts: Sync up I2C ports with the kernel Simon Glass
2015-07-10 11:51   ` Przemyslaw Marczak
2015-07-27 23:29     ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 12/55] exynos: dts: Add PMIC and regulator definitions Simon Glass
2015-07-10 11:51   ` Przemyslaw Marczak
2015-07-27 23:29     ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 13/55] exynos: dts: Support EC tunnel and main TPS65090 regulator Simon Glass
2015-07-27 23:29   ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 14/55] dm: cros_ec: Convert the I2C tunnel code to use driver model Simon Glass
2015-07-03  0:15 ` Simon Glass [this message]
2015-07-03  0:15 ` [U-Boot] [PATCH 16/55] exynos: serial: Refactor init code for debug UART Simon Glass
2015-07-27 23:29   ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 17/55] exynos: Add debug UART support for Samsung S5P serial Simon Glass
2015-07-27 23:29   ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 18/55] exynos: Enable the debug UART in SPL Simon Glass
2015-07-27 23:30   ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 19/55] dm: gpio: Add support for setting a GPIO's pull direction Simon Glass
2015-07-05  4:55   ` Masahiro Yamada
2015-07-06 16:39     ` Simon Glass
2015-07-06 17:20       ` Masahiro Yamada
2015-07-06 17:33         ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 20/55] dm: exynos: gpio: Support pull-up/down in GPIOs Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 21/55] dm: power: Add a new driver for the TPS65090 PMIC Simon Glass
2015-07-10 11:52   ` Przemyslaw Marczak
2015-07-27 23:30     ` Simon Glass
2015-07-03  0:15 ` [U-Boot] [PATCH 22/55] dm: power: Add support for TPS65090 FETs Simon Glass
2015-07-10 11:52   ` Przemyslaw Marczak
2015-07-27 23:30     ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 23/55] dm: power: Add support for the S5M8767 PMIC Simon Glass
2015-07-10 11:52   ` Przemyslaw Marczak
2015-07-27 23:30     ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 24/55] dm: power: Add support for S5M8767 regulators Simon Glass
2015-07-10 11:52   ` Przemyslaw Marczak
2015-07-27 23:30     ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 25/55] dm: pmic: max77686: Correct a few nits Simon Glass
2015-07-10 11:53   ` Przemyslaw Marczak
2015-07-27 23:30     ` Simon Glass
2015-07-28  6:19       ` Przemyslaw Marczak
2015-08-03 14:02         ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 26/55] dm: pmic: Correct the pmic_reg_write() implementation Simon Glass
2015-07-10 11:53   ` Przemyslaw Marczak
2015-07-27 23:30     ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 27/55] dm: power: max77686: Correct BUCK register access Simon Glass
2015-07-10 11:53   ` Przemyslaw Marczak
2015-07-27 23:30     ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 28/55] dm: pmic: max77686: Support all BUCK regulators Simon Glass
2015-07-10 11:53   ` Przemyslaw Marczak
2015-07-30  2:05     ` Simon Glass
2015-07-30  8:22       ` Przemyslaw Marczak
2015-08-03 14:05         ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 29/55] dm: power: Don't return an error when regulators are not autoset Simon Glass
2015-07-10 11:54   ` Przemyslaw Marczak
2015-07-27 23:30     ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 30/55] dm: pmic: Display the regulator limits on error Simon Glass
2015-07-10 11:54   ` Przemyslaw Marczak
2015-07-27 23:30     ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 31/55] dm: video: Add support for video bridges Simon Glass
2015-07-27 23:30   ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 32/55] dm: video: Add support for the Parade PS8622/625 bridge Simon Glass
2015-07-27 23:30   ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 33/55] dm: video: Add support for the NXP PTN3460 bridge Simon Glass
2015-07-27 23:30   ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 34/55] exynos: spi: Convert the timeout to debug() Simon Glass
2015-07-27 23:30   ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 35/55] exynos: Correct return value in exynos_mmc_init() Simon Glass
2015-07-27 23:31   ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 36/55] exynos: Add support for the DisplayPort hotplug detect Simon Glass
2015-07-27 23:31   ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 37/55] exynos: video: Correct debug output Simon Glass
2015-07-27 23:31   ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 38/55] exynos: Tidy up CPU frequency display Simon Glass
2015-07-27 23:31   ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 39/55] dm: gpio: Check a GPIO is valid before using it Simon Glass
2015-07-27 23:31   ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 40/55] dts: exynos: snow: Add memory layout description Simon Glass
2015-07-27 23:31   ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 41/55] dts: exynos: pit: Add a new node for the parade video bridge driver Simon Glass
2015-07-27 23:31   ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 42/55] dts: exynos: snow: Add a new node for the NXP " Simon Glass
2015-07-27 23:31   ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 43/55] exynos: dts: Drop the old TPS65090 I2C node Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 44/55] exynos: Add common board code for exynos5 boards that use device tree Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 45/55] exynos: Enable new features for exynos5 boards Simon Glass
2015-07-10 11:55   ` Przemyslaw Marczak
2015-07-28 16:29     ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 46/55] exynos: Remove unneeded device tree control #ifdefs Simon Glass
2015-07-27 23:31   ` Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 47/55] exynos: config: Move common options to the common headers and tidy up Simon Glass
2015-07-10 11:56   ` Przemyslaw Marczak
2015-07-03  0:16 ` [U-Boot] [PATCH 48/55] exynos: Drop old exynos5420-specific board code Simon Glass
2015-07-10 11:56   ` Przemyslaw Marczak
2015-07-03  0:16 ` [U-Boot] [PATCH 49/55] exynos: Drop old exynos5250-specific " Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 50/55] power: Remove old TPS65090 drivers Simon Glass
2015-07-10 11:56   ` Przemyslaw Marczak
2015-07-03  0:16 ` [U-Boot] [PATCH 51/55] cros_ec: Remove the old tunnel code Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 52/55] video: Remove the old parade driver Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 53/55] dts: Drop unused compatible ID for the NXP video bridge Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 54/55] exynos: video: Remove non-device-tree code Simon Glass
2015-07-03  0:16 ` [U-Boot] [PATCH 55/55] exynos: Add support for spring Simon Glass
2015-07-20 14:19 ` [U-Boot] [PATCH 00/55] dm: exynos: Driver model improvements leading to spring support Simon Glass
2015-07-22  4:52   ` Minkyu Kang
2015-07-23  2:08     ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435882592-487-16-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.