Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2344161ybb; Sat, 21 Mar 2020 19:51:41 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsJzqXVCHa+QWvaQRDJK+DAGHVXNLJp7gkky73emv5ryzSBX3TE7678MLFT6SPG+azY0hWj X-Received: by 2002:a9d:5e8b:: with SMTP id f11mr13349236otl.110.1584845501044; Sat, 21 Mar 2020 19:51:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584845501; cv=none; d=google.com; s=arc-20160816; b=mBo5WOufS8ff6RieH2aKVW+Y2m6N9BNp6Y1Pe1qVaAGheKURHJxSVwZ71kLOOQU5wL +unbyUHbfxru61rlMoNh/zoIIeHB/PTjoeVAcpfF3mjHwmYr+VMlRInlA7c807HuE6vv 1b+EFKd8xUT1oy6oxmysZMWqHFJnS+IpOCgWKB9vaEY4Ub+xd6ok7K3VjMz3A2qPNepe II3iTpuM9UWEJUnAbf1qyCRPyb6vjDnnUOmh33+40L5SF0UF3EDFTT+8Ssx5tqFyewhu JXPhYn1khOJn0YNRNhiGPYNgSXVQYEBFDsUQLhU5ZH9+o/8LZhqcmdjEq9FzrOdf5Qq6 1yCw== 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=1VcYGik7hKP7sx1O39JIjU063LsYKhPa4fKZoVZkWgw=; b=AQEMp8XiAr+KjJ91CmlphbSzsiOg3YP7NKmmWWqa+dCZfrQAyR+VJHSredz2C5HKnk BwC3s2Apula2c0vHrYLeMX71wi/T/6IXqR8J86SvUR+D75S7tzIa/8afOO9YXrx8fAvv IUfZYLIeqYijW4xPlKjY7cQ8wpIyPXhMZ/1XCFTkSQu6CEsAN1wzKr5QLuMJ54OfGX7c AA+DOkRmb/j9rmL9kj3JRsAjmXOzaXJ8QcaiLvt/rHvm446d8FiJfSqEqREChgXkEOWF LLlVcz18vghGaKxHaCgm9CdsLQWT4BDCUnW/eNYvHnf4d3qr5QGoZWVPZwG7KiSSdxBW T1iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=roFyt3rs; 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 e4si5418881oib.135.2020.03.21.19.51.28; Sat, 21 Mar 2020 19:51:41 -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=roFyt3rs; 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 S1728463AbgCVCts (ORCPT + 99 others); Sat, 21 Mar 2020 22:49:48 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40293 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728440AbgCVCtq (ORCPT ); Sat, 21 Mar 2020 22:49:46 -0400 Received: by mail-pg1-f195.google.com with SMTP id t24so5249006pgj.7; Sat, 21 Mar 2020 19:49:45 -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=1VcYGik7hKP7sx1O39JIjU063LsYKhPa4fKZoVZkWgw=; b=roFyt3rsBBLqxTgu9tA8nmp6t57gCbc2M5qF9MSofActeFc/Mvh0aFRaXNL37bW9Bh 8S4Bwvn3X2gTCnfrtkGDYtKqFd91lzAMQoSMvfRNjxjO30GGK88LN52L8s7/qnOro/yJ hyHMpujBh+3nt67IDHBXUrmx13eCyd6h9UX1/kfTl1tEb0rwn49Re7Jg4fbvHPvAf7pz rnwhbE6B3qFWiyxpRI4bRlzGsopE89R+P1f5IQbTL+LgkH5CodjB3rjsqyfVmT6BFXX5 iSLR3wIgQgF8djcDYt1T6rbNEa00OA5WulywCIrEjA7g15mrlb0nw1rGgrzLXqHDFuyJ bitQ== 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=1VcYGik7hKP7sx1O39JIjU063LsYKhPa4fKZoVZkWgw=; b=CTAL8dQy8rlVl6fiDdXcKZm47aHIwXAzwybiqiprSoRAkLTswTZJqBn0IIe6PlSs2a 6jcPZnzVn3a1z8FlFgenUPUk3hegNAV7D7l3hMX7BAcBHOscToxP5GjKyALeXHYIYemi RXj6FyejBRcxADg9Tom38kbguQdaFAjPlU0ecNRLOoEHM3h+GLeUv+PV7HyC9KkWbqir VMVZm+nS9PLh00Pjr2LUMikku++ULvPDDWHbMTuEks1PXXJTtvRD8r4O+dCXOWU7iYSw bzTak082TUW7F/4HGvqEAzm+PKSRj7UWQY+SF2qW+lAQ65j9qoVz9Zrvq+R0W/C1mgvI bEwQ== X-Gm-Message-State: ANhLgQ3aYtUD0Jav/Ffhl657DNB7Bh4AnpiJEFXIvay4FElHhXb6T3Ep 2okeaD09xiTlSRs6XPRrAck= X-Received: by 2002:a63:1517:: with SMTP id v23mr15442033pgl.89.1584845385234; Sat, 21 Mar 2020 19:49:45 -0700 (PDT) Received: from localhost ([216.24.188.11]) by smtp.gmail.com with ESMTPSA id f64sm10111279pfb.72.2020.03.21.19.49.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 21 Mar 2020 19:49:44 -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 6/7] net: phy: introduce phy_read_poll_timeout macro Date: Sun, 22 Mar 2020 10:48:33 +0800 Message-Id: <20200322024834.31402-7-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() function until its value satisfies some condition. introduce phy_read_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_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 29718865242d..a23d6caf5c2c 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