Commit 662a3834 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

kernel: various fixes:

- time setting (TAI/host)
- proper buffer purge after disabling acquisition
- removed nested spinlock if ft_enable_acquisition()
parent 3b148ac5
......@@ -222,6 +222,8 @@ void ft_irq_exit(struct fmctdc_dev *ft);
int ft_time_init(struct fmctdc_dev *ft);
void ft_time_exit(struct fmctdc_dev *ft);
void ft_zio_kill_buffer(struct fmctdc_dev *ft, int channel);
int ft_zio_register(void);
void ft_zio_unregister(void);
int ft_zio_init(struct fmctdc_dev *ft);
......
......@@ -70,15 +70,18 @@ static int ft_init_channel(struct fmctdc_dev *ft, int channel)
return 0;
}
static void ft_purge_fifo(struct fmctdc_dev *ft, int channel)
static void ft_reset_channel (struct fmctdc_dev *ft, int channel)
{
struct ft_channel_state *st = &ft->channels[channel - 1];
struct ft_channel_state *st = &ft->channels[channel - FT_CH_1];
spin_lock(&ft->lock);
st->fifo.head = 0;
st->fifo.tail = 0;
st->fifo.count = 0;
spin_unlock(&ft->lock);
st->cur_seq_id = 0;
st->expected_edge = 1;
clear_bit(FT_FLAG_CH_INPUT_READY, &st->flags);
ft_zio_kill_buffer( ft, channel );
}
int ft_enable_termination(struct fmctdc_dev *ft, int channel, int enable)
......@@ -124,18 +127,31 @@ void ft_enable_acquisition(struct fmctdc_dev *ft, int enable)
} else {
ien &= ~TDC_INPUT_ENABLE_FLAG;
cmd = TDC_CTRL_DIS_ACQ;
for (i = FT_CH_1; i <= FT_NUM_CHANNELS; i++)
ft_purge_fifo(ft, i);
}
spin_lock (&ft->lock);
ft_writel(ft, ien, TDC_REG_INPUT_ENABLE);
ft_writel(ft, TDC_CTRL_CLEAR_DACAPO_FLAG, TDC_REG_CTRL);
ft_writel(ft, cmd, TDC_REG_CTRL);
ft->acquisition_on = enable;
if(!enable)
{
/* when disabling acquisition, clear the FIFOs, reset width validation state
machine and sequence IDs */
for (i = FT_CH_1; i <= FT_NUM_CHANNELS; i++)
ft_reset_channel( ft, i);
ft->prev_wr_ptr = ft->cur_wr_ptr = 0;
}
spin_unlock (&ft->lock);
if(ft->verbose)
dev_info(&ft->fmc->dev, "acuqisition is %s\n", enable ? "on" : "off");
dev_info(&ft->fmc->dev, "acquisition is %s\n", enable ? "on" : "off");
}
static int ft_channels_init(struct fmctdc_dev *ft)
......
......@@ -54,6 +54,7 @@ int ft_read_sw_fifo(struct fmctdc_dev *ft, int channel,
if (st->fifo.tail == st->fifo.size)
st->fifo.tail = 0;
st->fifo.count--;
spin_unlock_irqrestore(&ft->lock, flags);
/* Write the timestamp in the trigger, it will reach the control */
......
......@@ -95,7 +95,7 @@ int ft_set_tai_time(struct fmctdc_dev *ft, uint64_t seconds, uint32_t coarse)
if(coarse != 0)
dev_warn(&ft->fmc->dev, "Warning: ignoring sub-second part (%d) when setting time.\n", coarse);
ft_writel(ft, seconds & 0xffffffff, TDC_REG_CURRENT_UTC);
ft_writel(ft, seconds & 0xffffffff, TDC_REG_START_UTC);
ft_writel(ft, TDC_CTRL_LOAD_UTC, TDC_REG_CTRL);
return 0;
}
......@@ -116,7 +116,9 @@ int ft_set_host_time (struct fmctdc_dev *ft)
return -EAGAIN;
getnstimeofday(&local_ts);
ft_writel(ft, local_ts.tv_sec & 0xffffffff, TDC_REG_CURRENT_UTC);
ft_writel(ft, local_ts.tv_sec & 0xffffffff, TDC_REG_START_UTC);
ft_writel(ft, TDC_CTRL_LOAD_UTC, TDC_REG_CTRL);
return 0;
}
......
......@@ -71,6 +71,11 @@ static enum ft_devtype __ft_get_type(struct device *dev)
return FT_TYPE_INPUT;
}
void ft_zio_kill_buffer(struct fmctdc_dev *ft, int channel)
{
zio_trigger_abort_disable( &ft->zdev->cset [ channel - FT_CH_1 ], 0);
}
/* TDC input attributes: only the user offset is special */
static int ft_zio_info_channel(struct device *dev, struct zio_attribute *zattr,
uint32_t * usr_val)
......@@ -111,7 +116,6 @@ static int ft_zio_info_get(struct device *dev, struct zio_attribute *zattr,
if (__ft_get_type(dev) == FT_TYPE_INPUT)
return ft_zio_info_channel(dev, zattr, usr_val);
/* reading temperature */
zdev = to_zio_dev(dev);
attr = zdev->zattr_set.ext_zattr;
ft = zdev->priv_d;
......@@ -121,8 +125,10 @@ static int ft_zio_info_get(struct device *dev, struct zio_attribute *zattr,
return 0;
case FT_ATTR_DEV_TEMP:
if (ft->temp_ready) {
attr[FT_ATTR_DEV_TEMP].value = ft->temp;
*usr_val = ft->temp;
return 0;
} else
return -EAGAIN;
......@@ -135,13 +141,17 @@ static int ft_zio_info_get(struct device *dev, struct zio_attribute *zattr,
if (ft_get_tai_time(ft, &seconds, &coarse) < 0)
return -EAGAIN;
attr[FT_ATTR_DEV_COARSE].value = coarse;
attr[FT_ATTR_DEV_SECONDS].value = (uint32_t) seconds;
*usr_val = (zattr->id == FT_ATTR_DEV_COARSE ? coarse : (uint32_t) seconds);
return 0;
}
case FT_ATTR_DEV_ENABLE_INPUTS:
attr[FT_ATTR_DEV_ENABLE_INPUTS].value =
ft->acquisition_on ? 1 : 0;
*usr_val = ft->acquisition_on ? 1 : 0;
return 0;
}
return -EINVAL;
......@@ -197,11 +207,12 @@ static int ft_zio_input(struct zio_cset *cset)
/* Ready for input. If there's already something, return it now */
if (ft_read_sw_fifo(ft, cset->index + 1, cset->chan) == 0) {
return 0; /* don't call data_done, let the caller do it */
return 0; /* don't call data_done, let the caller do it */
}
/* Mark the active block is valid, and return EAGAIN */
set_bit(FT_FLAG_CH_INPUT_READY, &st->flags);
set_bit(FT_FLAG_CH_INPUT_READY, &st->flags);
return -EAGAIN;
}
......@@ -221,15 +232,19 @@ static int ft_zio_conf_set(struct device *dev, struct zio_attribute *zattr,
attr = zdev->zattr_set.ext_zattr;
ft = zdev->priv_d;
printk("conf-set: zattr %lu val %u\n", zattr->id, zattr->value);
if (zattr->id == FT_ATTR_DEV_SECONDS) {
return ft_set_tai_time( ft, attr[FT_ATTR_DEV_SECONDS].value,
attr[FT_ATTR_DEV_SECONDS].value = usr_val;
return ft_set_tai_time( ft,
attr[FT_ATTR_DEV_SECONDS].value,
attr[FT_ATTR_DEV_COARSE].value
);
return -ENOTSUPP;
} else if (zattr->id == FT_ATTR_DEV_ENABLE_INPUTS)
ft_enable_acquisition(ft, zattr->value);
} else if (zattr->id == FT_ATTR_DEV_ENABLE_INPUTS) {
attr[FT_ATTR_DEV_ENABLE_INPUTS].value = usr_val ? 1 : 0;
ft_enable_acquisition(ft, usr_val);
}
/* Not command, nothing to do */
if (zattr->id != FT_ATTR_DEV_COMMAND)
......
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