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: 1001643 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="w9NaqW/6"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 430w2d100Hz9s5c for ; Thu, 22 Nov 2018 21:01:45 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id C4E73C21F02; Thu, 22 Nov 2018 10:01:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 36733C21F19; Thu, 22 Nov 2018 10:01:13 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id F1DB4C21EC2; Thu, 22 Nov 2018 10:01:09 +0000 (UTC) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by lists.denx.de (Postfix) with ESMTPS id 98D34C21EBE for ; Thu, 22 Nov 2018 10:01:09 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id y139so8258181wmc.5 for ; Thu, 22 Nov 2018 02:01:09 -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=MO8xcZJoOIHI9flHOeprKhA54Si2rDEd6ioouoaq0gnpxSNKbEkRZSP1Pgbcr0TWGv Kqv7afbtw7S8zSG7hZnZSR+jnaQuU5+xlGRKwu1qPNEyT6SDJ+q0LXubn0OZu/IRF1w3 iT60mbj3Z77WuEchqdsACNj/sEWLvEwFTSVq26JqdcLReV6Hhs15iY7MLBkxP/3B1zpN qBbYcGelO51lI+b1I7FiIbda+FRFHPQ9FnAeKD+kV8iFSKiXYjJIxDc8ojFfcf+mUOBw hrmZ4tH7VSKWrqzBnOzxltCzHBYvOcOzV4pp8orntuGYlwhfIELmFiN14xHw1blVx9SN MYNQ== X-Gm-Message-State: AA+aEWbbkQ9L7STxuzFSZuW3TxmjyffMnT2fCRjMcHHTVlATy7nmErWn 0NnuTDyEfyRGm+jfi4aDT1sJQQ== 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 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 Cc: u-boot@lists.denx.de, linux-amlogic@lists.infradead.org Subject: [U-Boot] [PATCH u-boot v3 1/3] regmap: add regmap_read_poll_timeout() helper X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 *