From: Jonathan Lemon <jonathan.lemon@gmail.com>
To: netdev@vger.kernel.org
Cc: richardcochran@gmail.com, davem@davemloft.net, kuba@kernel.org,
kernel-team@fb.com
Subject: [PATCH net-next 3/5] ptp: ocp: add tod_correction attribute
Date: Wed, 2 Mar 2022 13:34:57 -0800 [thread overview]
Message-ID: <20220302213459.6565-4-jonathan.lemon@gmail.com> (raw)
In-Reply-To: <20220302213459.6565-1-jonathan.lemon@gmail.com>
From: Vadim Fedorenko <vadfed@fb.com>
TOD correction register is used to compensate for leap seconds in
different domains. Export it as an attribute with write access.
Signed-off-by: Vadim Fedorenko <vadfed@fb.com>
Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>
---
drivers/ptp/ptp_ocp.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 803b67a3659a..2a3384c9e3b8 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -1988,6 +1988,46 @@ clock_status_offset_show(struct device *dev,
}
static DEVICE_ATTR_RO(clock_status_offset);
+static ssize_t
+tod_correction_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct ptp_ocp *bp = dev_get_drvdata(dev);
+ u32 val;
+ int res;
+
+ val = ioread32(&bp->tod->adj_sec);
+ res = (val & ~INT_MAX) ? -1 : 1;
+ res *= (val & INT_MAX);
+ return sysfs_emit(buf, "%d\n", res);
+}
+
+static ssize_t
+tod_correction_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct ptp_ocp *bp = dev_get_drvdata(dev);
+ unsigned long flags;
+ int err, res;
+ u32 val = 0;
+
+ err = kstrtos32(buf, 0, &res);
+ if (err)
+ return err;
+ if (res < 0) {
+ res *= -1;
+ val |= BIT(31);
+ }
+ val |= res;
+
+ spin_lock_irqsave(&bp->lock, flags);
+ iowrite32(val, &bp->tod->adj_sec);
+ spin_unlock_irqrestore(&bp->lock, flags);
+
+ return count;
+}
+static DEVICE_ATTR_RW(tod_correction);
+
static struct attribute *timecard_attrs[] = {
&dev_attr_serialnum.attr,
&dev_attr_gnss_sync.attr,
@@ -2004,6 +2044,7 @@ static struct attribute *timecard_attrs[] = {
&dev_attr_irig_b_mode.attr,
&dev_attr_utc_tai_offset.attr,
&dev_attr_ts_window_adjust.attr,
+ &dev_attr_tod_correction.attr,
NULL,
};
ATTRIBUTE_GROUPS(timecard);
--
2.31.1
next prev parent reply other threads:[~2022-03-02 21:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-02 21:34 [PATCH net-next 0/5] ptp: ocp: TOD and monitoring updates Jonathan Lemon
2022-03-02 21:34 ` [PATCH net-next 1/5] ptp: ocp: add TOD debug information Jonathan Lemon
2022-03-02 21:34 ` [PATCH net-next 2/5] ptp: ocp: Expose clock status drift and offset Jonathan Lemon
2022-03-02 21:34 ` Jonathan Lemon [this message]
2022-03-02 21:34 ` [PATCH net-next 4/5] ptp: ocp: adjust utc_tai_offset to TOD info Jonathan Lemon
2022-03-02 21:34 ` [PATCH net-next 5/5] docs: ABI: Document new timecard sysfs nodes Jonathan Lemon
2022-03-03 14:50 ` [PATCH net-next 0/5] ptp: ocp: TOD and monitoring updates patchwork-bot+netdevbpf
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=20220302213459.6565-4-jonathan.lemon@gmail.com \
--to=jonathan.lemon@gmail.com \
--cc=davem@davemloft.net \
--cc=kernel-team@fb.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.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 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.