From patchwork Mon Nov 24 16:00:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Popov X-Patchwork-Id: 414023 X-Patchwork-Delegate: hs@denx.de 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 8E1D71400EA for ; Tue, 25 Nov 2014 03:00:52 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CCE3C4B60B; Mon, 24 Nov 2014 17:00:50 +0100 (CET) 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 O73xMNIxnrOr; Mon, 24 Nov 2014 17:00:50 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 36E234B604; Mon, 24 Nov 2014 17:00:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F0B564B604 for ; Mon, 24 Nov 2014 17:00:45 +0100 (CET) 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 x0UqM-+AEJMp for ; Mon, 24 Nov 2014 17:00:45 +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 extserv.mm-sol.com (ns.mm-sol.com [37.157.136.199]) by theia.denx.de (Postfix) with ESMTPS id C58F94B5FD for ; Mon, 24 Nov 2014 17:00:41 +0100 (CET) Received: by extserv.mm-sol.com (Postfix, from userid 33) id 8B51ABF1B; Mon, 24 Nov 2014 18:00:39 +0200 (EET) Received: from 192.91.75.29 (SquirrelMail authenticated user lpopov) by www.mm-sol.com with HTTP; Mon, 24 Nov 2014 18:00:39 +0200 Message-ID: Date: Mon, 24 Nov 2014 18:00:39 +0200 From: "Lubomir Popov" To: u-boot@lists.denx.de User-Agent: SquirrelMail/1.4.23 [SVN] MIME-Version: 1.0 X-Priority: 3 (Normal) Importance: Normal Subject: [U-Boot] [PATCH] cmd_i2c: Provide option for bulk 'i2c write' in one transaction X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list Reply-To: lpopov@mm-sol.com List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de I2C chips do exist that require a write of some multi-byte data to occur in a single bus transaction (aka atomic transfer), otherwise either the write does not come into effect at all, or normal operation of internal circuitry cannot be guaranteed. The current implementation of the 'i2c write' command (transfer of multiple bytes from a memory buffer) in fact performs a separate transaction for each byte to be written and thus cannot support such types of I2C slave devices. This patch provides an alternative by allowing 'i2c write' to execute the write transfer of the given number of bytes in a single bus transaction if CONFIG_SYS_I2C_BULK_WRITE is defined in the board header (otherwise the old method shall compile). Signed-off-by: Lubomir Popov --- common/cmd_i2c.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c index 3a75f94..7116458 100644 --- a/common/cmd_i2c.c +++ b/common/cmd_i2c.c @@ -280,10 +280,22 @@ static int do_i2c_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ return cmd_usage(cmdtp); /* - * Length is the number of objects, not number of bytes. + * Length is the number of bytes. */ length = simple_strtoul(argv[4], NULL, 16); +#if defined(CONFIG_SYS_I2C_BULK_WRITE) + /* + * Write all bytes in a single I2C transaction. If the target + * device is an EEPROM, it is your responsibility to not cross + * a page bounady. + */ + if (i2c_write(chip, devaddr, alen, memaddr, length) != 0) { + puts("Error writing to the chip.\n"); + return 1; + } +#else + /* Perform separate write transactions of one byte each */ while (length-- > 0) { if (i2c_write(chip, devaddr++, alen, memaddr++, 1) != 0) { puts("Error writing to the chip.\n"); @@ -296,6 +308,7 @@ static int do_i2c_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[ udelay(11000); #endif } +#endif return 0; }