From patchwork Tue Jan 19 01:05:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 1428365 X-Patchwork-Delegate: andre.przywara@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKVpY42Ngz9sVv for ; Tue, 19 Jan 2021 12:06:13 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5B8EF828BD; Tue, 19 Jan 2021 02:06:10 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 5B0E7828BD; Tue, 19 Jan 2021 02:06:09 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 99175828B1 for ; Tue, 19 Jan 2021 02:06:06 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B6E4A1FB; Mon, 18 Jan 2021 17:06:04 -0800 (PST) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C3E243F66E; Mon, 18 Jan 2021 17:06:03 -0800 (PST) From: Andre Przywara To: Jagan Teki Cc: Peter Robinson , Hans de Goede , u-boot@lists.denx.de, linux-sunxi@googlegroups.com Subject: [PATCH] sunxi: Properly check for SATAPWR and MACPWR Date: Tue, 19 Jan 2021 01:05:20 +0000 Message-Id: <20210119010520.13284-1-andre.przywara@arm.com> X-Mailer: git-send-email 2.14.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean The #ifdef CONFIG_xxxPWR conditionals were not working as expected, as string Kconfig symbols are always "defined" from the preprocessor's perspective. This lead to unnecessary calls to the GPIO routines, but also always added a half a second delay to wait for a SATA disk to power up. Many thanks to Peter for pointing this out! Fix this by properly comparing the Kconfig symbols against the empty string. strcmp() would be nicer for this, but GCC does not optimise this away, probably due to our standalone compiler switches. Reported-by: Peter Robinson Signed-off-by: Andre Przywara Tested-by: Samuel Holland # Orange Pi WinPlus Tested-by: Peter Robinson Reviewed-by: Jernej Skrabec --- board/sunxi/board.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/board/sunxi/board.c b/board/sunxi/board.c index 4f058952b5b..a0b5778b3bc 100644 --- a/board/sunxi/board.c +++ b/board/sunxi/board.c @@ -265,18 +265,28 @@ int board_init(void) if (ret) return ret; -#ifdef CONFIG_SATAPWR - satapwr_pin = sunxi_name_to_gpio(CONFIG_SATAPWR); - gpio_request(satapwr_pin, "satapwr"); - gpio_direction_output(satapwr_pin, 1); - /* Give attached sata device time to power-up to avoid link timeouts */ - mdelay(500); -#endif -#ifdef CONFIG_MACPWR - macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR); - gpio_request(macpwr_pin, "macpwr"); - gpio_direction_output(macpwr_pin, 1); -#endif + /* strcmp() would look better, but doesn't get optimised away. */ + if (CONFIG_SATAPWR[0]) { + satapwr_pin = sunxi_name_to_gpio(CONFIG_SATAPWR); + if (satapwr_pin >= 0) { + gpio_request(satapwr_pin, "satapwr"); + gpio_direction_output(satapwr_pin, 1); + + /* + * Give the attached SATA device time to power-up + * to avoid link timeouts + */ + mdelay(500); + } + } + + if (CONFIG_MACPWR[0]) { + macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR); + if (macpwr_pin >= 0) { + gpio_request(macpwr_pin, "macpwr"); + gpio_direction_output(macpwr_pin, 1); + } + } #ifdef CONFIG_DM_I2C /*