From patchwork Thu Feb 27 20:26:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 324914 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 1AFAC2C0096 for ; Fri, 28 Feb 2014 07:29:52 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7D2504B5BB; Thu, 27 Feb 2014 21:29:46 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 0HmHCPp6uq-P; Thu, 27 Feb 2014 21:29:46 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 115A04B61A; Thu, 27 Feb 2014 21:28:35 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 12ED54B4E9 for ; Thu, 27 Feb 2014 21:28:28 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 1SaZIoVLI++l for ; Thu, 27 Feb 2014 21:28:22 +0100 (CET) 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-ob0-f202.google.com (mail-ob0-f202.google.com [209.85.214.202]) by theia.denx.de (Postfix) with ESMTPS id 6FE264B372 for ; Thu, 27 Feb 2014 21:28:15 +0100 (CET) Received: by mail-ob0-f202.google.com with SMTP id wo20so133965obc.1 for ; Thu, 27 Feb 2014 12:28:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/YewGPpI6U6mTklTQaeMUtCWoKYMMTcq23Nzcwd4QOs=; b=A3twgnW0pEdYdfh86fSacpkR7K3U+P16iu/tDf1+pbweo9ngzCpgNS68K63zg9JXnz tIZv4ymnDPsT1IHyq8ODyi6Bgw5KMYYbh1wSovN/ZAR8b3BXOee8CqqDFU+aksj2FZa0 lK+veg3pohpCMR4JrZXNQlfVW+9F5O58TsvbyqCKUxIUKo3yFJyMRgADHSaFeK1mU+MM 6KZJWzqlRuMd//aZWUVyyFc5Gj65FpyCIz1zsArMC91PC9AcZQmz2Yj22udLgNvr3RHx ijK4z8/Y1M4HsOmZOqY1G9jqodtNOCtSO3RCCEhLvuHV1rSFzr2fsbjq+8EQ7esveSSw SSVA== X-Gm-Message-State: ALoCoQmRrDa6EsvsD8MJ4xMOLIVr0RIANI2jGcfIanu/23B4GTRW5B2TG92QiiAkKY5+zgnWu/UH0EdCeGxoCt/ibbq8aYRIzPtzbrZjri9VBFUEqiynn5HLWgSd5ipkm2huOS0EBEP0tutvRErIWne1hWSHoDRRZw6SOMgEIMwD8okAsbAsy8YPBbNOVvl+ODQHpsCcaFdI X-Received: by 10.182.95.68 with SMTP id di4mr5067291obb.4.1393532894612; Thu, 27 Feb 2014 12:28:14 -0800 (PST) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id x29si952722yha.0.2014.02.27.12.28.14 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Feb 2014 12:28:14 -0800 (PST) Received: from kaki.bld.corp.google.com (kaki.bld.corp.google.com [172.29.216.32]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 713B231C1CD; Thu, 27 Feb 2014 12:28:14 -0800 (PST) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 2FAB42217C6; Thu, 27 Feb 2014 13:28:14 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 27 Feb 2014 13:26:08 -0700 Message-Id: <1393532785-9020-15-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.9.0.279.gdc9e3eb In-Reply-To: <1393532785-9020-1-git-send-email-sjg@chromium.org> References: <1393532785-9020-1-git-send-email-sjg@chromium.org> Cc: Randall Spangler , u-boot-review@google.com Subject: [U-Boot] [PATCH v2 14/31] cros_ec: Clean up multiple EC protocol support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Randall Spangler Version 1 protocols (without command version) were already no longer supported in cros_ec.c. This removes some dead code from the cros_ec_i2c driver. Version 2 protcols (with command version) are now called protocol_version=2, instead of cmd_version_is_supported=1. A subsequent change will introduce protocol version 3 for SPI. Reviewed-by: Simon Glass Signed-off-by: Randall Spangler Signed-off-by: Simon Glass --- Changes in v2: None drivers/misc/cros_ec.c | 21 +++++++++------ drivers/misc/cros_ec_i2c.c | 64 ++++++++++++++++++++-------------------------- drivers/misc/cros_ec_spi.c | 6 +++++ include/cros_ec.h | 5 ++-- 4 files changed, 49 insertions(+), 47 deletions(-) diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index ff46762..33b9390 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -501,18 +501,23 @@ static int cros_ec_check_version(struct cros_ec_dev *dev) * * So for now, just read all the data anyway. */ - dev->cmd_version_is_supported = 1; + + /* Try sending a version 2 packet */ + dev->protocol_version = 2; if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req), (uint8_t **)&resp, sizeof(*resp)) > 0) { - /* It appears to understand new version commands */ - dev->cmd_version_is_supported = 1; - } else { - printf("%s: ERROR: old EC interface not supported\n", - __func__); - return -1; + return 0; } - return 0; + /* + * Fail if we're still here, since the EC doesn't understand any + * protcol version we speak. Version 1 interface without command + * version is no longer supported, and we don't know about any new + * protocol versions. + */ + dev->protocol_version = 0; + printf("%s: ERROR: old EC interface not supported\n", __func__); + return -1; } int cros_ec_test(struct cros_ec_dev *dev) diff --git a/drivers/misc/cros_ec_i2c.c b/drivers/misc/cros_ec_i2c.c index 0fbab99..513cdb1 100644 --- a/drivers/misc/cros_ec_i2c.c +++ b/drivers/misc/cros_ec_i2c.c @@ -35,7 +35,7 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, uint8_t *ptr; /* Receive input data, so that args will be dword aligned */ uint8_t *in_ptr; - int ret; + int len, csum, ret; old_bus = i2c_get_bus_num(); @@ -67,24 +67,24 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, * will be dword aligned. */ in_ptr = dev->din + sizeof(int64_t); - if (!dev->cmd_version_is_supported) { - /* Send an old-style command */ - *ptr++ = cmd; - out_bytes = dout_len + 1; - in_bytes = din_len + 2; - in_ptr--; /* Expect just a status byte */ - } else { - *ptr++ = EC_CMD_VERSION0 + cmd_version; - *ptr++ = cmd; - *ptr++ = dout_len; - in_ptr -= 2; /* Expect status, length bytes */ + + if (dev->protocol_version != 2) { + /* Something we don't support */ + debug("%s: Protocol version %d unsupported\n", + __func__, dev->protocol_version); + return -1; } + + *ptr++ = EC_CMD_VERSION0 + cmd_version; + *ptr++ = cmd; + *ptr++ = dout_len; + in_ptr -= 2; /* Expect status, length bytes */ + memcpy(ptr, dout, dout_len); ptr += dout_len; - if (dev->cmd_version_is_supported) - *ptr++ = (uint8_t) - cros_ec_calc_checksum(dev->dout, dout_len + 3); + *ptr++ = (uint8_t) + cros_ec_calc_checksum(dev->dout, dout_len + 3); /* Set to the proper i2c bus */ if (i2c_set_bus_num(dev->bus_num)) { @@ -121,26 +121,20 @@ int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, return -(int)*in_ptr; } - if (dev->cmd_version_is_supported) { - int len, csum; - - len = in_ptr[1]; - if (len + 3 > sizeof(dev->din)) { - debug("%s: Received length %#02x too large\n", - __func__, len); - return -1; - } - csum = cros_ec_calc_checksum(in_ptr, 2 + len); - if (csum != in_ptr[2 + len]) { - debug("%s: Invalid checksum rx %#02x, calced %#02x\n", - __func__, in_ptr[2 + din_len], csum); - return -1; - } - din_len = min(din_len, len); - cros_ec_dump_data("in", -1, in_ptr, din_len + 3); - } else { - cros_ec_dump_data("in (old)", -1, in_ptr, in_bytes); + len = in_ptr[1]; + if (len + 3 > sizeof(dev->din)) { + debug("%s: Received length %#02x too large\n", + __func__, len); + return -1; } + csum = cros_ec_calc_checksum(in_ptr, 2 + len); + if (csum != in_ptr[2 + len]) { + debug("%s: Invalid checksum rx %#02x, calced %#02x\n", + __func__, in_ptr[2 + din_len], csum); + return -1; + } + din_len = min(din_len, len); + cros_ec_dump_data("in", -1, in_ptr, din_len + 3); /* Return pointer to dword-aligned input data, if any */ *dinp = dev->din + sizeof(int64_t); @@ -178,7 +172,5 @@ int cros_ec_i2c_init(struct cros_ec_dev *dev, const void *blob) { i2c_init(dev->max_frequency, dev->addr); - dev->cmd_version_is_supported = 0; - return 0; } diff --git a/drivers/misc/cros_ec_spi.c b/drivers/misc/cros_ec_spi.c index 2fc9110..ef73782 100644 --- a/drivers/misc/cros_ec_spi.c +++ b/drivers/misc/cros_ec_spi.c @@ -42,6 +42,12 @@ int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, int csum, len; int rv; + if (dev->protocol_version != 2) { + debug("%s: Unsupported EC protcol version %d\n", + __func__, dev->protocol_version); + return -1; + } + /* * Sanity-check input size to make sure it plus transaction overhead * fits in the internal device buffer. diff --git a/include/cros_ec.h b/include/cros_ec.h index 3166132..1199d92 100644 --- a/include/cros_ec.h +++ b/include/cros_ec.h @@ -33,7 +33,7 @@ struct cros_ec_dev { unsigned int bus_num; /* Bus number (for I2C) */ unsigned int max_frequency; /* Maximum interface frequency */ struct fdt_gpio_state ec_int; /* GPIO used as EC interrupt line */ - int cmd_version_is_supported; /* Device supports command versions */ + int protocol_version; /* Protocol version to use */ int optimise_flash_write; /* Don't write erased flash blocks */ /* @@ -260,8 +260,7 @@ int cros_ec_spi_decode_fdt(struct cros_ec_dev *dev, const void *blob); * Check whether the LPC interface supports new-style commands. * * LPC has its own way of doing this, which involves checking LPC values - * visible to the host. Do this, and update dev->cmd_version_is_supported - * accordingly. + * visible to the host. Do this, and update dev->protocol_version accordingly. * * @param dev CROS-EC device to check */