From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 2/3] mfd: rn5t568: refactor to call reset_source_set_device only once
Date: Mon, 25 Nov 2024 09:30:41 +0100 [thread overview]
Message-ID: <20241125083042.482415-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241125083042.482415-1-a.fatoum@pengutronix.de>
The function currently calls reset_source_set_device() 10 times.
By refactoring it to call it only once, the code is easier to extend in
the follow-up commit with an additional argument to
reset_source_set_device().
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
- add S-o-b (Sascha)
- add missing commit message
---
drivers/mfd/rn5t568.c | 59 +++++++++++++++++++++----------------------
1 file changed, 29 insertions(+), 30 deletions(-)
diff --git a/drivers/mfd/rn5t568.c b/drivers/mfd/rn5t568.c
index f1e2eeb0c88b..7468338a2d53 100644
--- a/drivers/mfd/rn5t568.c
+++ b/drivers/mfd/rn5t568.c
@@ -33,6 +33,7 @@ static void rn5t568_restart(struct restart_handler *rst)
static int rn5t568_reset_reason_detect(struct device *dev,
struct regmap *regmap)
{
+ enum reset_src_type type;
unsigned int reg;
int ret;
@@ -47,40 +48,38 @@ static int rn5t568_reset_reason_detect(struct device *dev,
return 0;
}
- if (reg & RN5T568_PONHIS_ON_EXTINPON) {
- reset_source_set_device(dev, RESET_POR);
- return 0;
- } else if (reg & RN5T568_PONHIS_ON_PWRONPON) {
- reset_source_set_device(dev, RESET_POR);
- return 0;
- } else if (!(reg & RN5T568_PONHIS_ON_REPWRPON))
+ if (reg & (RN5T568_PONHIS_ON_EXTINPON | RN5T568_PONHIS_ON_PWRONPON)) {
+ type = RESET_POR;
+ } else if (!(reg & RN5T568_PONHIS_ON_REPWRPON)) {
return -EINVAL;
+ } else {
+ ret = regmap_read(regmap, RN5T568_POFFHIS, ®);
+ if (ret)
+ return ret;
- ret = regmap_read(regmap, RN5T568_POFFHIS, ®);
- if (ret)
- return ret;
+ dev_dbg(dev, "Power-off history: %x\n", reg);
- dev_dbg(dev, "Power-off history: %x\n", reg);
-
- if (reg & RN5T568_POFFHIS_PWRONPOFF)
- reset_source_set_device(dev, RESET_POR);
- else if (reg & RN5T568_POFFHIS_TSHUTPOFF)
- reset_source_set_device(dev, RESET_THERM);
- else if (reg & RN5T568_POFFHIS_VINDETPOFF)
- reset_source_set_device(dev, RESET_BROWNOUT);
- else if (reg & RN5T568_POFFHIS_IODETPOFF)
- reset_source_set_device(dev, RESET_UKWN);
- else if (reg & RN5T568_POFFHIS_CPUPOFF)
- reset_source_set_device(dev, RESET_RST);
- else if (reg & RN5T568_POFFHIS_WDGPOFF)
- reset_source_set_device(dev, RESET_WDG);
- else if (reg & RN5T568_POFFHIS_DCLIMPOFF)
- reset_source_set_device(dev, RESET_BROWNOUT);
- else if (reg & RN5T568_POFFHIS_N_OEPOFF)
- reset_source_set_device(dev, RESET_EXT);
- else
- return -EINVAL;
+ if (reg & RN5T568_POFFHIS_PWRONPOFF)
+ type = RESET_POR;
+ else if (reg & RN5T568_POFFHIS_TSHUTPOFF)
+ type = RESET_THERM;
+ else if (reg & RN5T568_POFFHIS_VINDETPOFF)
+ type = RESET_BROWNOUT;
+ else if (reg & RN5T568_POFFHIS_IODETPOFF)
+ type = RESET_UKWN;
+ else if (reg & RN5T568_POFFHIS_CPUPOFF)
+ type = RESET_RST;
+ else if (reg & RN5T568_POFFHIS_WDGPOFF)
+ type = RESET_WDG;
+ else if (reg & RN5T568_POFFHIS_DCLIMPOFF)
+ type = RESET_BROWNOUT;
+ else if (reg & RN5T568_POFFHIS_N_OEPOFF)
+ type = RESET_EXT;
+ else
+ return -EINVAL;
+ }
+ reset_source_set_device(dev, type);
return 0;
}
--
2.39.5
next prev parent reply other threads:[~2024-11-25 8:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-25 8:30 [PATCH v2 1/3] reset_source: have reset_source_set_device actually set device Ahmad Fatoum
2024-11-25 8:30 ` Ahmad Fatoum [this message]
2024-11-25 8:30 ` [PATCH v2 3/3] reset_source: give reset_source_set_device a priority parameter Ahmad Fatoum
2024-11-25 8:43 ` [PATCH v2 1/3] reset_source: have reset_source_set_device actually set device Sascha Hauer
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=20241125083042.482415-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.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