From: Rosen Penev <rosenp@gmail.com>
To: linux-rtc@vger.kernel.org
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] rtc: mpc5121: replace in_8/out_8 with generic accessors
Date: Sun, 4 Oct 2026 15:35:40 -0700 [thread overview]
Message-ID: <20261004223540.455708-1-rosenp@gmail.com> (raw)
Convert the PowerPC-specific in_8/out_8, in_be16/out_be16 and
in_be32/out_be32 accessors to the portable ioread8/iowrite8,
ioread16be/iowrite16be and ioread32be/iowrite32be. On PowerPC these
use the same ordered MMIO accessors, so behaviour is unchanged.
With no PowerPC-only accessors left, allow COMPILE_TEST, and add the
HAS_IOMEM dependency the generic accessors need.
Assisted-by: LLM
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/rtc/Kconfig | 3 +-
drivers/rtc/rtc-mpc5121.c | 80 +++++++++++++++++++--------------------
2 files changed, 42 insertions(+), 41 deletions(-)
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 0636b9ead2c2..8c0ac7e7a582 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1773,7 +1773,8 @@ config RTC_DRV_MC13XXX
config RTC_DRV_MPC5121
tristate "Freescale MPC5121 built-in RTC"
- depends on PPC_MPC512x || PPC_MPC52xx
+ depends on PPC_MPC512x || PPC_MPC52xx || COMPILE_TEST
+ depends on HAS_IOMEM
help
If you say yes here you will get support for the
built-in RTC on MPC5121 or on MPC5200.
diff --git a/drivers/rtc/rtc-mpc5121.c b/drivers/rtc/rtc-mpc5121.c
index b90f8337a7e6..c038301fb86b 100644
--- a/drivers/rtc/rtc-mpc5121.c
+++ b/drivers/rtc/rtc-mpc5121.c
@@ -87,15 +87,15 @@ struct mpc5121_rtc_data {
static void mpc5121_rtc_update_smh(struct mpc5121_rtc_regs __iomem *regs,
struct rtc_time *tm)
{
- out_8(®s->second_set, tm->tm_sec);
- out_8(®s->minute_set, tm->tm_min);
- out_8(®s->hour_set, tm->tm_hour);
+ iowrite8(tm->tm_sec, ®s->second_set);
+ iowrite8(tm->tm_min, ®s->minute_set);
+ iowrite8(tm->tm_hour, ®s->hour_set);
/* set time sequence */
- out_8(®s->set_time, 0x1);
- out_8(®s->set_time, 0x3);
- out_8(®s->set_time, 0x1);
- out_8(®s->set_time, 0x0);
+ iowrite8(0x1, ®s->set_time);
+ iowrite8(0x3, ®s->set_time);
+ iowrite8(0x1, ®s->set_time);
+ iowrite8(0x0, ®s->set_time);
}
static int mpc5121_rtc_read_time(struct device *dev, struct rtc_time *tm)
@@ -107,7 +107,7 @@ static int mpc5121_rtc_read_time(struct device *dev, struct rtc_time *tm)
/*
* linux time is actual_time plus the offset saved in target_time
*/
- now = in_be32(®s->actual_time) + in_be32(®s->target_time);
+ now = ioread32be(®s->actual_time) + ioread32be(®s->target_time);
rtc_time64_to_tm(now, tm);
@@ -131,7 +131,7 @@ static int mpc5121_rtc_set_time(struct device *dev, struct rtc_time *tm)
* between it and linux time to the target_time register.
*/
now = rtc_tm_to_time64(tm);
- out_be32(®s->target_time, now - in_be32(®s->actual_time));
+ iowrite32be(now - ioread32be(®s->actual_time), ®s->target_time);
/*
* update second minute hour registers
@@ -148,20 +148,20 @@ static int mpc5200_rtc_read_time(struct device *dev, struct rtc_time *tm)
struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
int tmp;
- tm->tm_sec = in_8(®s->second);
- tm->tm_min = in_8(®s->minute);
+ tm->tm_sec = ioread8(®s->second);
+ tm->tm_min = ioread8(®s->minute);
/* 12 hour format? */
- if (in_8(®s->hour) & 0x20)
- tm->tm_hour = (in_8(®s->hour) >> 1) +
- (in_8(®s->hour) & 1 ? 12 : 0);
+ if (ioread8(®s->hour) & 0x20)
+ tm->tm_hour = (ioread8(®s->hour) >> 1) +
+ (ioread8(®s->hour) & 1 ? 12 : 0);
else
- tm->tm_hour = in_8(®s->hour);
+ tm->tm_hour = ioread8(®s->hour);
- tmp = in_8(®s->wday_mday);
+ tmp = ioread8(®s->wday_mday);
tm->tm_mday = tmp & 0x1f;
- tm->tm_mon = in_8(®s->month) - 1;
- tm->tm_year = in_be16(®s->year) - 1900;
+ tm->tm_mon = ioread8(®s->month) - 1;
+ tm->tm_year = ioread16be(®s->year) - 1900;
tm->tm_wday = (tmp >> 5) % 7;
tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
tm->tm_isdst = 0;
@@ -177,16 +177,16 @@ static int mpc5200_rtc_set_time(struct device *dev, struct rtc_time *tm)
mpc5121_rtc_update_smh(regs, tm);
/* date */
- out_8(®s->month_set, tm->tm_mon + 1);
- out_8(®s->weekday_set, tm->tm_wday ? tm->tm_wday : 7);
- out_8(®s->date_set, tm->tm_mday);
- out_be16(®s->year_set, tm->tm_year + 1900);
+ iowrite8(tm->tm_mon + 1, ®s->month_set);
+ iowrite8(tm->tm_wday ? tm->tm_wday : 7, ®s->weekday_set);
+ iowrite8(tm->tm_mday, ®s->date_set);
+ iowrite16be(tm->tm_year + 1900, ®s->year_set);
/* set date sequence */
- out_8(®s->set_date, 0x1);
- out_8(®s->set_date, 0x3);
- out_8(®s->set_date, 0x1);
- out_8(®s->set_date, 0x0);
+ iowrite8(0x1, ®s->set_date);
+ iowrite8(0x3, ®s->set_date);
+ iowrite8(0x1, ®s->set_date);
+ iowrite8(0x0, ®s->set_date);
return 0;
}
@@ -198,7 +198,7 @@ static int mpc5121_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
*alarm = rtc->wkalarm;
- alarm->pending = in_8(®s->alm_status);
+ alarm->pending = ioread8(®s->alm_status);
return 0;
}
@@ -212,10 +212,10 @@ static int mpc5121_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
alarm->time.tm_mon = -1;
alarm->time.tm_year = -1;
- out_8(®s->alm_min_set, alarm->time.tm_min);
- out_8(®s->alm_hour_set, alarm->time.tm_hour);
+ iowrite8(alarm->time.tm_min, ®s->alm_min_set);
+ iowrite8(alarm->time.tm_hour, ®s->alm_hour_set);
- out_8(®s->alm_enable, alarm->enabled);
+ iowrite8(alarm->enabled, ®s->alm_enable);
rtc->wkalarm = *alarm;
return 0;
@@ -226,10 +226,10 @@ static irqreturn_t mpc5121_rtc_handler(int irq, void *dev)
struct mpc5121_rtc_data *rtc = dev_get_drvdata((struct device *)dev);
struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
- if (in_8(®s->int_alm)) {
+ if (ioread8(®s->int_alm)) {
/* acknowledge and clear status */
- out_8(®s->int_alm, 1);
- out_8(®s->alm_status, 1);
+ iowrite8(1, ®s->int_alm);
+ iowrite8(1, ®s->alm_status);
rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF);
return IRQ_HANDLED;
@@ -243,9 +243,9 @@ static irqreturn_t mpc5121_rtc_handler_upd(int irq, void *dev)
struct mpc5121_rtc_data *rtc = dev_get_drvdata((struct device *)dev);
struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
- if (in_8(®s->int_sec) && (in_8(®s->int_enable) & 0x1)) {
+ if (ioread8(®s->int_sec) && (ioread8(®s->int_enable) & 0x1)) {
/* acknowledge */
- out_8(®s->int_sec, 1);
+ iowrite8(1, ®s->int_sec);
rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_UF);
return IRQ_HANDLED;
@@ -266,7 +266,7 @@ static int mpc5121_rtc_alarm_irq_enable(struct device *dev,
else
val = 0;
- out_8(®s->alm_enable, val);
+ iowrite8(val, ®s->alm_enable);
rtc->wkalarm.enabled = val;
return 0;
@@ -340,11 +340,11 @@ static int mpc5121_rtc_probe(struct platform_device *op)
if (of_device_is_compatible(op->dev.of_node, "fsl,mpc5121-rtc")) {
u32 ka;
- ka = in_be32(&rtc->regs->keep_alive);
+ ka = ioread32be(&rtc->regs->keep_alive);
if (ka & 0x02) {
dev_warn(&op->dev,
"mpc5121-rtc: Battery or oscillator failure!\n");
- out_be32(&rtc->regs->keep_alive, ka);
+ iowrite32be(ka, &rtc->regs->keep_alive);
}
rtc->rtc->ops = &mpc5121_rtc_ops;
/*
@@ -376,8 +376,8 @@ static void mpc5121_rtc_remove(struct platform_device *op)
struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
/* disable interrupt, so there are no nasty surprises */
- out_8(®s->alm_enable, 0);
- out_8(®s->int_enable, in_8(®s->int_enable) & ~0x1);
+ iowrite8(0, ®s->alm_enable);
+ iowrite8(ioread8(®s->int_enable) & ~0x1, ®s->int_enable);
irq_dispose_mapping(rtc->irq);
irq_dispose_mapping(rtc->irq_periodic);
--
2.56.0
next reply other threads:[~2026-10-04 22:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-04 22:35 Rosen Penev [this message]
2026-10-04 22:41 ` [PATCH] rtc: mpc5121: replace in_8/out_8 with generic accessors sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-06-02 4:00 Rosen Penev
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=20261004223540.455708-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.