diff options
author | Jonathan Lemon <jonathan.lemon@gmail.com> | 2021-09-15 04:16:28 +0200 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-09-15 12:10:01 +0200 |
commit | 89260d878253f44bdbb76bcfe18e4a237b0d9d1a (patch) | |
tree | 45b4b141053425dfa56a50832c2a30fa94b9d797 /drivers/ptp | |
parent | ptp: ocp: Add IRIG-B output mode control (diff) | |
download | linux-89260d878253f44bdbb76bcfe18e4a237b0d9d1a.tar.xz linux-89260d878253f44bdbb76bcfe18e4a237b0d9d1a.zip |
ptp: ocp: Add sysfs attribute utc_tai_offset
IRIG and DCF output time in UTC, but the timecard operates
on TAI internally. Add an attribute node which allows adding
an offset to these modes before output.
Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/ptp')
-rw-r--r-- | drivers/ptp/ptp_ocp.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index 2b3d4282d77a..2c3af3c9def7 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -230,8 +230,9 @@ struct ptp_ocp { int gnss_port; int mac_port; /* miniature atomic clock */ u8 serial[6]; - int flash_start; bool has_serial; + int flash_start; + u32 utc_tai_offset; }; struct ocp_resource { @@ -742,6 +743,23 @@ ptp_ocp_init_clock(struct ptp_ocp *bp) } static void +ptp_ocp_utc_distribute(struct ptp_ocp *bp, u32 val) +{ + unsigned long flags; + + spin_lock_irqsave(&bp->lock, flags); + + bp->utc_tai_offset = val; + + if (bp->irig_out) + iowrite32(val, &bp->irig_out->adj_sec); + if (bp->dcf_out) + iowrite32(val, &bp->dcf_out->adj_sec); + + spin_unlock_irqrestore(&bp->lock, flags); +} + +static void ptp_ocp_tod_info(struct ptp_ocp *bp) { static const char * const proto_name[] = { @@ -1677,6 +1695,34 @@ gnss_sync_show(struct device *dev, struct device_attribute *attr, char *buf) static DEVICE_ATTR_RO(gnss_sync); static ssize_t +utc_tai_offset_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct ptp_ocp *bp = dev_get_drvdata(dev); + + return sysfs_emit(buf, "%d\n", bp->utc_tai_offset); +} + +static ssize_t +utc_tai_offset_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct ptp_ocp *bp = dev_get_drvdata(dev); + int err; + u32 val; + + err = kstrtou32(buf, 0, &val); + if (err) + return err; + + ptp_ocp_utc_distribute(bp, val); + + return count; +} +static DEVICE_ATTR_RW(utc_tai_offset); + +static ssize_t irig_b_mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct ptp_ocp *bp = dev_get_drvdata(dev); @@ -1769,6 +1815,7 @@ static struct attribute *timecard_attrs[] = { &dev_attr_available_sma_inputs.attr, &dev_attr_available_sma_outputs.attr, &dev_attr_irig_b_mode.attr, + &dev_attr_utc_tai_offset.attr, NULL, }; ATTRIBUTE_GROUPS(timecard); |