From patchwork Thu Nov 22 10:01:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 10693777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 837A75A4 for ; Thu, 22 Nov 2018 10:01:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 749582C9B0 for ; Thu, 22 Nov 2018 10:01:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68A2A2CA35; Thu, 22 Nov 2018 10:01:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3363D2CA0B for ; Thu, 22 Nov 2018 10:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=75MfCpWdWdy6/7FPJVMiwO04s2vZ/JnG0h/ces4t+B0=; b=iRlbhm4RK0luYh lkYhXEkKPXba0nEKet5X2ddRr+3jHNQsKJOZQcz5qEAuBL930FZvwLwgMBSzOueut2oxzbpGCISzq oPh4n0kI3FfRRbuTV9J89GenaZwdJSY8SxnBqh5FeF4rRyxhuYBXYIxh0ng6xLF2eiKQ7VbTIggSB BPxQsACDOvMpHtp+z/bx+fIEPBWkfdylexD/RQSqdyKKa2G6YFKzlY3eDjVUJ6nktdgdLfodqgNhX 1XewD0L9QdsiSfvbFGrqrybo//F9fe3MMiHqgP5rTiNuSHIueZLz+ZZ+VWu7B4jWfJI4Jjym5aoF5 y4gIdFKRCMkoq029+Gsg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPlnd-0002sn-OL; Thu, 22 Nov 2018 10:01:29 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPlnU-0002nS-Sv for linux-amlogic@lists.infradead.org; Thu, 22 Nov 2018 10:01:28 +0000 Received: by mail-wm1-x341.google.com with SMTP id y1so5069706wmi.3 for ; Thu, 22 Nov 2018 02:01:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+/d3fQ0KUjaUiMVLjI7Wm3yOqDGWkDypZ+4hsTrjFwk=; b=w9NaqW/64Nss1nd4TCyx/RCxwnV9W64hc8s/PjnYLhnJXWX5NTMh3t0Tha2GKX4SkA jyEffGklcytNPW49y/F27P0bOYg2PlsJ4Gj29R8qSBBiPNaPxGSEYjTrrizWSaxETM7m EPxTMFAtWRb9BgMu2Len/s5uY/ymqHW8Fh+r2yF9GeO78pw89T3D5w9OLuEMci8Q9ohW WuO1TUVUgJR9tjs1hIDuvwcOQx6PnYbb6mUNlZEf27tfK1PyhG3rAcy4+p9IEo6wj10t a9fO+kTidswy4aRE1U/W72fDm04ng3vHO/ZnMP3TR9iqoCWR/2/YtAe3+xQ45sKoWdRb bp3Q== 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=+/d3fQ0KUjaUiMVLjI7Wm3yOqDGWkDypZ+4hsTrjFwk=; b=L7AmCb1+TH8bs3FygRX0Vc9CRn4kz+XfC8NZQbFTr7/HRvrOiOZYsQN6YZt+JCbCmH oQymi9WNG4GIzSyAqyvn8BVRLApK1bQEoT3t+KPrJ2SCi1Fq1C8tHSzuKMTyIVX3f14s qFXoOEwcgJMQUkYvvJc3mL7vpyt2l+kouwakDbEKAoib8J2IoJj43mqf5O6S8pNd9Pbr UsLdJZLjJY2vK5CMu56pXNp8N1em/Bp+ikBQVUtgvRykvNmrXENB6fN/DdBjwM7UaUGZ 17i3u8n/nyL1dtxNQqKMjkS/sEo3yCE/gGwIRnYU6LNwa/mdYpTd/1vaYE8fuTqySa5Z uA+g== X-Gm-Message-State: AA+aEWZmjVcgG41v9Rr0+37zT2QiseGca9bEZJtNRMrMIIuc4MPYotb/ JtHelJ8pKbQx5xQTU2NofNVDvA== X-Google-Smtp-Source: AJdET5dXdzU7zxLEksariGHodwIfzZTVHLIZT+Hhs3HYsyB18iKncguAZfrQqi7B8ZO3Vu9n3ZjhBA== X-Received: by 2002:a1c:7c0b:: with SMTP id x11mr8862070wmc.20.1542880868997; Thu, 22 Nov 2018 02:01:08 -0800 (PST) Received: from bender.baylibre.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id t82-v6sm4677822wme.30.2018.11.22.02.01.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Nov 2018 02:01:08 -0800 (PST) From: Neil Armstrong To: jagan@openedev.com, sjg@chromium.org Subject: [PATCH u-boot v3 1/3] regmap: add regmap_read_poll_timeout() helper Date: Thu, 22 Nov 2018 11:01:03 +0100 Message-Id: <20181122100105.14829-2-narmstrong@baylibre.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181122100105.14829-1-narmstrong@baylibre.com> References: <20181122100105.14829-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181122_020120_929177_C97C0E29 X-CRM114-Status: GOOD ( 11.86 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: u-boot@lists.denx.de, linux-amlogic@lists.infradead.org, Neil Armstrong Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add the regmap_read_poll_timeout() macro based on the Linux implementation to simplify register polling with configurable timeout and sleep. Acked-by: Jagan Teki Signed-off-by: Neil Armstrong --- include/regmap.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/regmap.h b/include/regmap.h index b2b733fda6..a3afb72df5 100644 --- a/include/regmap.h +++ b/include/regmap.h @@ -239,6 +239,44 @@ int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset, #define regmap_get(map, type, member, valp) \ regmap_range_get(map, 0, type, member, valp) +/** + * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs + * + * @map: Regmap to read from + * @addr: Offset to poll + * @val: Unsigned integer variable to read the value into + * @cond: Break condition (usually involving @val) + * @sleep_us: Maximum time to sleep between reads in us (0 tight-loops). + * @timeout_ms: Timeout in ms, 0 means never timeout + * + * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read + * error return value in case of a error read. In the two former cases, + * the last read value at @addr is stored in @val. Must not be called + * from atomic context if sleep_us or timeout_us are used. + * + * This is modelled after the regmap_read_poll_timeout macros in linux but + * with millisecond timeout. + */ +#define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_ms) \ +({ \ + unsigned long __start = get_timer(0); \ + int __ret; \ + for (;;) { \ + __ret = regmap_read((map), (addr), &(val)); \ + if (__ret) \ + break; \ + if (cond) \ + break; \ + if ((timeout_ms) && get_timer(__start) > (timeout_ms)) { \ + __ret = regmap_read((map), (addr), &(val)); \ + break; \ + } \ + if ((sleep_us)) \ + udelay((sleep_us)); \ + } \ + __ret ?: ((cond) ? 0 : -ETIMEDOUT); \ +}) + /** * regmap_update_bits() - Perform a read/modify/write using a mask *