From patchwork Thu Apr 20 15:25:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Franklin S Cooper Jr X-Patchwork-Id: 752838 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3w82lR1mDvz9s4s for ; Fri, 21 Apr 2017 01:26:27 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="ZqdLsoMW"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id CC175C21E21; Thu, 20 Apr 2017 15:26:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 2BE71C21E43; Thu, 20 Apr 2017 15:26:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2FD51C21E41; Thu, 20 Apr 2017 15:26:07 +0000 (UTC) Received: from fllnx210.ext.ti.com (fllnx210.ext.ti.com [198.47.19.17]) by lists.denx.de (Postfix) with ESMTPS id 60B0CC21E12 for ; Thu, 20 Apr 2017 15:26:04 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx210.ext.ti.com (8.15.1/8.15.1) with ESMTP id v3KFQ2gW017875 for ; Thu, 20 Apr 2017 10:26:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1492701962; bh=3RZzAv/g0n++pU38GQ6uQWfGA/3gutEiOBeMkWEWSSs=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=ZqdLsoMWI8Y9bsPy+iLEuamszg5lbRXHktYpa/lFDCdHMkaX0dfs5N+YpgMv+CNC2 QCrSv/XwZElNj3M4Dd8FMj5uN1s6UeH7IANRAtZeI4TIXfegDpp7jvzVPZAvwtbQ4W ziaB4zwTmTvsbHIFL1XFCBNgsPDHEB0O5DQL0r9Q= Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id v3KFQ23Z024489 for ; Thu, 20 Apr 2017 10:26:02 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.294.0; Thu, 20 Apr 2017 10:26:01 -0500 Received: from dbdmail01.india.ti.com (dbdmail01.india.ti.com [172.24.162.206]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id v3KFQ0v4023509; Thu, 20 Apr 2017 10:26:01 -0500 Received: from udb0273011.am.dhcp.ti.com (udb0273011.am.dhcp.ti.com [128.247.83.178]) by dbdmail01.india.ti.com (8.14.3/8.14.3/SuSE Linux 0.8) with ESMTP id v3KFPptW015503; Thu, 20 Apr 2017 20:55:58 +0530 From: Franklin S Cooper Jr To: , , , Date: Thu, 20 Apr 2017 10:25:44 -0500 Message-ID: <20170420152549.28031-4-fcooper@ti.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20170420152549.28031-1-fcooper@ti.com> References: <20170420152549.28031-1-fcooper@ti.com> MIME-Version: 1.0 Cc: Franklin S Cooper Jr Subject: [U-Boot] [PATCH v2 3/8] ti: common: board_detect: Introduce function to set the address length. X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Reading from the I2C EEPROM used typically requires using an address length of 2. However, when using DM for I2C the default address length used is 1. To fix this introduce a new function that allows the address length to be changed. The logic to do so was copied from cmd/i2c.c. Signed-off-by: Franklin S Cooper Jr Reviewed-by: Tom Rini Reviewed-by: Heiko Schocher --- board/ti/common/board_detect.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c index c55e24e..1e695f4 100644 --- a/board/ti/common/board_detect.c +++ b/board/ti/common/board_detect.c @@ -10,10 +10,47 @@ #include #include +#include #include #include "board_detect.h" +#if defined(CONFIG_DM_I2C_COMPAT) +/** + * ti_i2c_set_alen - Set chip's i2c address length + * @bus_addr - I2C bus number + * @dev_addr - I2C eeprom id + * @alen - I2C address length in bytes + * + * DM_I2C by default sets the address length to be used to 1. This + * function allows this address length to be changed to match the + * eeprom used for board detection. + */ +int __maybe_unused ti_i2c_set_alen(int bus_addr, int dev_addr, int alen) +{ + struct udevice *dev; + struct udevice *bus; + int rc; + + rc = uclass_get_device_by_seq(UCLASS_I2C, bus_addr, &bus); + if (rc) + return rc; + rc = i2c_get_chip(bus, dev_addr, 1, &dev); + if (rc) + return rc; + rc = i2c_set_chip_offset_len(dev, alen); + if (rc) + return rc; + + return 0; +} +#else +int __maybe_unused ti_i2c_set_alen(int bus_addr, int dev_addr, int alen) +{ + return 0; +} +#endif + /** * ti_i2c_eeprom_init - Initialize an i2c bus and probe for a device * @i2c_bus: i2c bus number to initialize