From patchwork Fri Jun 22 04:11:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Troy Kisky X-Patchwork-Id: 166474 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 DC2BEB6FA1 for ; Fri, 22 Jun 2012 14:12:56 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 039BC280A5; Fri, 22 Jun 2012 06:12:47 +0200 (CEST) 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 3WVgfeTim8Z4; Fri, 22 Jun 2012 06:12:46 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 007B228087; Fri, 22 Jun 2012 06:12:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1072228094 for ; Fri, 22 Jun 2012 06:12:30 +0200 (CEST) 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 4lTWvVRSOsbk for ; Fri, 22 Jun 2012 06:12:29 +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-pb0-f44.google.com (mail-pb0-f44.google.com [209.85.160.44]) by theia.denx.de (Postfix) with ESMTPS id A1D1A28085 for ; Fri, 22 Jun 2012 06:12:26 +0200 (CEST) Received: by pbcwy7 with SMTP id wy7so2919103pbc.3 for ; Thu, 21 Jun 2012 21:12:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=iJMo2L75fMAzabnHVTpJBQwWRWmqy+yCzDHlsJZyICY=; b=JKV8aOx7NQRBRZips4iNUlDXHcpXs8unRGfn5cTsHeGeHmjadAkMYObJjougUVbqTe BUGYAfqivz/pHvdbK9Yhyi0iCvbDLROZeIZ/I8Anz6dR0beBNZIeYYVoSKrXs23RWyyo sj6dQIBv+aCNiq94XPT6W1h/H+RHyPMhi8CehoOhVEac/3mr7PsEsPR7i6T0e45e5WFq 2jefPW7ZTKVlpEw+Lg2FEIFKuaV0Y2YheYnyjzvINeQj0R97aWC6y3y1UTDuVEW5ZMwm SyDrgUqWTYhtKOu7Jv5AYKPHLhlw9xazAoTvTT4GVlL+afKpYbXEgnQ/ob8JL5fXjgVW XRTA== Received: by 10.68.195.167 with SMTP id if7mr6112064pbc.16.1340338344705; Thu, 21 Jun 2012 21:12:24 -0700 (PDT) Received: from officeserver-2 ([70.96.116.236]) by mx.google.com with ESMTPS id ip5sm37700026pbc.3.2012.06.21.21.12.22 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 21 Jun 2012 21:12:24 -0700 (PDT) Received: from tkisky by officeserver-2 with local (Exim 4.76) (envelope-from ) id 1ShvEL-00032V-4K; Thu, 21 Jun 2012 21:12:21 -0700 From: Troy Kisky To: hs@denx.de, sbabic@denx.de Date: Thu, 21 Jun 2012 21:11:58 -0700 Message-Id: <1340338339-11626-3-git-send-email-troy.kisky@boundarydevices.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1340338339-11626-1-git-send-email-troy.kisky@boundarydevices.com> References: <1340338339-11626-1-git-send-email-troy.kisky@boundarydevices.com> X-Gm-Message-State: ALoCoQlFLevC4PNcaXW0az07INmzPQzp8/1musS0z/CJhYPDX98+EM03b5h/4cU+cRg3THGY9MxL Cc: u-boot@lists.denx.de, r49496@freescale.com, jason.hui@linaro.org Subject: [U-Boot] [PATCH 03/24] mxc_i2c: create tx_byte function 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 Use tx_byte function instead of having 3 copies of the code. Signed-off-by: Troy Kisky Acked-by: Marek Vasut --- drivers/i2c/mxc_i2c.c | 72 +++++++++++++++---------------------------------- 1 file changed, 21 insertions(+), 51 deletions(-) diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c index 0b46c9c..0fd508a 100644 --- a/drivers/i2c/mxc_i2c.c +++ b/drivers/i2c/mxc_i2c.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -207,17 +208,21 @@ int i2c_imx_trx_complete(void) udelay(1); } - return 1; + return -ETIMEDOUT; } -/* - * Check if the transaction was ACKed - */ -int i2c_imx_acked(void) +static int tx_byte(struct mxc_i2c_regs *i2c_regs, u8 byte) { - struct mxc_i2c_regs *i2c_regs = (struct mxc_i2c_regs *)I2C_BASE; + unsigned ret; - return readb(&i2c_regs->i2sr) & I2SR_RX_NO_AK; + writeb(byte, &i2c_regs->i2dr); + ret = i2c_imx_trx_complete(); + if (ret < 0) + return ret; + ret = readb(&i2c_regs->i2sr); + if (ret & I2SR_RX_NO_AK) + return -ENODEV; + return 0; } /* @@ -271,30 +276,6 @@ void i2c_imx_stop(void) } /* - * Set chip address and access mode - * - * read = 1: READ access - * read = 0: WRITE access - */ -int i2c_imx_set_chip_addr(uchar chip, int read) -{ - struct mxc_i2c_regs *i2c_regs = (struct mxc_i2c_regs *)I2C_BASE; - int ret; - - writeb((chip << 1) | read, &i2c_regs->i2dr); - - ret = i2c_imx_trx_complete(); - if (ret) - return ret; - - ret = i2c_imx_acked(); - if (ret) - return ret; - - return ret; -} - -/* * Write register address */ int i2c_imx_set_reg_addr(uint addr, int alen) @@ -303,14 +284,8 @@ int i2c_imx_set_reg_addr(uint addr, int alen) int ret = 0; while (alen--) { - writeb((addr >> (alen * 8)) & 0xff, &i2c_regs->i2dr); - - ret = i2c_imx_trx_complete(); - if (ret) - break; - - ret = i2c_imx_acked(); - if (ret) + ret = tx_byte(i2c_regs, (addr >> (alen * 8)) & 0xff); + if (ret < 0) break; } @@ -322,13 +297,14 @@ int i2c_imx_set_reg_addr(uint addr, int alen) */ int i2c_probe(uchar chip) { + struct mxc_i2c_regs *i2c_regs = (struct mxc_i2c_regs *)I2C_BASE; int ret; ret = i2c_imx_start(); if (ret) return ret; - ret = i2c_imx_set_chip_addr(chip, 0); + ret = tx_byte(i2c_regs, chip << 1); if (ret) return ret; @@ -352,7 +328,7 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buf, int len) return ret; /* write slave address */ - ret = i2c_imx_set_chip_addr(chip, 0); + ret = tx_byte(i2c_regs, chip << 1); if (ret) return ret; @@ -364,7 +340,7 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buf, int len) temp |= I2CR_RSTA; writeb(temp, &i2c_regs->i2cr); - ret = i2c_imx_set_chip_addr(chip, 1); + ret = tx_byte(i2c_regs, (chip << 1) | 1); if (ret) return ret; @@ -419,7 +395,7 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buf, int len) return ret; /* write slave address */ - ret = i2c_imx_set_chip_addr(chip, 0); + ret = tx_byte(i2c_regs, chip << 1); if (ret) return ret; @@ -428,14 +404,8 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buf, int len) return ret; for (i = 0; i < len; i++) { - writeb(buf[i], &i2c_regs->i2dr); - - ret = i2c_imx_trx_complete(); - if (ret) - return ret; - - ret = i2c_imx_acked(); - if (ret) + ret = tx_byte(i2c_regs, buf[i]); + if (ret < 0) return ret; }