From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: Sudeep Holla <sudeep.holla@arm.com>,
Cristian Marussi <cristian.marussi@arm.com>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
imx@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-rtc@vger.kernel.org, Peng Fan <peng.fan@nxp.com>
Subject: [PATCH 3/4] rtc: Introduce devm_rtc_allocate_device_priv
Date: Mon, 20 Jan 2025 10:25:35 +0800 [thread overview]
Message-ID: <20250120-rtc-v1-3-08c50830bac9@nxp.com> (raw)
In-Reply-To: <20250120-rtc-v1-0-08c50830bac9@nxp.com>
From: Peng Fan <peng.fan@nxp.com>
Current users of rtc_class_ops->x are using 'rtc->dev.parent', so
there is no way for rtc drivers get rtc private information. Take
i.MX95 for example, i.MX95 SCMI BBM Protocol supports two RTCs
for i.MX95 EVK board. Using 'rtc->dev.parent' causing driver not
not able to know the exact RTC device. So introduce 'priv' and
devm_rtc_allocate_device_priv for driver to set rtc device private
information.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/rtc/class.c | 9 ++++++++-
drivers/rtc/dev.c | 8 +++++---
drivers/rtc/interface.c | 16 ++++++++--------
drivers/rtc/proc.c | 2 +-
include/linux/rtc.h | 2 ++
5 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index e31fa0ad127e9545afac745a621d4ccbcd5fca28..67413600785d806fe4da441483ce1280357d8791 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -361,7 +361,7 @@ static void devm_rtc_release_device(void *res)
put_device(&rtc->dev);
}
-struct rtc_device *devm_rtc_allocate_device(struct device *dev)
+struct rtc_device *devm_rtc_allocate_device_priv(struct device *dev, void *priv)
{
struct rtc_device *rtc;
int id, err;
@@ -378,6 +378,7 @@ struct rtc_device *devm_rtc_allocate_device(struct device *dev)
rtc->id = id;
rtc->dev.parent = dev;
+ rtc->priv = priv;
err = devm_add_action_or_reset(dev, devm_rtc_release_device, rtc);
if (err)
return ERR_PTR(err);
@@ -388,6 +389,12 @@ struct rtc_device *devm_rtc_allocate_device(struct device *dev)
return rtc;
}
+EXPORT_SYMBOL_GPL(devm_rtc_allocate_device_priv);
+
+struct rtc_device *devm_rtc_allocate_device(struct device *dev)
+{
+ return devm_rtc_allocate_device_priv(dev, NULL);
+}
EXPORT_SYMBOL_GPL(devm_rtc_allocate_device);
int __devm_rtc_register_device(struct module *owner, struct rtc_device *rtc)
diff --git a/drivers/rtc/dev.c b/drivers/rtc/dev.c
index c4a3ab53dcd4b7280a3a2981fe842729603a1feb..e0e1a488b795645d7c9453490d6cdba510cc5db5 100644
--- a/drivers/rtc/dev.c
+++ b/drivers/rtc/dev.c
@@ -410,7 +410,8 @@ static long rtc_dev_ioctl(struct file *file,
}
default:
if (rtc->ops->param_get)
- err = rtc->ops->param_get(rtc->dev.parent, ¶m);
+ err = rtc->ops->param_get(rtc->priv ?
+ &rtc->dev : rtc->dev.parent, ¶m);
else
err = -EINVAL;
}
@@ -440,7 +441,8 @@ static long rtc_dev_ioctl(struct file *file,
default:
if (rtc->ops->param_set)
- err = rtc->ops->param_set(rtc->dev.parent, ¶m);
+ err = rtc->ops->param_set(rtc->priv ?
+ &rtc->dev : rtc->dev.parent, ¶m);
else
err = -EINVAL;
}
@@ -450,7 +452,7 @@ static long rtc_dev_ioctl(struct file *file,
default:
/* Finally try the driver's ioctl interface */
if (ops->ioctl) {
- err = ops->ioctl(rtc->dev.parent, cmd, arg);
+ err = ops->ioctl(rtc->priv ? &rtc->dev : rtc->dev.parent, cmd, arg);
if (err == -ENOIOCTLCMD)
err = -ENOTTY;
} else {
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index aaf76406cd7d7d2cfd5479fc1fc892fcb5efbb6b..06d51761900ee5d6cc3916d31d907505c193c6ad 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -91,7 +91,7 @@ static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
err = -EINVAL;
} else {
memset(tm, 0, sizeof(struct rtc_time));
- err = rtc->ops->read_time(rtc->dev.parent, tm);
+ err = rtc->ops->read_time(rtc->priv ? &rtc->dev : rtc->dev.parent, tm);
if (err < 0) {
dev_dbg(&rtc->dev, "read_time: fail to read: %d\n",
err);
@@ -155,7 +155,7 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
if (!rtc->ops)
err = -ENODEV;
else if (rtc->ops->set_time)
- err = rtc->ops->set_time(rtc->dev.parent, tm);
+ err = rtc->ops->set_time(rtc->priv ? &rtc->dev : rtc->dev.parent, tm);
else
err = -EINVAL;
@@ -200,7 +200,7 @@ static int rtc_read_alarm_internal(struct rtc_device *rtc,
alarm->time.tm_wday = -1;
alarm->time.tm_yday = -1;
alarm->time.tm_isdst = -1;
- err = rtc->ops->read_alarm(rtc->dev.parent, alarm);
+ err = rtc->ops->read_alarm(rtc->priv ? &rtc->dev : rtc->dev.parent, alarm);
}
mutex_unlock(&rtc->ops_lock);
@@ -441,7 +441,7 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
else if (!test_bit(RTC_FEATURE_ALARM, rtc->features))
err = -EINVAL;
else
- err = rtc->ops->set_alarm(rtc->dev.parent, alarm);
+ err = rtc->ops->set_alarm(rtc->priv ? &rtc->dev : rtc->dev.parent, alarm);
trace_rtc_set_alarm(rtc_tm_to_time64(&alarm->time), err);
return err;
@@ -545,7 +545,7 @@ int rtc_alarm_irq_enable(struct rtc_device *rtc, unsigned int enabled)
else if (!test_bit(RTC_FEATURE_ALARM, rtc->features) || !rtc->ops->alarm_irq_enable)
err = -EINVAL;
else
- err = rtc->ops->alarm_irq_enable(rtc->dev.parent, enabled);
+ err = rtc->ops->alarm_irq_enable(rtc->priv ? &rtc->dev : rtc->dev.parent, enabled);
mutex_unlock(&rtc->ops_lock);
@@ -847,7 +847,7 @@ static void rtc_alarm_disable(struct rtc_device *rtc)
if (!rtc->ops || !test_bit(RTC_FEATURE_ALARM, rtc->features) || !rtc->ops->alarm_irq_enable)
return;
- rtc->ops->alarm_irq_enable(rtc->dev.parent, false);
+ rtc->ops->alarm_irq_enable(rtc->priv ? &rtc->dev : rtc->dev.parent, false);
trace_rtc_alarm_irq_enable(0, 0);
}
@@ -1049,7 +1049,7 @@ int rtc_read_offset(struct rtc_device *rtc, long *offset)
return -EINVAL;
mutex_lock(&rtc->ops_lock);
- ret = rtc->ops->read_offset(rtc->dev.parent, offset);
+ ret = rtc->ops->read_offset(rtc->priv ? &rtc->dev : rtc->dev.parent, offset);
mutex_unlock(&rtc->ops_lock);
trace_rtc_read_offset(*offset, ret);
@@ -1084,7 +1084,7 @@ int rtc_set_offset(struct rtc_device *rtc, long offset)
return -EINVAL;
mutex_lock(&rtc->ops_lock);
- ret = rtc->ops->set_offset(rtc->dev.parent, offset);
+ ret = rtc->ops->set_offset(rtc->priv ? &rtc->dev : rtc->dev.parent, offset);
mutex_unlock(&rtc->ops_lock);
trace_rtc_set_offset(offset, ret);
diff --git a/drivers/rtc/proc.c b/drivers/rtc/proc.c
index cbcdbb19d848e78e6674bd626833151a99773ef0..94cc4f9d62b7867018d876f7933468fbd1552ffc 100644
--- a/drivers/rtc/proc.c
+++ b/drivers/rtc/proc.c
@@ -73,7 +73,7 @@ static int rtc_proc_show(struct seq_file *seq, void *offset)
seq_printf(seq, "24hr\t\t: yes\n");
if (ops->proc)
- ops->proc(rtc->dev.parent, seq);
+ ops->proc(rtc->priv ? &rtc->dev : rtc->dev.parent, seq);
return 0;
}
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 3f4d315aaec9e641e35c1c86a522f2879bec19ba..a6f3c86a08e1e214062b2a68d9a6a437afb186b3 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -110,6 +110,7 @@ struct rtc_device {
struct hrtimer pie_timer; /* sub second exp, so needs hrtimer */
int pie_enabled;
struct work_struct irqwork;
+ void *priv;
/*
* This offset specifies the update timing of the RTC.
@@ -182,6 +183,7 @@ extern struct rtc_device *devm_rtc_device_register(struct device *dev,
const struct rtc_class_ops *ops,
struct module *owner);
struct rtc_device *devm_rtc_allocate_device(struct device *dev);
+struct rtc_device *devm_rtc_allocate_device_priv(struct device *dev, void *priv);
int __devm_rtc_register_device(struct module *owner, struct rtc_device *rtc);
extern int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm);
--
2.37.1
next prev parent reply other threads:[~2025-01-20 2:26 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-20 2:25 [PATCH 0/4] rtc/scmi: Support multiple RTCs Peng Fan (OSS)
2025-01-20 2:25 ` [PATCH 1/4] firmware: arm_scmi: imx: Support more event sources Peng Fan (OSS)
2025-01-20 2:25 ` [PATCH 2/4] firmware: arm_scmi: imx: Introduce bbm_info hook Peng Fan (OSS)
2025-01-20 2:25 ` Peng Fan (OSS) [this message]
2025-01-20 10:57 ` [PATCH 3/4] rtc: Introduce devm_rtc_allocate_device_priv Dan Carpenter
2025-01-21 14:35 ` Peng Fan
2025-01-21 15:15 ` Dan Carpenter
2025-01-20 2:25 ` [PATCH 4/4] rtc: imx-sm-bbm: Support multiple RTCs Peng Fan (OSS)
2025-02-11 17:01 ` Sudeep Holla
2025-02-12 6:41 ` Peng Fan
2025-02-12 10:44 ` Sudeep Holla
2025-01-20 10:21 ` [PATCH 0/4] rtc/scmi: " Alexandre Belloni
2025-01-21 14:31 ` Peng Fan
2025-02-03 11:50 ` Peng Fan
2025-02-11 16:59 ` Sudeep Holla
2025-02-12 6:35 ` Peng Fan
2025-02-12 10:43 ` Sudeep Holla
2025-02-12 17:01 ` Alexandre Belloni
2025-02-13 3:30 ` Peng Fan
2025-02-13 8:20 ` Alexandre Belloni
2025-02-13 10:52 ` Peng Fan
2025-02-13 11:26 ` Alexandre Belloni
2025-02-13 13:35 ` Peng Fan
2025-02-13 12:54 ` Alexandre Belloni
2025-02-14 3:55 ` Peng Fan
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=20250120-rtc-v1-3-08c50830bac9@nxp.com \
--to=peng.fan@oss.nxp.com \
--cc=alexandre.belloni@bootlin.com \
--cc=arm-scmi@vger.kernel.org \
--cc=cristian.marussi@arm.com \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=peng.fan@nxp.com \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=sudeep.holla@arm.com \
/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