Commit 3465f98f authored by Alessandro Rubini's avatar Alessandro Rubini

fd-zio: handle a negative coarse readout

parent 972b0f68
......@@ -441,6 +441,19 @@ static int fd_read_fifo(struct spec_fd *fd, struct zio_channel *chan)
t.channel = FD_TSBR_FID_CHANNEL_R(reg);
t.seq_id = FD_TSBR_FID_SEQID_R(reg);
/* The coarse count may be negative, because of how it works */
if (t.coarse & (1<<27)) { // coarse is 28 bits
printk("%i (%x)\n", t.coarse, t.coarse);
/* we may get 0xfff.ffef..0xffff.ffff -- 125M == 0x773.5940 */
t.coarse += 125000000;
t.coarse &= 0xfffffff;
t.utc--;
} else if(t.coarse > 125000000) {
printk("%i (%x)\n", t.coarse, t.coarse);
t.coarse -= 125000000;
t.utc++;
}
fd_ts_sub(&t, fd->calib.tdc_zero_offset);
/* The input data is written to attribute values in the active block. */
......@@ -454,6 +467,8 @@ static int fd_read_fifo(struct spec_fd *fd, struct zio_channel *chan)
v[FD_ATTR_TDC_CHAN] = t.channel;
v[FD_ATTR_TDC_OFFSET] = fd->calib.tdc_zero_offset;
__fd_apply_offset(v + FD_ATTR_TDC_UTC_H, fd->calib.tdc_user_offset);
/* We also need a copy within the device, so sysfs can read it */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment