Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3264390ybb; Sun, 22 Mar 2020 19:58:26 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt+Eq0wH5QeOsMFjIJyfdkWpL7/APa0YKe+NiWiAg6w9BnAGsOeNlW7fA3uTUrz9m8Yzoyv X-Received: by 2002:a9d:2c01:: with SMTP id f1mr6887081otb.67.1584932306852; Sun, 22 Mar 2020 19:58:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584932306; cv=none; d=google.com; s=arc-20160816; b=XS5Q55WHtNTfEkHJBxxEwi344UWZkzZxIpCJLtrZweMMcrDlEaRBpI2/JHc3VSwGnu PIRxTEtZvK2WxytUr50iPz/suWpfQeY8jlr5/jv9yZuWqMrq/iJvdxnNqX7WjefClhGl 3Nv9uUqB3Oh703iJPozrv6tja6na/JrrwMiNg+NSCF0KjMjhpt4yHJRcmQMkcsq5EOZB KRi9jZqa7DV7t3NeW2iTDANlcEFVZRDXg8MENTteTucYwD8+7028ngphRd9sRXLbfPlm AIqWQ5Jwd48LGSytd5VZEIsnSOvmQn6Vv0IrfR/uZCzDqSSYF14Q7J5ysihldj7Jsvpu GUIA== 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=AzKNp0Bukz0SfQKbFYnotqvXt5RjOKiGdbp496IXj9s=; b=RtXhgMjzwGtu8H/xgVKAvY/bKmRimmuFzhC0Kk4D+AtmPxD4sUTzybWZqVT2PKh98X OU1DACOXBkeHwWiMkeEcXsU5r9LroyMPQ8Q1QnifNNUGF/HYq4cJHfUVnl9UpLiNwrd7 uMlUIQuoATXzSfoj1njXFBbbAc1sT1TSj2lMTgGU8MRQrP+XQKWAUgpYn0ZXkMlPEfT9 9mROWBU52GhPAngtitSkcndJ9HFj6En+VuS97tbAtwUpLCGG2ahr+8ew3utsxxQOnH5M g7iCfT24voSvtB7idZzu809BvMRX1Dt1cDQgCb+kovKfgfk4eKDKOaYaNaMqJSAE8jDX Jukg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lfUesMTj; 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 w23si7310034oti.18.2020.03.22.19.58.15; Sun, 22 Mar 2020 19:58:26 -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=lfUesMTj; 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 S1727296AbgCWC5h (ORCPT + 99 others); Sun, 22 Mar 2020 22:57:37 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:38836 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726983AbgCWC5g (ORCPT ); Sun, 22 Mar 2020 22:57:36 -0400 Received: by mail-pf1-f196.google.com with SMTP id z25so2441204pfa.5; Sun, 22 Mar 2020 19:57:35 -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=AzKNp0Bukz0SfQKbFYnotqvXt5RjOKiGdbp496IXj9s=; b=lfUesMTjlNPx60Mxt/CMQDqFO8n68Fw8/VgDDp3OFQrayJ3kqJZ9QcTJKsYZ24SMae adSIr+c2NX9B0KllH4wLrlb1IXoiEcZKwWsI8E0krisUwJ405gfBS7dkloi+dxC7j2jk MLQdphP2uZWADPW8tSOnMMXGEZnvbNdsYPRm7bRv1tvp9R71409DVVgYNEKOqyi/Bk0J Bqw4eSQ3mSDx4rxORkvxiLCsVKPgAmT9/YlXU3ZCo2gXQNBEeKU94s1FQPsLlDXMXqtB exmMdIi1UGfQYuooGImXVB765ml356wFCMoVAhsalI7zhvYIn6AJrGWmvvUEEa8KzWX8 xbPQ== 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=AzKNp0Bukz0SfQKbFYnotqvXt5RjOKiGdbp496IXj9s=; b=I53j9LDkuxcQc0l30dxfdsS7TDQazd65uxXvr+kQnbCL/Vzq2DI1iv1ILlrgLnxtaa iXB/tJ973Db3fWi2JjhOPxygbgThk84xw+B4nnKJQlo+LpBR/UdmbcDA6IIIN7DnDwEF MbPAnHQv2Zwk1PkIY1trwQNDgpuieYHBQIvTA9vOL02IlUnq9vkiyAjv/Ngq9l67QAEd 0VF9j/3Rf1hxvnotdWt/+UQs4twuCpWFoL5AwoAAkQa61qS5PmonILVdBwPSHGIffLz0 RgHO1ZrmJ3lpd8BFNEF3fYMUt160PHNOwI6vYSFL2CLlK/uXQghG/f8E/53IGNurwHzP JwOg== X-Gm-Message-State: ANhLgQ0d4pq/2ivdTSj45s2Bw+bkFifF+AhPdZcNT7JUN21ubAPBKlR9 WyPoAnq/0uu/svbca3bmtEo= X-Received: by 2002:a62:ce48:: with SMTP id y69mr21861018pfg.178.1584932255139; Sun, 22 Mar 2020 19:57:35 -0700 (PDT) Received: from localhost (104.128.80.227.16clouds.com. [104.128.80.227]) by smtp.gmail.com with ESMTPSA id 71sm12103932pfv.8.2020.03.22.19.57.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Mar 2020 19:57:34 -0700 (PDT) From: Dejin Zheng To: andrew@lunn.ch, f.fainelli@gmail.com, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, mchehab+samsung@kernel.org, gregkh@linuxfoundation.org, broonie@kernel.org, tglx@linutronix.de, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Dejin Zheng Subject: [PATCH net-next v6 07/10] net: phy: introduce phy_read_poll_timeout macro Date: Mon, 23 Mar 2020 10:56:30 +0800 Message-Id: <20200323025633.6069-8-zhengdejin5@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200323025633.6069-1-zhengdejin5@gmail.com> References: <20200323025633.6069-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 it is sometimes necessary to poll a phy register by phy_read() function until its value satisfies some condition. introduce phy_read_poll_timeout() macros that do this. Suggested-by: Andrew Lunn Reviewed-by: Andrew Lunn Signed-off-by: Dejin Zheng --- v5 -> v6: - no changed. v4 -> v5: - no changed. v3 -> v4: - deal with precedence issues for parameter cond. v2 -> v3: - modify the parameter order of newly added functions. phy_read_poll_timeout(val, cond, sleep_us, timeout_us, \ phydev, regnum) || \/ phy_read_poll_timeout(phydev, regnum, val, cond, sleep_us, \ timeout_us) v1 -> v2: - pass a phydev and a regnum to replace args... parameter in the phy_read_poll_timeout(), and also handle the phy_read() function's return error. include/linux/phy.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/phy.h b/include/linux/phy.h index 42a5ec9288d5..f2e0aea13a2f 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -714,6 +714,19 @@ static inline int phy_read(struct phy_device *phydev, u32 regnum) return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum); } +#define phy_read_poll_timeout(phydev, regnum, val, cond, sleep_us, timeout_us) \ +({ \ + int ret = 0; \ + ret = read_poll_timeout(phy_read, val, (cond) || val < 0, sleep_us, \ + timeout_us, phydev, regnum); \ + if (val < 0) \ + ret = val; \ + if (ret) \ + phydev_err(phydev, "%s failed: %d\n", __func__, ret); \ + ret; \ +}) + + /** * __phy_read - convenience function for reading a given PHY register * @phydev: the phy_device struct -- 2.25.0