Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2920431ybb; Sun, 22 Mar 2020 10:51:54 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvGSMeP6bKTAWMmZv7O5OOSZH5cKrFAZRnT4c0dL2DUW0diAbCTP0mb1CtIn3RpizoJT/sz X-Received: by 2002:a9d:2f26:: with SMTP id h35mr14250881otb.246.1584899514167; Sun, 22 Mar 2020 10:51:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584899514; cv=none; d=google.com; s=arc-20160816; b=GeXysuHv3w4U9jBJvTA3aP3QPangqQ+UnX9vghosbqp2KX/Ym3KQaV1UYMLQLA5H8y JLjeyEgR8tdG2y6eLuD/KKBLgZRaQRihTLAULTUTu3U6Cmozkgmi8eIYMTNL6FJzYHbC iP14z3W2dkvnfqtNfDgE0vgSMVMv/cY4vp/YF611G3l0npHEXDyZpkH5yWlaIvPuXSai zNbREaJxUJ6E3HO9Hplen4KC8VDI8gikDxgucdsfbzuerTJR2nppdVqUUrUr/rnaeu15 4oMANRu3Dz0MdmS5WusXLTrWuCCgDLaYPN7R5Oumx9sqr3CXB4ALyHMNd8STa87pGfVq /2PQ== 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=/YhBDotZNiUkpqK45eTrgb3dFMB1KDWG5QBFRlQzbfM=; b=K+ek/zrozZEhYlDoto1tb2hcNICo9nfiF4bMGxWI+jmqrVFGEEAE2eOMw6XYyHtG8f MmzNgYKwwn22C64HuVquKPzek9ZM2H1nY3lbSYfM+bv0+dYjrQmVDGykRguGsv4zqFDm PRUTr4toc1DC6YuncL2a+ad1k5FhDq+EuybInCFrsRJVL0Zh9bic77nfja3w+ZvGgGkT 2MlW+JYkJRFVrXVbstNmzl79H+MLZPHCiLkdzZXucdLdXLWbFL99BsqMdJEnhaXTOR0/ e1EkNfrJhgz4PpAOtzwrSh7m+8VL4JhDh7tSooEdaHD0d9JfjSTLSOxeEzMro+P4uWBf vE/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Y6oLeb7X; 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 x63si5956263oia.101.2020.03.22.10.51.42; Sun, 22 Mar 2020 10:51:54 -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=Y6oLeb7X; 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 S1727040AbgCVRuK (ORCPT + 99 others); Sun, 22 Mar 2020 13:50:10 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:42033 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727024AbgCVRuF (ORCPT ); Sun, 22 Mar 2020 13:50:05 -0400 Received: by mail-pl1-f194.google.com with SMTP id t3so4853600plz.9; Sun, 22 Mar 2020 10:50:04 -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=/YhBDotZNiUkpqK45eTrgb3dFMB1KDWG5QBFRlQzbfM=; b=Y6oLeb7XdV3SgVAK5PbJRcvZ2+K1yOxt5UvbgsxZYszMis6QthDllZB4/n7rw2wlG3 bSiQe3f/RPF/Kxtlt2dLkFIOgn6eppA8xkzvG14Ww1mbuARoa8O1XgCB20KTMCERhh4L d8Y72xV0LwUhTmHDCMKsrQM/t8IY7017EXjYHukMiw/lu4reMK4QVbd0tbxcHAV7wYDg ZAQuErck+REWqOAVGtqXdycqpCDElESqSFpnr7LAWxFaEobEk15gjrsNDg74532dvKtq 4tJdMYgfc0h15Ja4W6ds212iN35VW1QEHvZujR7z6n9CzHoGmB4GsI2L04oE/g4A1uV/ y3YA== 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=/YhBDotZNiUkpqK45eTrgb3dFMB1KDWG5QBFRlQzbfM=; b=uHXwjGBxJNv3B3auJYzl81cUs0ZXuFAUXgl94h2P/R8jZ+p8dQMN6i86SSyLbA0Vst xm87tkEGmnYt7joeLdPXy1YjkUvZMW6QEvIbmkr0/dKkb3/P9oaKT5t229jq2Z/GpFZf PI4HGG2J7phsUTJim7NYpcSY60xFoDHJUgq+e+tZxhkutLEmUegn3HcixF46bl840t9a x8+OLmZ1q46JWOhcSct0NAvOZgzonP5+tgEmuAFDZwCvv6bwbY/DwfEh9EHkuyZilmnb UhStnq89HSc5WupYK6p+j0lGTGflasxOuyoKj8i4ruPr242sCl7Jr5UoJO6znIeFKcCf qf/Q== X-Gm-Message-State: ANhLgQ2mH6+eFaGp5rPypjS2rmN4U1h8x7pIsUud83cdKJZhAJmNRYkw /SwJX7SKhq0VyOB9oW55wW4= X-Received: by 2002:a17:90a:228c:: with SMTP id s12mr20944474pjc.68.1584899404058; Sun, 22 Mar 2020 10:50:04 -0700 (PDT) Received: from localhost ([216.24.188.11]) by smtp.gmail.com with ESMTPSA id e187sm10433716pfe.143.2020.03.22.10.50.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Mar 2020 10:50:03 -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, corbet@lwn.net, 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 v5 03/10] net: phy: introduce phy_read_mmd_poll_timeout macro Date: Mon, 23 Mar 2020 01:49:36 +0800 Message-Id: <20200322174943.26332-4-zhengdejin5@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200322174943.26332-1-zhengdejin5@gmail.com> References: <20200322174943.26332-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_mmd() function until its value satisfies some condition. introduce phy_read_mmd_poll_timeout() macros that do this. Suggested-by: Andrew Lunn Reviewed-by: Andrew Lunn Signed-off-by: Dejin Zheng --- 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_mmd_poll_timeout(val, cond, sleep_us, timeout_us, \ phydev, devaddr, regnum) || \/ phy_read_mmd_poll_timeout(phydev, devaddr regnum, val, cond, \ sleep_us, timeout_us) v1 -> v2: - passed a phydev, device address and a reg to replace args... parameter in phy_read_mmd_poll_timeout() by Andrew Lunn 's suggestion. Andrew Lunn , Thanks very much for your help! - handle phy_read_mmd return an error(the return value < 0) in phy_read_mmd_poll_timeout(). Thanks Andrew again. include/linux/phy.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/linux/phy.h b/include/linux/phy.h index 36d9dea04016..42a5ec9288d5 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -784,6 +785,20 @@ static inline int __phy_modify_changed(struct phy_device *phydev, u32 regnum, */ int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum); +#define phy_read_mmd_poll_timeout(phydev, devaddr, regnum, val, cond, \ + sleep_us, timeout_us) \ +({ \ + int ret = 0; \ + ret = read_poll_timeout(phy_read_mmd, val, (cond) || val < 0, \ + sleep_us, timeout_us, phydev, devaddr, \ + regnum); \ + if (val < 0) \ + ret = val; \ + if (ret) \ + phydev_err(phydev, "%s failed: %d\n", __func__, ret); \ + ret; \ +}) + /** * __phy_read_mmd - Convenience function for reading a register * from an MMD on a given PHY. -- 2.25.0