From: Dejin Zheng <zhengdejin5@gmail.com>
To: broonie@kernel.org, linux-kernel@vger.kernel.org
Cc: Dejin Zheng <zhengdejin5@gmail.com>
Subject: [PATCH v1 1/2] regmap: redefined regmap_read_poll_timeout to simplify code
Date: Sun, 19 Apr 2020 21:51:49 +0800 [thread overview]
Message-ID: <20200419135150.14741-2-zhengdejin5@gmail.com> (raw)
In-Reply-To: <20200419135150.14741-1-zhengdejin5@gmail.com>
use read_poll_timeout macro to redefined regmap_read_poll_timeout
and also remove the duplicate code.
Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
---
include/linux/regmap.h | 25 +++++--------------------
1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 40b07168fd8e..299c1f6a03b4 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -17,6 +17,7 @@
#include <linux/err.h>
#include <linux/bug.h>
#include <linux/lockdep.h>
+#include <linux/iopoll.h>
struct module;
struct clk;
@@ -122,26 +123,10 @@ struct reg_sequence {
*/
#define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
({ \
- u64 __timeout_us = (timeout_us); \
- unsigned long __sleep_us = (sleep_us); \
- ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
- int __ret; \
- might_sleep_if(__sleep_us); \
- for (;;) { \
- __ret = regmap_read((map), (addr), &(val)); \
- if (__ret) \
- break; \
- if (cond) \
- break; \
- if ((__timeout_us) && \
- ktime_compare(ktime_get(), __timeout) > 0) { \
- __ret = regmap_read((map), (addr), &(val)); \
- break; \
- } \
- if (__sleep_us) \
- usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
- } \
- __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
+ int __ret, __tmp; \
+ __tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
+ sleep_us, timeout_us, false, (map), (addr), &(val)); \
+ __ret ?: __tmp; \
})
/**
--
2.25.0
next prev parent reply other threads:[~2020-04-19 13:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-19 13:51 [PATCH v1 0/2] use read_poll_timeout macro " Dejin Zheng
2020-04-19 13:51 ` Dejin Zheng [this message]
2020-04-19 13:51 ` [PATCH v1 2/2] regmap: redefined regmap_field_read_poll_timeout " Dejin Zheng
2020-04-20 14:47 ` [PATCH v1 0/2] use read_poll_timeout macro " Mark Brown
2020-04-19 17:09 [PATCH v1 1/2] regmap: redefined regmap_read_poll_timeout " Markus Elfring
2020-04-20 13:30 ` Dejin Zheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200419135150.14741-2-zhengdejin5@gmail.com \
--to=zhengdejin5@gmail.com \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®