From patchwork Thu Nov 28 02:47:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuo-Jung Su X-Patchwork-Id: 294732 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 7D3FF2C00A0 for ; Thu, 28 Nov 2013 13:48:41 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 463454B935; Thu, 28 Nov 2013 03:48:40 +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 1PR8qmI-gMEs; Thu, 28 Nov 2013 03:48:40 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 551F04B963; Thu, 28 Nov 2013 03:48:32 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 443D84B939 for ; Thu, 28 Nov 2013 03:48:26 +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 p4IxuRi6nuLm for ; Thu, 28 Nov 2013 03:48:21 +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-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53]) by theia.denx.de (Postfix) with ESMTPS id 22B604B953 for ; Thu, 28 Nov 2013 03:48:10 +0100 (CET) Received: by mail-pb0-f53.google.com with SMTP id ma3so11560854pbc.26 for ; Wed, 27 Nov 2013 18:48:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=U/rT0LcS8JfXj9+/IdtkXEy2jahN4/pSs9ERUuOQoBI=; b=WPypjvEzslrEqMavn/gYwdH7Nwgzl4toFAxyyipgqDW1OLuSJVkGldYfsWw9gWNqN4 59AJc6/vKwZRqsXhUVk3l09s51hxZtMH+At7RB42tgreVh8myrbcQDPDO5+o9X+6+4jW 9cv3RqvbQVOlFh/ZE75RktKR8p8wzSCSt+B5xeIbWE14K/g/x9YX31qrblCu1v1cINx1 L0MJr8n/2bhZA1HTRHZVxcEC0/5L9vogxnzsiCZ79MHK7TQa4hD2RZjlyP3AdvIxjoU4 JRQNRDaeSYGyZXaRG8CgL1G0F28UAYEGjqmyEVeyx/orRtSGvEnqAbZKePrYjOiFz9vA YabA== X-Received: by 10.66.218.198 with SMTP id pi6mr44965853pac.107.1385606889398; Wed, 27 Nov 2013 18:48:09 -0800 (PST) Received: from localhost ([42.75.143.10]) by mx.google.com with ESMTPSA id rz6sm91035850pab.22.2013.11.27.18.48.07 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 27 Nov 2013 18:48:08 -0800 (PST) From: Kuo-Jung Su To: u-boot@lists.denx.de Date: Thu, 28 Nov 2013 10:47:05 +0800 Message-Id: <1385606826-2540-4-git-send-email-dantesu@gmail.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1385606826-2540-1-git-send-email-dantesu@gmail.com> References: <1385606826-2540-1-git-send-email-dantesu@gmail.com> In-Reply-To: <1385347693-1192-1-git-send-email-dantesu@gmail.com> References: <1385347693-1192-1-git-send-email-dantesu@gmail.com> Cc: Kuo-Jung Su Subject: [U-Boot] [PATCH v2 3/4] i2c: fti2c010: serial out r/w address in MSB order 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: Kuo-Jung Su For a eeprom with a 2-bytes address (e.g., Ateml AT24C1024B), the r/w address should be serial out in MSB order. Signed-off-by: Kuo-Jung Su Cc: Heiko Schocher --- Changes for v2: - Initial release drivers/i2c/fti2c010.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) -- 1.7.9.5 diff --git a/drivers/i2c/fti2c010.c b/drivers/i2c/fti2c010.c index eccc1da..351fa38 100644 --- a/drivers/i2c/fti2c010.c +++ b/drivers/i2c/fti2c010.c @@ -179,6 +179,34 @@ static int fti2c010_probe(struct i2c_adapter *adap, u8 dev) return ret; } +static void addr_to_i2c_data(u8 *buf, uint32_t val, int len) +{ + if (!buf || len <= 0) + return; + + /* MSB first */ + switch (len) { + case 1: + buf[0] = (u8)(val & 0xff); + break; + case 2: + buf[0] = (u8)((val >> 8) & 0xff); + buf[1] = (u8)(val & 0xff); + break; + case 3: + buf[0] = (u8)((val >> 16) & 0xff); + buf[1] = (u8)((val >> 8) & 0xff); + buf[2] = (u8)(val & 0xff); + break; + default: + buf[0] = (u8)((val >> 24) & 0xff); + buf[1] = (u8)((val >> 16) & 0xff); + buf[2] = (u8)((val >> 8) & 0xff); + buf[3] = (u8)(val & 0xff); + break; + } +} + static int fti2c010_read(struct i2c_adapter *adap, u8 dev, uint addr, int alen, uchar *buf, int len) { @@ -187,10 +215,7 @@ static int fti2c010_read(struct i2c_adapter *adap, int ret, pos; uchar paddr[4]; - paddr[0] = (addr >> 0) & 0xFF; - paddr[1] = (addr >> 8) & 0xFF; - paddr[2] = (addr >> 16) & 0xFF; - paddr[3] = (addr >> 24) & 0xFF; + addr_to_i2c_data(paddr, addr, alen); /* * Phase A. Set register address @@ -252,10 +277,7 @@ static int fti2c010_write(struct i2c_adapter *adap, int ret, pos; uchar paddr[4]; - paddr[0] = (addr >> 0) & 0xFF; - paddr[1] = (addr >> 8) & 0xFF; - paddr[2] = (addr >> 16) & 0xFF; - paddr[3] = (addr >> 24) & 0xFF; + addr_to_i2c_data(paddr, addr, alen); /* * Phase A. Set register address