Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1739592

[PATCH v2 08/13] regmap: add iopoll-like polling macro for regmap_field

From Chen-Yu Tsai <wens@csie.org>
Newsgroups linux.kernel
Subject [PATCH v2 08/13] regmap: add iopoll-like polling macro for regmap_field
Date 2017-09-26 09:10 +0200
Message-ID <utSag-1rM-47@gated-at.bofh.it> (permalink)
References <utSae-1rM-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


This patch adds a macro regmap_field_read_poll_timeout that works
similar to the readx_poll_timeout defined in linux/iopoll.h, except
that this can also return the error value returned by a failed
regmap_field_read.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 include/linux/regmap.h | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 978abfbac617..93a4663d7acb 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -139,6 +139,45 @@ struct reg_sequence {
 	pollret ?: ((cond) ? 0 : -ETIMEDOUT); \
 })
 
+/**
+ * regmap_field_read_poll_timeout - Poll until a condition is met or timeout
+ *
+ * @field: Regmap field to read from
+ * @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).  Should be less than ~20ms since usleep_range
+ *            is used (see Documentation/timers/timers-howto.txt).
+ * @timeout_us: Timeout in us, 0 means never timeout
+ *
+ * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_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 readx_poll_timeout macros in linux/iopoll.h.
+ */
+#define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \
+({ \
+	ktime_t timeout = ktime_add_us(ktime_get(), timeout_us); \
+	int pollret; \
+	might_sleep_if(sleep_us); \
+	for (;;) { \
+		pollret = regmap_field_read((field), &(val)); \
+		if (pollret) \
+			break; \
+		if (cond) \
+			break; \
+		if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
+			pollret = regmap_field_read((field), &(val)); \
+			break; \
+		} \
+		if (sleep_us) \
+			usleep_range((sleep_us >> 2) + 1, sleep_us); \
+	} \
+	pollret ?: ((cond) ? 0 : -ETIMEDOUT); \
+})
+
 #ifdef CONFIG_REGMAP
 
 enum regmap_endian {
-- 
2.14.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 00/13] drm/sun4i: hdmi: Support HDMI controller on A31 Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
  [PATCH v2 07/13] dt-bindings: display: sun4i: Add binding for A31 HDMI controller Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
  [PATCH v2 02/13] clk: sunxi-ng: sun6i: Rename HDMI DDC clock to avoid name collision Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 02/13] clk: sunxi-ng: sun6i: Rename HDMI DDC clock to  avoid name collision Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 11:40 +0200
      Re: [PATCH v2 02/13] clk: sunxi-ng: sun6i: Rename HDMI DDC clock to  avoid name collision Chen-Yu Tsai <wens@csie.org> - 2017-09-27 05:50 +0200
  [PATCH v2 09/13] drm/sun4i: hdmi: Add support for controller hardware variants Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 09/13] drm/sun4i: hdmi: Add support for controller  hardware variants Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 12:10 +0200
  [PATCH v2 13/13] ARM: dts: sun6i: Enable HDMI support on some A31/A31s devices Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
  [PATCH v2 08/13] regmap: add iopoll-like polling macro for regmap_field Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
  [PATCH v2 10/13] drm/sun4i: hdmi: Add A31 specific DDC register definitions Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 10/13] drm/sun4i: hdmi: Add A31 specific DDC register  definitions Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 12:10 +0200
  [PATCH v2 04/13] drm/sun4i: hdmi: Disable clks in bind function error path and unbind function Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 04/13] drm/sun4i: hdmi: Disable clks in bind function  error path and unbind function Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 12:00 +0200
  [PATCH v2 03/13] drm/sun4i: tcon: Add support for demuxing TCON output on A31 Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 03/13] drm/sun4i: tcon: Add support for demuxing TCON  output on A31 Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 12:00 +0200
      Re: [PATCH v2 03/13] drm/sun4i: tcon: Add support for demuxing TCON  output on A31 Chen-Yu Tsai <wens@csie.org> - 2017-09-27 06:10 +0200
  [PATCH v2 05/13] drm/sun4i: hdmi: create a regmap for later use Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 05/13] drm/sun4i: hdmi: create a regmap for later use Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 12:00 +0200
  [PATCH v2 06/13] drm/sun4i: hdmi: Allow using second PLL as TMDS clk parent Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 06/13] drm/sun4i: hdmi: Allow using second PLL as TMDS  clk parent Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 12:00 +0200

csiph-web