From patchwork Fri Dec 7 13:50:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 1009444 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="ccXmZkgH"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43BDlq4KNvz9rxp for ; Sat, 8 Dec 2018 01:06:15 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 2551AC22702; Fri, 7 Dec 2018 13:57:23 +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 1D6D8C22757; Fri, 7 Dec 2018 13:51:59 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 61290C22707; Fri, 7 Dec 2018 13:51:21 +0000 (UTC) Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lists.denx.de (Postfix) with ESMTPS id 373B4C226FD for ; Fri, 7 Dec 2018 13:51:15 +0000 (UTC) Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id wB7DpDIk093889; Fri, 7 Dec 2018 07:51:13 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1544190673; bh=iVo2FekK8oTPdcZegJ7sCa8mOr1J2xovb+nIJ2tXgbI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=ccXmZkgHvVwN7r672FvV5m9CWH9iZvy7Wey1xT59IzmeXDflxkmGYyXc9c5mWLx8W CX1LwXhna+iqze7Yhsu9kHRXvdUKHQ2+7KucIQzB/qgaAX8W/eQPRshiRRqCk/7trD feTXVW+Mq6u/QvgsJ4Tmq6gbsqJcoxweeAMaCgrg= Received: from DFLE100.ent.ti.com (dfle100.ent.ti.com [10.64.6.21]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id wB7DpDOB096394 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 7 Dec 2018 07:51:13 -0600 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Fri, 7 Dec 2018 07:51:13 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Fri, 7 Dec 2018 07:51:13 -0600 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id wB7DpCC0014532; Fri, 7 Dec 2018 07:51:13 -0600 From: Jean-Jacques Hiblot To: , Date: Fri, 7 Dec 2018 14:50:47 +0100 Message-ID: <1544190655-4405-12-git-send-email-jjhiblot@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544190655-4405-1-git-send-email-jjhiblot@ti.com> References: <1544190655-4405-1-git-send-email-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RESEND PATCH v3 11/19] ti: common: board_detect: Allow DM I2C without CONFIG_DM_I2C_COMPAT 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" From: Andreas Dannenberg The EEPROM reading in the board detection code is done through legacy I2C functions which on platforms using DM_I2C this functionality is provided via the CONFIG_DM_I2C_COMPAT layer. To allow newer platforms to use the board detection code without relying on CONFIG_DM_I2C_COMPAT go ahead and add an I2C handling implementation that directly uses the I2C DM functionality. Signed-off-by: Andreas Dannenberg Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini Reviewed-by: Heiko Schocher --- Changes in v3: None Changes in v2: None board/ti/common/board_detect.c | 54 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c index c475f10..085e732 100644 --- a/board/ti/common/board_detect.c +++ b/board/ti/common/board_detect.c @@ -50,6 +50,7 @@ int __maybe_unused ti_i2c_set_alen(int bus_addr, int dev_addr, int alen) } #endif +#if !defined(CONFIG_DM_I2C) || defined(CONFIG_DM_I2C_COMPAT) /** * ti_i2c_eeprom_init - Initialize an i2c bus and probe for a device * @i2c_bus: i2c bus number to initialize @@ -94,6 +95,7 @@ static int __maybe_unused ti_i2c_eeprom_read(int dev_addr, int offset, return i2c_read(dev_addr, offset, alen, ep, epsize); } +#endif /** * ti_eeprom_string_cleanup() - Handle eeprom programming errors @@ -122,9 +124,57 @@ __weak void gpi2c_init(void) static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr, u32 header, u32 size, uint8_t *ep) { - u32 byte, hdr_read; + u32 hdr_read; int rc; +#if defined(CONFIG_DM_I2C) && !defined(CONFIG_DM_I2C_COMPAT) + struct udevice *dev; + struct udevice *bus; + + 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; + + /* + * Read the header first then only read the other contents. + */ + rc = i2c_set_chip_offset_len(dev, 2); + if (rc) + return rc; + + rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4); + if (rc) + return rc; + + /* Corrupted data??? */ + if (hdr_read != header) { + rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4); + /* + * read the eeprom header using i2c again, but use only a + * 1 byte address (some legacy boards need this..) + */ + if (rc) { + rc = i2c_set_chip_offset_len(dev, 1); + if (rc) + return rc; + + rc = dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4); + } + if (rc) + return rc; + } + if (hdr_read != header) + return -1; + + rc = dm_i2c_read(dev, 0, ep, size); + if (rc) + return rc; +#else + u32 byte; + gpi2c_init(); rc = ti_i2c_eeprom_init(bus_addr, dev_addr); if (rc) @@ -168,7 +218,7 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr, rc = i2c_read(dev_addr, 0x0, byte, ep, size); if (rc) return rc; - +#endif return 0; }