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: 10682327 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 F0F8F1759 for ; Wed, 14 Nov 2018 10:25:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E40DD27E01 for ; Wed, 14 Nov 2018 10:25:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D83A32A6A3; Wed, 14 Nov 2018 10:25:44 +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 750902880F for ; Wed, 14 Nov 2018 10:25:44 +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=tAl0FoZjkjN8V6Y+DoWC8QeffWODtQ/qga+S2ZuKiaE=; b=iCNrPaRyRukW/N n4z5Mxyjr5acAyIYNunuaUsgESOvV6d8lzk+27oh5dmiInQ7OYjm/ugCLU3fays4Swq/Ale/KKsOR irokidhOZ6fc+vnJmIIM4gBczyt+ldxN7RGo9rG72hVV36lds8LO/y6b/ruSdokMSROL8fFq4Dfhk h+XuflYcQIgpgwb/3AugOPEE5R4G+j/BI871ThPoYOfvHzF4sWPEMMijCadcFnaqhiw4L/iIYo0HF yhP2c8PktrddvGjWe4YnDC15OENgH5qQ9s9ugBIwcCFF04F+yDMUfzu1v+lFdS2SG0NSX1eA32K1j qQRL4MkfmqGpaqeN4XPA==; 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 1gMsMh-0000Eg-IV; Wed, 14 Nov 2018 10:25:43 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMsMc-0000AP-Kh for linux-amlogic@lists.infradead.org; Wed, 14 Nov 2018 10:25:41 +0000 Received: by mail-wr1-x441.google.com with SMTP id u5-v6so11365144wrn.9 for ; Wed, 14 Nov 2018 02:25:28 -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=GLXIn2MrJfbGz2UzlVksMT+/IlJQXTbSw9nYGkokp7XyL84axsRwyI2DiJNqsVwF+t nujRqt+Qup38+fC+kCyWjYEy1LdYDgEWgzdpL6+GO+aI/OO5VAuV6fgdXFKgcjSaSO7r zyHBffSf9ELTXmS56YwrKGEaBDqje9jdk1U/JJvzGvRfeFZxoe4c6gXR04MDTpp9mB0O SN65btvwtWE+ITiyWUVTfQw+zznn0lLEm64wQ91yjtt7itwr05T1Jb07IzxBZioLkAxy ncmo8NgJt0ktOpfMvY8Fa/Nx36y7qxQCfEUpamcXextlGWSiYrWVKzBHpXuoKGpxv54s 11hA== X-Gm-Message-State: AGRZ1gKMQNuirD/3B2yKQYq9tvB7h3MfjKLSjbu1xX2ETiVYkk+1PBu7 zzCrorq39pQ+RlvSB+Ki8WqQvg== 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 Subject: [PATCH u-boot v3 1/3] regmap: add regmap_read_poll_timeout() helper 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_022538_675822_17C87040 X-CRM114-Status: GOOD ( 11.76 ) 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. 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 *