From patchwork Tue Nov 10 19:53:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 542572 X-Patchwork-Delegate: trini@ti.com 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 0A9BB141430 for ; Wed, 11 Nov 2015 06:54:18 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0A2244B89C; Tue, 10 Nov 2015 20:54:13 +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 n_JAw4gEdNWf; Tue, 10 Nov 2015 20:54:12 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CEE714B86F; Tue, 10 Nov 2015 20:54:02 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8EE5B4B76D for ; Tue, 10 Nov 2015 20:53:54 +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 ojQYHIQt1ONe for ; Tue, 10 Nov 2015 20:53:54 +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-out.m-online.net (mail-out.m-online.net [212.18.0.10]) by theia.denx.de (Postfix) with ESMTPS id 5F5964B83C for ; Tue, 10 Nov 2015 20:53:54 +0100 (CET) Received: from mail.nefkom.net (unknown [192.168.8.184]) by mail-out.m-online.net (Postfix) with ESMTP id 3nwKdD2dvJz3hjLp; Tue, 10 Nov 2015 20:53:52 +0100 (CET) X-Auth-Info: 7TL58u+oGb0N/xeiMT6mVOBQSMi3bh8+qTvBTcYhMfI= Received: from chi.lan (unknown [195.140.253.167]) by smtp-auth.mnet-online.de (Postfix) with ESMTPA id 3nwKdD0NMQzvdWS; Tue, 10 Nov 2015 20:53:52 +0100 (CET) From: Marek Vasut To: u-boot@lists.denx.de Date: Tue, 10 Nov 2015 20:53:24 +0100 Message-Id: <1447185213-5799-8-git-send-email-marex@denx.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1447185213-5799-1-git-send-email-marex@denx.de> References: <1447185213-5799-1-git-send-email-marex@denx.de> Cc: Marek Vasut , Tom Rini Subject: [U-Boot] [PATCH 08/17] eeprom: Pull out address computation 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" Pull out the code computing the EEPROM address into separate function so that it's not duplicated. Signed-off-by: Marek Vasut Cc: Simon Glass Cc: Tom Rini Cc: Heiko Schocher Reviewed-by: Heiko Schocher --- common/cmd_eeprom.c | 64 ++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/common/cmd_eeprom.c b/common/cmd_eeprom.c index 7797d0e..5979993 100644 --- a/common/cmd_eeprom.c +++ b/common/cmd_eeprom.c @@ -61,6 +61,28 @@ void eeprom_init(void) #endif } +static int eeprom_addr(unsigned dev_addr, unsigned offset, uchar *addr) +{ + unsigned blk_off; + int alen; + + blk_off = offset & 0xff; /* block offset */ +#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 + addr[0] = offset >> 8; /* block number */ + addr[1] = blk_off; /* block offset */ + alen = 2; +#else + addr[0] = offset >> 16; /* block number */ + addr[1] = offset >> 8; /* upper address octet */ + addr[2] = blk_off; /* lower address octet */ + alen = 3; +#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */ + + addr[0] |= dev_addr; /* insert device address */ + + return alen; +} + static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen, uchar *buffer, unsigned len, bool read) { @@ -94,6 +116,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt unsigned end = offset + cnt; unsigned blk_off; int rcode = 0; + uchar addr[3]; /* * Read data until done or would cross a page boundary. @@ -106,26 +129,8 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt unsigned maxlen; #endif -#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 - uchar addr[2]; - - blk_off = offset & 0xFF; /* block offset */ - - addr[0] = offset >> 8; /* block number */ - addr[1] = blk_off; /* block offset */ - alen = 2; -#else - uchar addr[3]; - blk_off = offset & 0xFF; /* block offset */ - - addr[0] = offset >> 16; /* block number */ - addr[1] = offset >> 8; /* upper address octet */ - addr[2] = blk_off; /* lower address octet */ - alen = 3; -#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */ - - addr[0] |= dev_addr; /* insert device address */ + alen = eeprom_addr(dev_addr, offset, addr); len = end - offset; @@ -156,6 +161,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn unsigned end = offset + cnt; unsigned blk_off; int rcode = 0; + uchar addr[3]; #if defined(CONFIG_SYS_EEPROM_WREN) eeprom_write_enable (dev_addr,1); @@ -172,26 +178,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn unsigned maxlen; #endif -#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 - uchar addr[2]; - blk_off = offset & 0xFF; /* block offset */ - - addr[0] = offset >> 8; /* block number */ - addr[1] = blk_off; /* block offset */ - alen = 2; -#else - uchar addr[3]; - - blk_off = offset & 0xFF; /* block offset */ - - addr[0] = offset >> 16; /* block number */ - addr[1] = offset >> 8; /* upper address octet */ - addr[2] = blk_off; /* lower address octet */ - alen = 3; -#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */ - - addr[0] |= dev_addr; /* insert device address */ + alen = eeprom_addr(dev_addr, offset, addr); len = end - offset;