Message ID | 20210830235236.309993-9-jonathan.lemon@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | ocp timecard updates | expand |
Context | Check | Description |
---|---|---|
netdev/cover_letter | success | Link |
netdev/fixes_present | success | Link |
netdev/patch_count | success | Link |
netdev/tree_selection | success | Clearly marked for net-next |
netdev/subject_prefix | success | Link |
netdev/cc_maintainers | success | CCed 3 of 3 maintainers |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Link |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 0 this patch: 0 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | Link |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 57 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 0 this patch: 0 |
netdev/header_inline | success | Link |
On Mon, 30 Aug 2021 16:52:33 -0700 Jonathan Lemon wrote: > +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); > + unsigned long flags; > + int err; > + s32 val; > + > + err = kstrtos32(buf, 0, &val); > + if (err) > + return err; > + > + bp->utc_tai_offset = val; This line should probably be under the lock. > + spin_lock_irqsave(&bp->lock, flags); > + iowrite32(val, &bp->irig_out->adj_sec); > + iowrite32(val, &bp->dcf_out->adj_sec); > + spin_unlock_irqrestore(&bp->lock, flags); > + > + return count; > +} > +static DEVICE_ATTR_RW(utc_tai_offset);
On Wed, Sep 01, 2021 at 04:56:42PM -0700, Jakub Kicinski wrote: > On Mon, 30 Aug 2021 16:52:33 -0700 Jonathan Lemon wrote: > > +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); > > + unsigned long flags; > > + int err; > > + s32 val; > > + > > + err = kstrtos32(buf, 0, &val); > > + if (err) > > + return err; > > + > > + bp->utc_tai_offset = val; > > This line should probably be under the lock. Ack. BTW, I hate this entire function - but don't really see a better way to handle it. One suggestion was to automatically get the offset from the NMEA parser, but I can't depend on GNSS being available.
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index fceeee380d9f..093385c6fed0 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; + s32 utc_tai_offset; }; struct ocp_resource { @@ -1592,6 +1593,40 @@ available_sma_outputs_show(struct device *dev, } static DEVICE_ATTR_RO(available_sma_outputs); +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); + unsigned long flags; + int err; + s32 val; + + err = kstrtos32(buf, 0, &val); + if (err) + return err; + + bp->utc_tai_offset = val; + + spin_lock_irqsave(&bp->lock, flags); + iowrite32(val, &bp->irig_out->adj_sec); + iowrite32(val, &bp->dcf_out->adj_sec); + spin_unlock_irqrestore(&bp->lock, flags); + + return count; +} +static DEVICE_ATTR_RW(utc_tai_offset); + static ssize_t clock_source_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -1644,6 +1679,7 @@ static struct attribute *timecard_attrs[] = { &dev_attr_sma4_in.attr, &dev_attr_available_sma_inputs.attr, &dev_attr_available_sma_outputs.attr, + &dev_attr_utc_tai_offset.attr, NULL, }; ATTRIBUTE_GROUPS(timecard);
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> --- drivers/ptp/ptp_ocp.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)