From patchwork Wed Nov 21 22:40:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 1001457 X-Patchwork-Delegate: trini@ti.com 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=none (p=none dis=none) header.from=denx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 430cxX6gJmz9s1x for ; Thu, 22 Nov 2018 09:41:17 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 51EE2C21E3A; Wed, 21 Nov 2018 22:41:09 +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=none 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 6DF15C21C2C; Wed, 21 Nov 2018 22:41:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E11B6C21C2C; Wed, 21 Nov 2018 22:41:05 +0000 (UTC) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) by lists.denx.de (Postfix) with ESMTPS id 9BC2EC21C27 for ; Wed, 21 Nov 2018 22:41:05 +0000 (UTC) Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 430cxF2cSRz1qvNV; Wed, 21 Nov 2018 23:41:05 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 430cxF2CjFz1qsJQ; Wed, 21 Nov 2018 23:41:05 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id l6MBgfr3XcWx; Wed, 21 Nov 2018 23:41:04 +0100 (CET) X-Auth-Info: tsP0G3jHvacgMpKJHUHmdpoIBUn2rXvm0ZVPVJAO7NA= Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Wed, 21 Nov 2018 23:41:04 +0100 (CET) From: Lukasz Majewski To: u-boot@lists.denx.de Date: Wed, 21 Nov 2018 23:40:43 +0100 Message-Id: <20181121224043.23524-1-lukma@denx.de> X-Mailer: git-send-email 2.11.0 Cc: Tom Rini Subject: [U-Boot] [PATCH v1] eeprom: Add device model based I2C support to eeprom command 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" After this change the 'eeprom' command can be used with DM aware boards. Signed-off-by: Lukasz Majewski --- cmd/eeprom.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/cmd/eeprom.c b/cmd/eeprom.c index 4052cf494a..e88cb131a1 100644 --- a/cmd/eeprom.c +++ b/cmd/eeprom.c @@ -137,6 +137,23 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen, spi_write(addr, alen, buffer, len); #else /* I2C */ +#if defined(CONFIG_DM_I2C) && defined(CONFIG_SYS_I2C_EEPROM_BUS) + struct udevice *dev; + + ret = i2c_get_chip_for_busnum(CONFIG_SYS_I2C_EEPROM_BUS, addr[0], + alen - 1, &dev); + if (ret) { + printf("%s: Cannot find udev for a bus %d\n", __func__, + CONFIG_SYS_I2C_EEPROM_BUS); + return CMD_RET_FAILURE; + } + + if (read) + ret = dm_i2c_read(dev, offset, buffer, len); + else + ret = dm_i2c_write(dev, offset, buffer, len); + +#else /* Non DM I2C support - will be removed */ #if defined(CONFIG_SYS_I2C_EEPROM_BUS) i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS); #endif @@ -145,10 +162,11 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen, ret = i2c_read(addr[0], offset, alen - 1, buffer, len); else ret = i2c_write(addr[0], offset, alen - 1, buffer, len); - - if (ret) - ret = 1; #endif +#endif /* CONFIG_DM_I2C && CONFIG_SYS_I2C_EEPROM_BUS */ + if (ret) + ret = CMD_RET_FAILURE; + return ret; }