From patchwork Wed Nov 14 10:25:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 997606 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="ItPQO6BX"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42w0yj2HClz9s3Z for ; Wed, 14 Nov 2018 21:26:21 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 02C2BC22079; Wed, 14 Nov 2018 10:25:48 +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 BC614C2207A; Wed, 14 Nov 2018 10:25:29 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EAF73C2201D; Wed, 14 Nov 2018 10:25:27 +0000 (UTC) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by lists.denx.de (Postfix) with ESMTPS id 9B554C21E1D for ; Wed, 14 Nov 2018 10:25:27 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id j10so2430204wru.4 for ; Wed, 14 Nov 2018 02:25:27 -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=u6Rr94t5mKfs6+FKsNUxvMh4VL3AgaZVTVC4YMDeLrM=; b=ItPQO6BXYPDBhVnoL+lRbuteJGSr2LjniEl2RT2h5W+OlMH1UEdcCLtGbFwh1MfcBP kKETT9B/0/z9hNH8GIIqbmhkkSSjHvvJN2WWcvg2VTXSnMjAOP7Vzdrf+Bpdq1D4UnCH GSPzTDUSb+s0kkxoUKkkRV34GYtfhXSs3sjo6arI5OYnvmmrWdy4TBGYgKVRlCTVylzw HTPijbkeeyg026v1M9JFD7ae/u+LgWPUuSWI+cdiuYOkiz7sDxk1tVv2LcoKg3h/fApy OQAGrEQdmr0lA6r7KIjoNMuwJT1bQq1uKUQ7758QSoTbqdfVFTzqjbnKAkX+1GBuqc5V kG3g== 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=u6Rr94t5mKfs6+FKsNUxvMh4VL3AgaZVTVC4YMDeLrM=; b=Cz9R2NXnVRLdaaVjyYQ1+hkJ6f3gH2uCv9hbWgxSmMw/vfxvSYt2QyCAOZze7Z4e42 x2mj/U++v8ihCIYXVUS19SnEDp10yw6qph2hLlR5kmYxBC16PS2piyMS3vc4y66pw67C ICOvgfbiMqTWJUFCcFpPvfgqIpANpnOv0pX+kUUZh2V+TMMpOy5akFxBR/KUC24dGens IPdP+1kEvDHnHB+YZfpQ0iXXddc5QVK/Relqa/mDxeIA6rWNlgU70k/EjDUUWbxBaV9k 0qOH/rpy91D+0vpwXL27jm5O/3vjVvVeOw4BS36sPKlYvf63ZykfIdfHpYihC6t/jgr8 j8oQ== X-Gm-Message-State: AGRZ1gIryiuUWJJioYuo0q1HLVxe8RKfpMhjWcjJUnpEkXerhLw7r4NO wc+m01tfn3pEZQ3dZOd3Nme4vg== X-Google-Smtp-Source: AJdET5eerQrwiAYpDDZ5HRc5extdUWyE0F5HPad6dl+pPY2Oi4mGuN7Qb+Hx22mHCn1qG6ph+SJqfw== X-Received: by 2002:a5d:6389:: with SMTP id p9-v6mr1246145wru.215.1542191127006; Wed, 14 Nov 2018 02:25:27 -0800 (PST) Received: from bender.baylibre.local ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id v9-v6sm23720908wrm.6.2018.11.14.02.25.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Nov 2018 02:25:26 -0800 (PST) From: Neil Armstrong To: jagan@openedev.com, sjg@chromium.org Date: Wed, 14 Nov 2018 11:25:18 +0100 Message-Id: <20181114102520.25346-2-narmstrong@baylibre.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181114102520.25346-1-narmstrong@baylibre.com> References: <20181114102520.25346-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. Signed-off-by: Neil Armstrong Acked-by: Jagan Teki --- include/regmap.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/regmap.h b/include/regmap.h index 6a574eaa41..cf795c455f 100644 --- a/include/regmap.h +++ b/include/regmap.h @@ -42,6 +42,44 @@ int regmap_read(struct regmap *map, uint offset, uint *valp); #define regmap_read32(map, ptr, member, valp) \ regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), 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 *