Skip to content

Commit

Permalink
ptp: ocp: Add sysfs attribute utc_tai_offset
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jlemon authored and davem330 committed Sep 15, 2021
1 parent d14ee25 commit 89260d8
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion drivers/ptp/ptp_ocp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -741,6 +742,23 @@ ptp_ocp_init_clock(struct ptp_ocp *bp)
return 0;
}

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)
{
Expand Down Expand Up @@ -1676,6 +1694,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)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 89260d8

Please sign in to comment.