From patchwork Mon Aug 3 14:19:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 503174 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 8EF9F140E3F for ; Tue, 4 Aug 2015 00:21:05 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=ljgc/wng; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2477BA749C; Mon, 3 Aug 2015 16:20:44 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LHDjOMx9egjY; Mon, 3 Aug 2015 16:20:44 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 42BD5A7471; Mon, 3 Aug 2015 16:20:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 144FD4BF03 for ; Mon, 3 Aug 2015 16:19:59 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FG9Z4Qmm2ojb for ; Mon, 3 Aug 2015 16:19:58 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ig0-f172.google.com (mail-ig0-f172.google.com [209.85.213.172]) by theia.denx.de (Postfix) with ESMTPS id 086A1A7461 for ; Mon, 3 Aug 2015 16:19:53 +0200 (CEST) Received: by igk11 with SMTP id 11so72666399igk.1 for ; Mon, 03 Aug 2015 07:19:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=hZrt3T5bvigcQju6BMIg6NiChiufrWTjwzXXHZernHE=; b=ljgc/wngQXWrwIZOTTJBhY5ghcRg2R3gWpgVlHSqTGiZBkUsv2G9VwocYK48Wm0RFs USVxwqAcJZ8VmxquMtS08bvcXbpXFzkmsztpBq0G67CaxUftAUDSo70AK2IO6oRQXQRe Z0VllD3rT6wyVvQMLemyi86kjxx/qlmI/yn+aUWQ90y5vJO4dbIYTvHSb0Ak7gV5LWX0 3yidN31wXSyBiMy/Uu5g9QkMDdA5KfcZ8y5x+0zaXspkld2vPgzMv616Of2vt2vhaxk1 E74QWMoQXs6cmQtt+AXMupnFEs6pttkQ4phQq9GqbcBmkzR5DLi/v/nHsQAxNY/uAsIh sP4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=hZrt3T5bvigcQju6BMIg6NiChiufrWTjwzXXHZernHE=; b=EorZTP20sVnCmSPAbfBzTMpoyW4PaJuAmeczRRF4i+EBxV82wop7Sv/WMrRpmyzF5G iBYLJPBT8YxaneDNBMeAiLwFYXk48ito0hZCN3NdMhbf5cc3DuX5PXpHLLYBU6YPZoD4 q7+/h5w4PNfYmpe/oPUPG59G4XRpMUPtUCLGm6q1QrPYzd7xxUcxFqp3mLyWn01oHALe Mea/H/EgWJCDHDYm6+c+mHF9o660cw8V+dtgkdDKhz9WySs4bGpK/4XbwURl/VkBzXB+ z2XfDaa7QRec2hcfsb6HbQ0EqC+DmAI9ry5EEkptBP3kKoK8JMI9P2bzlL9X5q0uBMJr YK5A== X-Gm-Message-State: ALoCoQnpr19+xu40mJkFc195G37zK35dx+sfFclZvcRauN6WnodoUBRlILt1xxHGUsGSthBwVrrT X-Received: by 10.50.23.38 with SMTP id j6mr22084240igf.84.1438611592223; Mon, 03 Aug 2015 07:19:52 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by smtp.gmail.com with ESMTPSA id uw5sm5802467igb.21.2015.08.03.07.19.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Aug 2015 07:19:50 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 21CB02220FB; Mon, 3 Aug 2015 08:19:47 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 3 Aug 2015 08:19:24 -0600 Message-Id: <1438611577-2245-7-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.5.0.rc2.392.g76e840b In-Reply-To: <1438611577-2245-1-git-send-email-sjg@chromium.org> References: <1438611577-2245-1-git-send-email-sjg@chromium.org> Subject: [U-Boot] [PATCH v2 06/19] cros_ec: Support the LDO access method used by spring X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- Changes in v2: None 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 + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include + +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, - ¶ms, sizeof(params), - NULL, 0)) + if (ec_command_inptr(cdev, EC_CMD_LDO_SET, 0, ¶ms, 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, - ¶ms, sizeof(params), - (uint8_t **)&resp, sizeof(*resp)) != sizeof(*resp)) + if (ec_command_inptr(cdev, EC_CMD_LDO_GET, 0, ¶ms, 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