Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2343557ybb; Sat, 21 Mar 2020 19:50:25 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtcyM1EJUmKobrdy8XHtLP/zpwMq45M0E39ZRlDQRYIJ3zgYvLbSalRUxUQPfeOlLLsnanT X-Received: by 2002:a05:6830:1e96:: with SMTP id n22mr12623673otr.189.1584845424934; Sat, 21 Mar 2020 19:50:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584845424; cv=none; d=google.com; s=arc-20160816; b=0cFcc92QIN9TUzUJnntEOle5O/Ne1Jjkw2beEql/SSyfEj7qbgxQyn8pE9gXps+g6X GcapQfnyZk19r//3s/iP/1ZiF7ia2Qxc/12qhToY3rY/RVD/+Q3cXEzjHiEi1ei+OOmu wogDDHJTJWFVAN7eWd0cwuYW5pDf6BpcYun97f6Ea5WP4nd/7ituqCROBRvMX+j79IHR SGDLULi9g010fePYuO5VSjPb0WHfdrDzCBn/ZEIi3d9RyYDFlUJ7n4xkOxa1mGJ8qfmj qjYb+fcjdAPF7IbG80R1BO4uocJrAH5b5mZiDc3X1sLkGmKRY8ETxTeB6ncmqMRMlaLb hxpA== 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=FS355/DlagMHd1BrxDh8ix1dGSAXXztsH4fyn/7Ndgs=; b=nv/DFPeaZP/jVAnB+xjveZFOYbAG6d8sAX4OQX9zED6MHS2BAI4a9i1ioFBoZYRDHR m11A+7fcZXj8EUHvqB5tbPSE4fWEgdwDNaApx46C/r0yH/Vm+0TSue6YIV9QihB0Jizp bTofTlhUxBdJ67OlbT1YI2rIOzSJteBPYXFK4ZjMXE8TiYsRUlPdsnETKCMHReWdM56K vzpnZ7h0uOD/gQZwjd1OR2t3T7KYhkT2z/4Fd1EezUdP4zuZ5w1aMvHugkIn+HHsd5eR WHDUHMJjuZjHDRWS6iWEoZO+yrHmCAJEAUKUIA/hXLIYuZpn3tXvSTJl9k8W1/7mHKX1 MjHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Sggf9bSJ; 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 f9si6000279oti.44.2020.03.21.19.50.13; Sat, 21 Mar 2020 19:50:24 -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=Sggf9bSJ; 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 S1728375AbgCVCtg (ORCPT + 99 others); Sat, 21 Mar 2020 22:49:36 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34212 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727851AbgCVCtf (ORCPT ); Sat, 21 Mar 2020 22:49:35 -0400 Received: by mail-pg1-f195.google.com with SMTP id t3so5268660pgn.1; Sat, 21 Mar 2020 19:49:34 -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=FS355/DlagMHd1BrxDh8ix1dGSAXXztsH4fyn/7Ndgs=; b=Sggf9bSJmr839qR715Pf5DDl3Hzw4Sq1ViaqXU5gxpE8IuAZ2fu5mVqOMi6pfA/MnD WQccCGLrxVfkFjmsJwP7Rk3K7nADBNEXogYu83hnEyt48tBsZNV3M/fumvKMjJzkIMKZ E+Hy1qNJgMAyUXcb2uru+4upn+ccArcbvOatW1eR+USW1rRIufwbF96j+BFd9MmoFW8/ UUzWPuuhizQmCXSaHRSPuYxYVG9xFjatyFOoRYOx7oMNhhcZq5eMUdbMrL+MSq8OHd9u WyTGaj4EbM9QQc8pX7H2h26D6t8T/bbjUWrQaZG6yb14qFDORBtysQPoOPV/VLgP9ich zPoQ== 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=FS355/DlagMHd1BrxDh8ix1dGSAXXztsH4fyn/7Ndgs=; b=fy3jQaMjlqho33Je9sVL3z/Cxeq2MgS7K9nprJpRPrWQM3gTGgBYgFLjm76gHNAgEw U+ERpm5UQje9UKJ71/aIRGqy3lROta8X2E4QoUd6V0aonuvVhUaH5314xLWEJJz2JGYN FzCNAW0uIXOMLMOXSPhKvGUbkXPOZWX6fMozaRXBZ6ct9xpkUs1ulC7xe/Ivyvj4i0Vz 1LQCBpkaZEmPHGKWubPtyHF90XzK8o5mr1l3pJ0YG+gnmVRiQnzEwmL2PxXt8gqXQDGD Ns3BUgRZsZCAPkxBmbvYMESsep4U4fDeKD4QzEYxiFA7UnsIHYQ7cLYo9Z2nvdK43thO iu/Q== X-Gm-Message-State: ANhLgQ3uw4DBcjYEQnsItjxpG218XnQEoOskj6eSR69HwW6k+v+VPNhD 9AKP7ikZCvr9mEo5o1nDk3o= X-Received: by 2002:aa7:92da:: with SMTP id k26mr17668594pfa.139.1584845373549; Sat, 21 Mar 2020 19:49:33 -0700 (PDT) Received: from localhost ([216.24.188.11]) by smtp.gmail.com with ESMTPSA id h64sm9178931pfg.191.2020.03.21.19.49.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 21 Mar 2020 19:49:33 -0700 (PDT) From: Dejin Zheng To: andrew@lunn.ch, f.fainelli@gmail.com, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, allison@lohutok.net, tglx@linutronix.de, gregkh@linuxfoundation.org, mchehab+samsung@kernel.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Dejin Zheng Subject: [PATCH net-next v3 3/7] net: phy: introduce phy_read_mmd_poll_timeout macro Date: Sun, 22 Mar 2020 10:48:30 +0800 Message-Id: <20200322024834.31402-4-zhengdejin5@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200322024834.31402-1-zhengdejin5@gmail.com> References: <20200322024834.31402-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 Signed-off-by: Dejin Zheng --- 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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/phy.h b/include/linux/phy.h index 36d9dea04016..29718865242d 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -784,6 +785,19 @@ 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