From patchwork Wed Sep 17 03:51:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 390274 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 29447140119 for ; Wed, 17 Sep 2014 13:53:31 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 54E3CA7436; Wed, 17 Sep 2014 05:53:14 +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 tZ7QlHgVypfi; Wed, 17 Sep 2014 05:53:14 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4DE43A74C1; Wed, 17 Sep 2014 05:52:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 820FAA7450 for ; Wed, 17 Sep 2014 05:52:15 +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 cFP6HUE1qdOM for ; Wed, 17 Sep 2014 05:52:12 +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-ie0-f201.google.com (mail-ie0-f201.google.com [209.85.223.201]) by theia.denx.de (Postfix) with ESMTPS id 06E00A746F for ; Wed, 17 Sep 2014 05:52:00 +0200 (CEST) Received: by mail-ie0-f201.google.com with SMTP id rl12so167093iec.4 for ; Tue, 16 Sep 2014 20:51:59 -0700 (PDT) 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=zM5EpqND85kfdnnbaiKLURUxWLjG1eXckZfaQUAtoIg=; b=iUQipw+R8YvhzS9NGsnb1318q9ApTDrrxIbtqHvmHqDPA1o9WYebRtPfjgKODOw6ca eTZjM+JGHhPuKz8E7gNZFJ/CkfC/yO9z2E/JemzWUvdIY7dh3RNk9FVXAJJSEWxtbqQH AeHhSTqJAtIQPBQ2wK9hWSERPoSn0LFhALciZsVaWUPo3iWRCA8ga0lAu7fyqw0T/qDO 846BgTgNcPnxvTSR+DeunWUmSFcCRPbRxTOnVKu1013RAAPqjt/rnLeXRtCfaboQmFib ddP/WfGEhMLwXd4/GyHW4nYnSUo2jHi7E4zW+iTi6vkT2suktQR2THtCOhKWAYUpUfmO tmBQ== X-Gm-Message-State: ALoCoQmLeuRLuZjmXmzYBtIz3GprDb6usWMJWkZz3V2MNQBsPqAcm97FWGR3eNWWbVnnlTcAy5Z/ X-Received: by 10.182.107.135 with SMTP id hc7mr3178635obb.48.1410925918936; Tue, 16 Sep 2014 20:51:58 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id n24si791681yha.6.2014.09.16.20.51.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Sep 2014 20:51:58 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id Z5BMpMDG.1; Tue, 16 Sep 2014 20:51:58 -0700 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id BC6D52227BC; Tue, 16 Sep 2014 21:51:56 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 16 Sep 2014 21:51:20 -0600 Message-Id: <1410925884-8767-8-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1410925884-8767-1-git-send-email-sjg@chromium.org> References: <1410925884-8767-1-git-send-email-sjg@chromium.org> Subject: [U-Boot] [PATCH v2 07/11] dm: imx: Add error checking to setup_i2c() 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 Since this function can fail, check its return value. Signed-off-by: Simon Glass --- Changes in v2: - Add new patch to add error checking to setup_i2c() arch/arm/imx-common/i2c-mxv7.c | 24 ++++++++++++++++----- arch/arm/include/asm/imx-common/mxc_i2c.h | 4 ++-- board/compulab/cm_fx6/cm_fx6.c | 35 +++++++++++++++++++++---------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/arch/arm/imx-common/i2c-mxv7.c b/arch/arm/imx-common/i2c-mxv7.c index a580873..70cff5c 100644 --- a/arch/arm/imx-common/i2c-mxv7.c +++ b/arch/arm/imx-common/i2c-mxv7.c @@ -69,15 +69,29 @@ static void * const i2c_bases[] = { }; /* i2c_index can be from 0 - 2 */ -void setup_i2c(unsigned i2c_index, int speed, int slave_addr, - struct i2c_pads_info *p) +int setup_i2c(unsigned i2c_index, int speed, int slave_addr, + struct i2c_pads_info *p) { + int ret; + if (i2c_index >= ARRAY_SIZE(i2c_bases)) - return; + return -EINVAL; /* Enable i2c clock */ - enable_i2c_clk(1, i2c_index); + ret = enable_i2c_clk(1, i2c_index); + if (ret) + goto err_clk; + /* Make sure bus is idle */ - force_idle_bus(p); + ret = force_idle_bus(p); + if (ret) + goto err_idle; + bus_i2c_init(i2c_bases[i2c_index], speed, slave_addr, force_idle_bus, p); + + return 0; + +err_idle: +err_clk: + return ret; } diff --git a/arch/arm/include/asm/imx-common/mxc_i2c.h b/arch/arm/include/asm/imx-common/mxc_i2c.h index 182c2f3..af86163 100644 --- a/arch/arm/include/asm/imx-common/mxc_i2c.h +++ b/arch/arm/include/asm/imx-common/mxc_i2c.h @@ -52,8 +52,8 @@ struct i2c_pads_info { &mx6q_##name : &mx6s_##name #endif -void setup_i2c(unsigned i2c_index, int speed, int slave_addr, - struct i2c_pads_info *p); +int setup_i2c(unsigned i2c_index, int speed, int slave_addr, + struct i2c_pads_info *p); void bus_i2c_init(void *base, int speed, int slave_addr, int (*idle_bus_fn)(void *p), void *p); int bus_i2c_read(void *base, uchar chip, uint addr, int alen, uchar *buf, diff --git a/board/compulab/cm_fx6/cm_fx6.c b/board/compulab/cm_fx6/cm_fx6.c index fdb8ebf..62c625a 100644 --- a/board/compulab/cm_fx6/cm_fx6.c +++ b/board/compulab/cm_fx6/cm_fx6.c @@ -69,7 +69,7 @@ static iomux_v3_cfg_t const sata_pads[] = { IOMUX_PADS(PAD_EIM_BCLK__GPIO6_IO31 | MUX_PAD_CTRL(NO_PAD_CTRL)), }; -static void cm_fx6_setup_issd(void) +static int cm_fx6_setup_issd(void) { SETUP_IOMUX_PADS(sata_pads); /* Make sure this gpio has logical 0 value */ @@ -79,14 +79,18 @@ static void cm_fx6_setup_issd(void) cm_fx6_sata_power(0); mdelay(250); cm_fx6_sata_power(1); + + return 0; } #define CM_FX6_SATA_INIT_RETRIES 10 int sata_initialize(void) { - int err, i; + int err, i, ret; - cm_fx6_setup_issd(); + ret = cm_fx6_setup_issd(); + if (ret) + return ret; for (i = 0; i < CM_FX6_SATA_INIT_RETRIES; i++) { err = setup_sata(); if (err) { @@ -141,14 +145,25 @@ I2C_PADS(i2c2_pads, IMX_GPIO_NR(1, 6)); -static void cm_fx6_setup_i2c(void) +static int cm_fx6_setup_i2c(void) { - setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, I2C_PADS_INFO(i2c0_pads)); - setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, I2C_PADS_INFO(i2c1_pads)); - setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, I2C_PADS_INFO(i2c2_pads)); + int ret; + + ret = setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, + I2C_PADS_INFO(i2c0_pads)); + if (!ret) { + ret = setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, + I2C_PADS_INFO(i2c1_pads)); + } + if (!ret) { + ret = setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, + I2C_PADS_INFO(i2c2_pads)); + } + + return ret; } #else -static void cm_fx6_setup_i2c(void) { } +static int cm_fx6_setup_i2c(void) { return 0; } #endif #ifdef CONFIG_USB_EHCI_MX6 @@ -411,9 +426,7 @@ int board_init(void) { gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; cm_fx6_setup_gpmi_nand(); - cm_fx6_setup_i2c(); - - return 0; + return cm_fx6_setup_i2c(); } int checkboard(void)