Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3812171ybb; Mon, 23 Mar 2020 08:08:51 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtpbuViOF0mftDcecjGmoNibgBKJ/0rCgyq5L5f7Gvg8CUPGnEuZOh1ePtNhnBOzr5HWKuH X-Received: by 2002:a4a:a286:: with SMTP id h6mr508964ool.47.1584976130970; Mon, 23 Mar 2020 08:08:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584976130; cv=none; d=google.com; s=arc-20160816; b=ZXiUrq/fGcRtP7nXpY7/bqsDH/Rihgeq9p/o3TU1YByD1ZuZ36gfZAi8f2ektf4U6s ndGMuOsV13mtRPOZiH/N8xiifKpNMovGN/cjzbrDa9D5CaDWR5+FTNPnNjtE5DuAeJe2 y+eB5b17rgsm/KB8kDTjfoK7iRqpCu5FnSAYcDzLHn2AEgFS5taJz4iD/AeE+WmfOvRP EpMlG9ieFMWUA2976vB1nN83+ddVGptlvzYSCdLQqoRdLr8VqIfELtfCgOOGKb2xcTZK ZzpzEDIXBysg9Mu2gieIO5EKgIi7YBLCnfc1l9ccq7zvfw+lSU7bytnTHX8tDdrQAHhe +xbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MWMlIjTk5KuF2+RRlAxJbPgNkWmTokiEC+TY2tIstt0=; b=wHuUXaQ6Cz4fpCyGk7Wa8YqN3b/Wtdkw7ae0ulaxMYXj7vdTTsL0RhMdmxXElYSNT4 NPFDjmIH8pdxwz21rNMMRZiaR/g9en26srszDszEWwnVhMGcH8RfimUZnO8p2tTR4KMz PMshrZnDKCzulxKUk5Ub3N+aKDrCYIRuR0pM6+BLvkhLl2rIdZZ6MKPDCEKf3iLkkXB4 dyu8ht73clJx2+QSwg1bCJX3bVmkK7GaEc+5etF7Z0NbtBmPJzFkiEiZANmcBi8ODCqn wHZhORxcJ5NflIX34wamf4pf9+HiyGHaWhrden9Sfd0x4vjESBJFyOW8SIOdez197/eE YDDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NXGL0ufl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m13si7994737otk.113.2020.03.23.08.08.31; Mon, 23 Mar 2020 08:08:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NXGL0ufl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727555AbgCWPHP (ORCPT + 99 others); Mon, 23 Mar 2020 11:07:15 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:37865 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727024AbgCWPHO (ORCPT ); Mon, 23 Mar 2020 11:07:14 -0400 Received: by mail-pg1-f196.google.com with SMTP id a32so7329724pga.4; Mon, 23 Mar 2020 08:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MWMlIjTk5KuF2+RRlAxJbPgNkWmTokiEC+TY2tIstt0=; b=NXGL0uflfR0jVYuRAQ5XJCitGJMb+V0WVZjersIHsn+ApsXjvPBWnxWMNCNB2ZhZTG o/gHoAeTR8qWZrl6sW7xeDtbOzvpA7r1dnTC4PIdqazilVlLrdW1JwG6okiFNi3/RGjj cRVjZNBsGbFWidbM0egcyhWyYXdaNrEArLTZcxrq4j/cnh6mKqzKEXoLhruLk4AyOPyZ qkSE0veQOWdN6Lvj/9ak4fdK8hXKGwU8vcK0YFS0dAVECJfZMAh/1VfMK/npi1gniB4g h159ZPnwGec/Ms7g9ZiJbejHeO7H0AgJKKWgSzrnZo2To1PcOKq7joIdVh4P5Cn4BkV2 z8kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MWMlIjTk5KuF2+RRlAxJbPgNkWmTokiEC+TY2tIstt0=; b=KZbgTsnt++GKuaqudEOY39J2Wkr8tlQkwUu4IsbSpq9Qpsl8T6E0MVtfCml9Y+2Wea KW8PHPpicul7L7AE13UOo25vHiLbucPieakwZMaL2V9WcZ1W6GvhIp3QBXXzJczYHWvi HpgSwlJH2BvzX5YUSiIjHkwBtDcJPFmcD+wT8JwtJh+LRx0cieTwT+L6EoFlYwgM6UI5 vCEL63YLRQ4Uh7GUg54GTJT4BNNLVx+SWP/unEB+RJnfIj4mfhSzq1PbVDfbDUOtH+hl wMz1gRXu1fc0mwTLrw1HfLqVmM8LUzi8Vf9mv1iLsk8GQ96nlvu+WOVgEUTfeyI+A84j +mKQ== X-Gm-Message-State: ANhLgQ2PRx4TZKPoR5btHoBIbZSFkZVLlcfDTTgPvIquG4ZoCkbUH9VS QhxMs1PB9EtBfTNqGVgLuKA= X-Received: by 2002:aa7:9ec7:: with SMTP id r7mr10541482pfq.191.1584976033203; Mon, 23 Mar 2020 08:07:13 -0700 (PDT) Received: from localhost (176.122.158.203.16clouds.com. [176.122.158.203]) by smtp.gmail.com with ESMTPSA id g11sm13457935pfm.4.2020.03.23.08.07.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Mar 2020 08:07:12 -0700 (PDT) From: Dejin Zheng To: andrew@lunn.ch, f.fainelli@gmail.com, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, corbet@lwn.net, tglx@linutronix.de, gregkh@linuxfoundation.org, allison@lohutok.net, mchehab+samsung@kernel.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Dejin Zheng Subject: [PATCH net-next v7 08/10] net: phy: use phy_read_poll_timeout() to simplify the code Date: Mon, 23 Mar 2020 23:05:58 +0800 Message-Id: <20200323150600.21382-9-zhengdejin5@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200323150600.21382-1-zhengdejin5@gmail.com> References: <20200323150600.21382-1-zhengdejin5@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org use phy_read_poll_timeout() to replace the poll codes for simplify the code in phy_poll_reset() function. Reviewed-by: Andrew Lunn Signed-off-by: Dejin Zheng --- v6 -> v7: - adapt to a newly added parameter sleep_before_read. v5 -> v6: - add some check for keep the code more similar. v4 -> v5: - it can add msleep before call phy_read_poll_timeout() to keep the code more similar. so add it. v3 -> v4: - drop it. v2 -> v3: - adapt to it after modifying the parameter order of the newly added function v1 -> v2: - remove the handle of phy_read()'s return error. drivers/net/phy/phy_device.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index a585faf8b844..3b8f6b0b47b5 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1059,18 +1059,12 @@ EXPORT_SYMBOL(phy_disconnect); static int phy_poll_reset(struct phy_device *phydev) { /* Poll until the reset bit clears (50ms per retry == 0.6 sec) */ - unsigned int retries = 12; - int ret; - - do { - msleep(50); - ret = phy_read(phydev, MII_BMCR); - if (ret < 0) - return ret; - } while (ret & BMCR_RESET && --retries); - if (ret & BMCR_RESET) - return -ETIMEDOUT; + int ret, val; + ret = phy_read_poll_timeout(phydev, MII_BMCR, val, !(val & BMCR_RESET), + 50000, 600000, true); + if (ret) + return ret; /* Some chips (smsc911x) may still need up to another 1ms after the * BMCR_RESET bit is cleared before they are usable. */ -- 2.25.0