Commit d7352716 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

kernel, lib: reindented code according to kernel style

parent f813f1e7
...@@ -56,18 +56,18 @@ enum ft_zattr_in_idx { ...@@ -56,18 +56,18 @@ enum ft_zattr_in_idx {
}; };
enum ft_command { enum ft_command {
FT_CMD_WR_ENABLE = 0, /* Enable White Rabbit */ FT_CMD_WR_ENABLE = 0, /* Enable White Rabbit */
FT_CMD_WR_DISABLE, /* Disable it */ FT_CMD_WR_DISABLE, /* Disable it */
FT_CMD_WR_QUERY, /* Check if WR is locked */ FT_CMD_WR_QUERY, /* Check if WR is locked */
FT_CMD_SET_HOST_TIME, /* Set board time to current host time */ FT_CMD_SET_HOST_TIME, /* Set board time to current host time */
FT_CMD_IDENTIFY_ON, /* Identify card by blinking status LEDs, reserved for future use. */ FT_CMD_IDENTIFY_ON, /* Identify card by blinking status LEDs, reserved for future use. */
FT_CMD_IDENTIFY_OFF FT_CMD_IDENTIFY_OFF
}; };
/* rest of the file is kernel-only */ /* rest of the file is kernel-only */
#ifdef __KERNEL__ #ifdef __KERNEL__
#define FT_USER_OFFSET_RANGE 1000000000 /* picoseconds */ #define FT_USER_OFFSET_RANGE 1000000000 /* picoseconds */
enum ft_channel_flags { enum ft_channel_flags {
FT_FLAG_CH_TERMINATED = 0, FT_FLAG_CH_TERMINATED = 0,
...@@ -209,7 +209,7 @@ void ft_ts_sub(struct ft_wr_timestamp *a, struct ft_wr_timestamp *b); ...@@ -209,7 +209,7 @@ void ft_ts_sub(struct ft_wr_timestamp *a, struct ft_wr_timestamp *b);
int ft_set_tai_time(struct fmctdc_dev *ft, uint64_t seconds, uint32_t coarse); int ft_set_tai_time(struct fmctdc_dev *ft, uint64_t seconds, uint32_t coarse);
int ft_get_tai_time(struct fmctdc_dev *ft, uint64_t * seconds, int ft_get_tai_time(struct fmctdc_dev *ft, uint64_t * seconds,
uint32_t * coarse); uint32_t * coarse);
int ft_set_host_time (struct fmctdc_dev *ft); int ft_set_host_time(struct fmctdc_dev *ft);
int ft_enable_wr_mode(struct fmctdc_dev *ft, int enable); int ft_enable_wr_mode(struct fmctdc_dev *ft, int enable);
int ft_check_wr_mode(struct fmctdc_dev *ft); int ft_check_wr_mode(struct fmctdc_dev *ft);
......
...@@ -70,7 +70,7 @@ static int ft_init_channel(struct fmctdc_dev *ft, int channel) ...@@ -70,7 +70,7 @@ static int ft_init_channel(struct fmctdc_dev *ft, int channel)
return 0; return 0;
} }
static void ft_reset_channel (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 - FT_CH_1]; struct ft_channel_state *st = &ft->channels[channel - FT_CH_1];
...@@ -81,7 +81,7 @@ static void ft_reset_channel (struct fmctdc_dev *ft, int channel) ...@@ -81,7 +81,7 @@ static void ft_reset_channel (struct fmctdc_dev *ft, int channel)
st->cur_seq_id = 0; st->cur_seq_id = 0;
st->expected_edge = 1; st->expected_edge = 1;
clear_bit(FT_FLAG_CH_INPUT_READY, &st->flags); clear_bit(FT_FLAG_CH_INPUT_READY, &st->flags);
ft_zio_kill_buffer( ft, channel ); ft_zio_kill_buffer(ft, channel);
} }
int ft_enable_termination(struct fmctdc_dev *ft, int channel, int enable) int ft_enable_termination(struct fmctdc_dev *ft, int channel, int enable)
...@@ -116,8 +116,8 @@ void ft_enable_acquisition(struct fmctdc_dev *ft, int enable) ...@@ -116,8 +116,8 @@ void ft_enable_acquisition(struct fmctdc_dev *ft, int enable)
uint32_t ien, cmd; uint32_t ien, cmd;
int i; int i;
if (ft->acquisition_on == ( enable ? 1: 0 )) if (ft->acquisition_on == (enable ? 1 : 0))
return; return;
ien = ft_readl(ft, TDC_REG_INPUT_ENABLE); ien = ft_readl(ft, TDC_REG_INPUT_ENABLE);
...@@ -129,7 +129,7 @@ void ft_enable_acquisition(struct fmctdc_dev *ft, int enable) ...@@ -129,7 +129,7 @@ void ft_enable_acquisition(struct fmctdc_dev *ft, int enable)
cmd = TDC_CTRL_DIS_ACQ; cmd = TDC_CTRL_DIS_ACQ;
} }
spin_lock (&ft->lock); spin_lock(&ft->lock);
ft_writel(ft, ien, TDC_REG_INPUT_ENABLE); ft_writel(ft, ien, TDC_REG_INPUT_ENABLE);
ft_writel(ft, TDC_CTRL_CLEAR_DACAPO_FLAG, TDC_REG_CTRL); ft_writel(ft, TDC_CTRL_CLEAR_DACAPO_FLAG, TDC_REG_CTRL);
...@@ -137,21 +137,21 @@ void ft_enable_acquisition(struct fmctdc_dev *ft, int enable) ...@@ -137,21 +137,21 @@ void ft_enable_acquisition(struct fmctdc_dev *ft, int enable)
ft->acquisition_on = enable; ft->acquisition_on = enable;
if(!enable) if (!enable) {
{ /* when disabling acquisition, clear the FIFOs, reset width validation state
/* when disabling acquisition, clear the FIFOs, reset width validation state machine and sequence IDs */
machine and sequence IDs */
for (i = FT_CH_1; i <= FT_NUM_CHANNELS; i++) for (i = FT_CH_1; i <= FT_NUM_CHANNELS; i++)
ft_reset_channel( ft, i); ft_reset_channel(ft, i);
ft->prev_wr_ptr = ft->cur_wr_ptr = 0; ft->prev_wr_ptr = ft->cur_wr_ptr = 0;
} }
spin_unlock (&ft->lock); spin_unlock(&ft->lock);
if(ft->verbose) if (ft->verbose)
dev_info(&ft->fmc->dev, "acquisition 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) static int ft_channels_init(struct fmctdc_dev *ft)
...@@ -335,7 +335,7 @@ int ft_probe(struct fmc_device *fmc) ...@@ -335,7 +335,7 @@ int ft_probe(struct fmc_device *fmc)
ft->initialized = 1; ft->initialized = 1;
return 0; return 0;
err: err:
while (--m, --i >= 0) while (--m, --i >= 0)
if (m->exit) if (m->exit)
m->exit(ft); m->exit(ft);
......
...@@ -153,8 +153,9 @@ static inline void process_timestamp(struct fmctdc_dev *ft, ...@@ -153,8 +153,9 @@ static inline void process_timestamp(struct fmctdc_dev *ft,
(diff.seconds || diff.coarse > 12 (diff.seconds || diff.coarse > 12
|| (diff.coarse == 12 && diff.frac >= 2048))) { || (diff.coarse == 12 && diff.frac >= 2048))) {
ft_ts_apply_offset(&ts, ft_ts_apply_offset(&ts,
ft->calib. ft->
zero_offset[channel - 1]); calib.zero_offset[channel -
1]);
if (st->user_offset) if (st->user_offset)
ft_ts_apply_offset(&ts, ft_ts_apply_offset(&ts,
...@@ -282,7 +283,7 @@ static void ft_readout_tasklet(unsigned long arg) ...@@ -282,7 +283,7 @@ static void ft_readout_tasklet(unsigned long arg)
} }
} }
out: out:
/* ack the irq */ /* ack the irq */
fmc_writel(ft->fmc, TDC_IRQ_TDC_TSTAMP << ft->irq_shift, fmc_writel(ft->fmc, TDC_IRQ_TDC_TSTAMP << ft->irq_shift,
ft->ft_irq_base + TDC_REG_IRQ_STATUS); ft->ft_irq_base + TDC_REG_IRQ_STATUS);
......
...@@ -85,15 +85,17 @@ void ft_ts_apply_offset(struct ft_wr_timestamp *ts, int32_t offset_picos) ...@@ -85,15 +85,17 @@ void ft_ts_apply_offset(struct ft_wr_timestamp *ts, int32_t offset_picos)
int ft_set_tai_time(struct fmctdc_dev *ft, uint64_t seconds, uint32_t coarse) int ft_set_tai_time(struct fmctdc_dev *ft, uint64_t seconds, uint32_t coarse)
{ {
if (ft->acquisition_on) /* can't change time when inputs are enabled */ if (ft->acquisition_on) /* can't change time when inputs are enabled */
return -EAGAIN; return -EAGAIN;
if (ft->verbose) if (ft->verbose)
dev_info(&ft->fmc->dev, "Setting TAI time to %lld:%d\n", dev_info(&ft->fmc->dev, "Setting TAI time to %lld:%d\n",
seconds, coarse); seconds, coarse);
if(coarse != 0) if (coarse != 0)
dev_warn(&ft->fmc->dev, "Warning: ignoring sub-second part (%d) when setting time.\n", coarse); dev_warn(&ft->fmc->dev,
"Warning: ignoring sub-second part (%d) when setting time.\n",
coarse);
ft_writel(ft, seconds & 0xffffffff, TDC_REG_START_UTC); ft_writel(ft, seconds & 0xffffffff, TDC_REG_START_UTC);
ft_writel(ft, TDC_CTRL_LOAD_UTC, TDC_REG_CTRL); ft_writel(ft, TDC_CTRL_LOAD_UTC, TDC_REG_CTRL);
...@@ -108,12 +110,12 @@ int ft_get_tai_time(struct fmctdc_dev *ft, uint64_t * seconds, ...@@ -108,12 +110,12 @@ int ft_get_tai_time(struct fmctdc_dev *ft, uint64_t * seconds,
return 0; return 0;
} }
int ft_set_host_time (struct fmctdc_dev *ft) int ft_set_host_time(struct fmctdc_dev *ft)
{ {
struct timespec local_ts; struct timespec local_ts;
if (ft->acquisition_on) /* can't change time when inputs are enabled */ if (ft->acquisition_on) /* can't change time when inputs are enabled */
return -EAGAIN; return -EAGAIN;
getnstimeofday(&local_ts); getnstimeofday(&local_ts);
......
...@@ -73,7 +73,7 @@ static enum ft_devtype __ft_get_type(struct device *dev) ...@@ -73,7 +73,7 @@ static enum ft_devtype __ft_get_type(struct device *dev)
void ft_zio_kill_buffer(struct fmctdc_dev *ft, int channel) void ft_zio_kill_buffer(struct fmctdc_dev *ft, int channel)
{ {
zio_trigger_abort_disable( &ft->zdev->cset [ channel - FT_CH_1 ], 0); zio_trigger_abort_disable(&ft->zdev->cset[channel - FT_CH_1], 0);
} }
/* TDC input attributes: only the user offset is special */ /* TDC input attributes: only the user offset is special */
...@@ -145,7 +145,9 @@ static int ft_zio_info_get(struct device *dev, struct zio_attribute *zattr, ...@@ -145,7 +145,9 @@ static int ft_zio_info_get(struct device *dev, struct zio_attribute *zattr,
attr[FT_ATTR_DEV_COARSE].value = coarse; attr[FT_ATTR_DEV_COARSE].value = coarse;
attr[FT_ATTR_DEV_SECONDS].value = (uint32_t) seconds; attr[FT_ATTR_DEV_SECONDS].value = (uint32_t) seconds;
*usr_val = (zattr->id == FT_ATTR_DEV_COARSE ? coarse : (uint32_t) seconds); *usr_val =
(zattr->id ==
FT_ATTR_DEV_COARSE ? coarse : (uint32_t) seconds);
return 0; return 0;
} }
case FT_ATTR_DEV_ENABLE_INPUTS: case FT_ATTR_DEV_ENABLE_INPUTS:
...@@ -176,8 +178,9 @@ static int ft_zio_conf_channel(struct device *dev, struct zio_attribute *zattr, ...@@ -176,8 +178,9 @@ static int ft_zio_conf_channel(struct device *dev, struct zio_attribute *zattr,
case FT_ATTR_TDC_USER_OFFSET: case FT_ATTR_TDC_USER_OFFSET:
user_offs = usr_val; user_offs = usr_val;
if(user_offs < -FT_USER_OFFSET_RANGE || user_offs > FT_USER_OFFSET_RANGE) if (user_offs < -FT_USER_OFFSET_RANGE
return -EINVAL; || user_offs > FT_USER_OFFSET_RANGE)
return -EINVAL;
spin_lock(&ft->lock); spin_lock(&ft->lock);
st->user_offset = usr_val; st->user_offset = usr_val;
spin_unlock(&ft->lock); spin_unlock(&ft->lock);
...@@ -207,12 +210,12 @@ static int ft_zio_input(struct zio_cset *cset) ...@@ -207,12 +210,12 @@ static int ft_zio_input(struct zio_cset *cset)
/* Ready for input. If there's already something, return it now */ /* Ready for input. If there's already something, return it now */
if (ft_read_sw_fifo(ft, cset->index + 1, cset->chan) == 0) { 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 */ /* 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; return -EAGAIN;
} }
...@@ -235,15 +238,14 @@ static int ft_zio_conf_set(struct device *dev, struct zio_attribute *zattr, ...@@ -235,15 +238,14 @@ static int ft_zio_conf_set(struct device *dev, struct zio_attribute *zattr,
if (zattr->id == FT_ATTR_DEV_SECONDS) { if (zattr->id == FT_ATTR_DEV_SECONDS) {
attr[FT_ATTR_DEV_SECONDS].value = usr_val; attr[FT_ATTR_DEV_SECONDS].value = usr_val;
return ft_set_tai_time( ft, return ft_set_tai_time(ft,
attr[FT_ATTR_DEV_SECONDS].value, attr[FT_ATTR_DEV_SECONDS].value,
attr[FT_ATTR_DEV_COARSE].value attr[FT_ATTR_DEV_COARSE].value);
);
return -ENOTSUPP; return -ENOTSUPP;
} else if (zattr->id == FT_ATTR_DEV_ENABLE_INPUTS) { } else if (zattr->id == FT_ATTR_DEV_ENABLE_INPUTS) {
attr[FT_ATTR_DEV_ENABLE_INPUTS].value = usr_val ? 1 : 0; attr[FT_ATTR_DEV_ENABLE_INPUTS].value = usr_val ? 1 : 0;
ft_enable_acquisition(ft, usr_val); ft_enable_acquisition(ft, usr_val);
} }
/* Not command, nothing to do */ /* Not command, nothing to do */
...@@ -252,7 +254,7 @@ static int ft_zio_conf_set(struct device *dev, struct zio_attribute *zattr, ...@@ -252,7 +254,7 @@ static int ft_zio_conf_set(struct device *dev, struct zio_attribute *zattr,
switch (usr_val) { switch (usr_val) {
case FT_CMD_SET_HOST_TIME: case FT_CMD_SET_HOST_TIME:
return ft_set_host_time(ft); return ft_set_host_time(ft);
case FT_CMD_WR_ENABLE: case FT_CMD_WR_ENABLE:
case FT_CMD_WR_DISABLE: case FT_CMD_WR_DISABLE:
case FT_CMD_WR_QUERY: case FT_CMD_WR_QUERY:
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
#define CMD_RECALL_EEPROM 0xB8 #define CMD_RECALL_EEPROM 0xB8
#define CMD_READ_POWER_SUPPLY 0xB4 #define CMD_READ_POWER_SUPPLY 0xB4
#define FT_OW_PORT 0 /* what is this slow? */ #define FT_OW_PORT 0 /* what is this slow? */
static void ow_writel(struct fmctdc_dev *ft, uint32_t val, unsigned long reg) static void ow_writel(struct fmctdc_dev *ft, uint32_t val, unsigned long reg)
{ {
...@@ -69,10 +69,10 @@ static int ow_reset(struct fmctdc_dev *ft, int port) ...@@ -69,10 +69,10 @@ static int ow_reset(struct fmctdc_dev *ft, int port)
uint32_t reg, data; uint32_t reg, data;
data = ((port << CSR_SEL_OFS) & CSR_SEL_MSK) data = ((port << CSR_SEL_OFS) & CSR_SEL_MSK)
| CSR_CYC_MSK | CSR_RST_MSK; | CSR_CYC_MSK | CSR_RST_MSK;
ow_writel(ft, data, R_CSR); ow_writel(ft, data, R_CSR);
while(ow_readl(ft, R_CSR) & CSR_CYC_MSK) while (ow_readl(ft, R_CSR) & CSR_CYC_MSK)
/* FIXME: timeout */; /* FIXME: timeout */ ;
reg = ow_readl(ft, R_CSR); reg = ow_readl(ft, R_CSR);
return ~reg & CSR_DAT_MSK; return ~reg & CSR_DAT_MSK;
} }
...@@ -81,11 +81,11 @@ static int slot(struct fmctdc_dev *ft, int port, int bit) ...@@ -81,11 +81,11 @@ static int slot(struct fmctdc_dev *ft, int port, int bit)
{ {
uint32_t reg, data; uint32_t reg, data;
data = ((port<<CSR_SEL_OFS) & CSR_SEL_MSK) data = ((port << CSR_SEL_OFS) & CSR_SEL_MSK)
| CSR_CYC_MSK | (bit & CSR_DAT_MSK); | CSR_CYC_MSK | (bit & CSR_DAT_MSK);
ow_writel(ft, data, R_CSR); ow_writel(ft, data, R_CSR);
while(ow_readl(ft, R_CSR) & CSR_CYC_MSK) while (ow_readl(ft, R_CSR) & CSR_CYC_MSK)
/* FIXME: timeout */; /* FIXME: timeout */ ;
reg = ow_readl(ft, R_CSR); reg = ow_readl(ft, R_CSR);
return reg & CSR_DAT_MSK; return reg & CSR_DAT_MSK;
} }
...@@ -104,7 +104,7 @@ static int ow_read_byte(struct fmctdc_dev *ft, int port) ...@@ -104,7 +104,7 @@ static int ow_read_byte(struct fmctdc_dev *ft, int port)
{ {
int byte = 0, i; int byte = 0, i;
for(i = 0; i < 8; i++) for (i = 0; i < 8; i++)
byte |= (read_bit(ft, port) << i); byte |= (read_bit(ft, port) << i);
return byte; return byte;
} }
...@@ -114,34 +114,37 @@ static int ow_write_byte(struct fmctdc_dev *ft, int port, int byte) ...@@ -114,34 +114,37 @@ static int ow_write_byte(struct fmctdc_dev *ft, int port, int byte)
int data = 0; int data = 0;
int i; int i;
for (i = 0; i < 8; i++){ for (i = 0; i < 8; i++) {
data |= write_bit(ft, port, (byte & 0x1)) << i; data |= write_bit(ft, port, (byte & 0x1)) << i;
byte >>= 1; byte >>= 1;
} }
return 0; /* success */ return 0; /* success */
} }
static int ow_write_block(struct fmctdc_dev *ft, int port, uint8_t *block, int len) static int ow_write_block(struct fmctdc_dev *ft, int port, uint8_t * block,
int len)
{ {
int i; int i;
for(i = 0; i < len; i++) for (i = 0; i < len; i++)
ow_write_byte(ft, port, block[i]); ow_write_byte(ft, port, block[i]);
return 0; return 0;
} }
static int ow_read_block(struct fmctdc_dev *ft, int port, uint8_t *block, int len) static int ow_read_block(struct fmctdc_dev *ft, int port, uint8_t * block,
int len)
{ {
int i; int i;
for(i = 0; i < len; i++) for (i = 0; i < len; i++)
block[i] = ow_read_byte(ft, port); block[i] = ow_read_byte(ft, port);
return 0; return 0;
} }
static int ds18x_read_serial(struct fmctdc_dev *ft) static int ds18x_read_serial(struct fmctdc_dev *ft)
{ {
if(!ow_reset(ft, 0)) { if (!ow_reset(ft, 0)) {
dev_err(&ft->fmc->dev, "Failure in resetting one-wire channel\n"); dev_err(&ft->fmc->dev,
"Failure in resetting one-wire channel\n");
return -EIO; return -EIO;
} }
...@@ -151,7 +154,7 @@ static int ds18x_read_serial(struct fmctdc_dev *ft) ...@@ -151,7 +154,7 @@ static int ds18x_read_serial(struct fmctdc_dev *ft)
static int ds18x_access(struct fmctdc_dev *ft) static int ds18x_access(struct fmctdc_dev *ft)
{ {
if(!ow_reset(ft, 0)) if (!ow_reset(ft, 0))
goto out; goto out;
if (0) { if (0) {
...@@ -175,7 +178,7 @@ static void __temp_command_and_next_t(struct fmctdc_dev *ft, int cfg_reg) ...@@ -175,7 +178,7 @@ static void __temp_command_and_next_t(struct fmctdc_dev *ft, int cfg_reg)
ds18x_access(ft); ds18x_access(ft);
ow_write_byte(ft, FT_OW_PORT, CMD_CONVERT_TEMP); ow_write_byte(ft, FT_OW_PORT, CMD_CONVERT_TEMP);
/* The conversion takes some time, so mark when will it be ready */ /* The conversion takes some time, so mark when will it be ready */
ms = 94 * ( 1 << (cfg_reg >> 5)); ms = 94 * (1 << (cfg_reg >> 5));
ft->next_t = jiffies + msecs_to_jiffies(ms); ft->next_t = jiffies + msecs_to_jiffies(ms);
} }
...@@ -188,7 +191,7 @@ int ft_read_temp(struct fmctdc_dev *ft, int verbose) ...@@ -188,7 +191,7 @@ int ft_read_temp(struct fmctdc_dev *ft, int verbose)
/* If first conversion, ask for it first */ /* If first conversion, ask for it first */
if (ft->next_t == 0) if (ft->next_t == 0)
__temp_command_and_next_t(ft, 0x7f /* we ignore: max time */); __temp_command_and_next_t(ft, 0x7f /* we ignore: max time */ );
/* Wait for it to be ready: (FIXME: we need a time policy here) */ /* Wait for it to be ready: (FIXME: we need a time policy here) */
j = jiffies; j = jiffies;
...@@ -209,16 +212,16 @@ int ft_read_temp(struct fmctdc_dev *ft, int verbose) ...@@ -209,16 +212,16 @@ int ft_read_temp(struct fmctdc_dev *ft, int verbose)
printk("%02x%c", data[i], i == 8 ? '\n' : ':'); printk("%02x%c", data[i], i == 8 ? '\n' : ':');
} }
temp = ((int)data[1] << 8) | ((int)data[0]); temp = ((int)data[1] << 8) | ((int)data[0]);
if(temp & 0x1000) if (temp & 0x1000)
temp = -0x10000 + temp; temp = -0x10000 + temp;
ft->temp = temp; ft->temp = temp;
ft->temp_ready = 1; ft->temp_ready = 1;
if (verbose) { if (verbose) {
dev_info(dev, "%s: Temperature 0x%x (%i bits: %i.%03i)\n", __func__, dev_info(dev, "%s: Temperature 0x%x (%i bits: %i.%03i)\n",
temp, 9 + (data[4] >> 5), __func__, temp, 9 + (data[4] >> 5), temp / 16,
temp / 16, (temp & 0xf) * 1000 / 16); (temp & 0xf) * 1000 / 16);
} }
__temp_command_and_next_t(ft, data[4]); /* start next conversion */ __temp_command_and_next_t(ft, data[4]); /* start next conversion */
...@@ -230,10 +233,9 @@ int ft_onewire_init(struct fmctdc_dev *ft) ...@@ -230,10 +233,9 @@ int ft_onewire_init(struct fmctdc_dev *ft)
int i; int i;
ow_writel(ft, ((CLK_DIV_NOR & CDR_NOR_MSK) ow_writel(ft, ((CLK_DIV_NOR & CDR_NOR_MSK)
| (( CLK_DIV_OVD << CDR_OVD_OFS) & CDR_OVD_MSK)), | ((CLK_DIV_OVD << CDR_OVD_OFS) & CDR_OVD_MSK)), R_CDR);
R_CDR);
if(ds18x_read_serial(ft) < 0) if (ds18x_read_serial(ft) < 0)
return -EIO; return -EIO;
if (ft->verbose) { if (ft->verbose) {
......
...@@ -27,8 +27,8 @@ struct __fmctdc_board { ...@@ -27,8 +27,8 @@ struct __fmctdc_board {
int dev_id; int dev_id;
char *devbase; char *devbase;
char *sysbase; char *sysbase;
int fdc[5]; /* The 5 control channels */ int fdc[5]; /* The 5 control channels */
int fdd[5]; /* The 5 data channels */ int fdd[5]; /* The 5 data channels */
}; };
static inline int fmctdc_is_verbose(void) static inline int fmctdc_is_verbose(void)
...@@ -39,7 +39,7 @@ static inline int fmctdc_is_verbose(void) ...@@ -39,7 +39,7 @@ static inline int fmctdc_is_verbose(void)
#define __define_board(b, ub) struct __fmctdc_board *b = (void *)(ub) #define __define_board(b, ub) struct __fmctdc_board *b = (void *)(ub)
/* These two from ../tools/fdelay-raw.h, used internally */ /* These two from ../tools/fdelay-raw.h, used internally */
static inline int __fmctdc_sysfs_get(char *path, uint32_t *resp) static inline int __fmctdc_sysfs_get(char *path, uint32_t * resp)
{ {
FILE *f = fopen(path, "r"); FILE *f = fopen(path, "r");
...@@ -56,7 +56,7 @@ static inline int __fmctdc_sysfs_get(char *path, uint32_t *resp) ...@@ -56,7 +56,7 @@ static inline int __fmctdc_sysfs_get(char *path, uint32_t *resp)
return 0; return 0;
} }
static inline int __fmctdc_sysfs_set(char *path, uint32_t *value) static inline int __fmctdc_sysfs_set(char *path, uint32_t * value)
{ {
char s[16]; char s[16];
int fd, ret, len; int fd, ret, len;
...@@ -77,7 +77,7 @@ static inline int __fmctdc_sysfs_set(char *path, uint32_t *value) ...@@ -77,7 +77,7 @@ static inline int __fmctdc_sysfs_set(char *path, uint32_t *value)
/* And these two for the board structure */ /* And these two for the board structure */
static inline int fmctdc_sysfs_get(struct __fmctdc_board *b, char *name, static inline int fmctdc_sysfs_get(struct __fmctdc_board *b, char *name,
uint32_t *resp) uint32_t * resp)
{ {
char pathname[128]; char pathname[128];
...@@ -86,7 +86,7 @@ static inline int fmctdc_sysfs_get(struct __fmctdc_board *b, char *name, ...@@ -86,7 +86,7 @@ static inline int fmctdc_sysfs_get(struct __fmctdc_board *b, char *name,
} }
static inline int fmctdc_sysfs_set(struct __fmctdc_board *b, char *name, static inline int fmctdc_sysfs_set(struct __fmctdc_board *b, char *name,
uint32_t *value) uint32_t * value)
{ {
char pathname[128]; char pathname[128];
......
...@@ -49,8 +49,8 @@ int fmctdc_init(void) ...@@ -49,8 +49,8 @@ int fmctdc_init(void)
glob("/dev/zio/zio-ft-*-0-0-ctrl", GLOB_APPEND, NULL, &glob_dev); glob("/dev/zio/zio-ft-*-0-0-ctrl", GLOB_APPEND, NULL, &glob_dev);
/* And look in /sys as well */ /* And look in /sys as well */
glob("/sys/bus/zio/devices/ft-*", 0, NULL, &glob_sys); glob("/sys/bus/zio/devices/ft-*", 0, NULL, &glob_sys);
glob("/sys/bus/zio/devices/zio-ft-*", GLOB_APPEND , NULL, &glob_sys); glob("/sys/bus/zio/devices/zio-ft-*", GLOB_APPEND, NULL, &glob_sys);
assert(glob_dev.gl_pathc == glob_sys.gl_pathc); assert(glob_dev.gl_pathc == glob_sys.gl_pathc);
/* Allocate as needed */ /* Allocate as needed */
...@@ -126,7 +126,7 @@ void fmctdc_exit(void) ...@@ -126,7 +126,7 @@ void fmctdc_exit(void)
free(b->sysbase); free(b->sysbase);
free(b->devbase); free(b->devbase);
} }
if(ft_nboards) if (ft_nboards)
free(ft_boards); free(ft_boards);
} }
...@@ -224,7 +224,7 @@ int fmctdc_set_termination(struct fmctdc_board *userb, int channel, int on) ...@@ -224,7 +224,7 @@ int fmctdc_set_termination(struct fmctdc_board *userb, int channel, int on)
uint32_t val; uint32_t val;
char attr[32]; char attr[32];
if(channel < FMCTDC_CH_1 || channel > FMCTDC_NUM_CHANNELS) if (channel < FMCTDC_CH_1 || channel > FMCTDC_NUM_CHANNELS)
return -EINVAL; return -EINVAL;
snprintf(attr, sizeof(attr), "ft-ch%d/termination", channel); snprintf(attr, sizeof(attr), "ft-ch%d/termination", channel);
...@@ -240,13 +240,13 @@ int fmctdc_get_termination(struct fmctdc_board *userb, int channel) ...@@ -240,13 +240,13 @@ int fmctdc_get_termination(struct fmctdc_board *userb, int channel)
char attr[32]; char attr[32];
int ret; int ret;
if(channel < FMCTDC_CH_1 || channel > FMCTDC_NUM_CHANNELS) if (channel < FMCTDC_CH_1 || channel > FMCTDC_NUM_CHANNELS)
return -EINVAL; return -EINVAL;
snprintf(attr, sizeof(attr), "ft-ch%d/termination", channel); snprintf(attr, sizeof(attr), "ft-ch%d/termination", channel);
ret = fmctdc_sysfs_get(b, attr, &val); ret = fmctdc_sysfs_get(b, attr, &val);
if(ret) if (ret)
return ret; return ret;
return val; return val;
} }
...@@ -258,7 +258,7 @@ int fmctdc_get_acquisition(struct fmctdc_board *userb) ...@@ -258,7 +258,7 @@ int fmctdc_get_acquisition(struct fmctdc_board *userb)
int ret; int ret;
ret = fmctdc_sysfs_get(b, "enable_inputs", &val); ret = fmctdc_sysfs_get(b, "enable_inputs", &val);
if(ret) if (ret)
return ret; return ret;
return val; return val;
} }
...@@ -272,12 +272,12 @@ int fmctdc_set_acquisition(struct fmctdc_board *userb, int on) ...@@ -272,12 +272,12 @@ int fmctdc_set_acquisition(struct fmctdc_board *userb, int on)
return fmctdc_sysfs_set(b, "enable_inputs", &val); return fmctdc_sysfs_set(b, "enable_inputs", &val);
} }
static int __fmctdc_open_channel(struct __fmctdc_board *b, int channel) static int __fmctdc_open_channel(struct __fmctdc_board *b, int channel)
{ {
char fname[128]; char fname[128];
if (b->fdc[channel - 1] <= 0) { if (b->fdc[channel - 1] <= 0) {
snprintf(fname, sizeof(fname), "%s-%d-0-ctrl", b->devbase, channel - 1); snprintf(fname, sizeof(fname), "%s-%d-0-ctrl", b->devbase,
channel - 1);
b->fdc[channel - 1] = open(fname, O_RDONLY | O_NONBLOCK); b->fdc[channel - 1] = open(fname, O_RDONLY | O_NONBLOCK);
} }
return b->fdc[channel - 1]; return b->fdc[channel - 1];
...@@ -290,8 +290,8 @@ int fmctdc_fileno_channel(struct fmctdc_board *userb, int channel) ...@@ -290,8 +290,8 @@ int fmctdc_fileno_channel(struct fmctdc_board *userb, int channel)
} }
/* "read" behaves like the system call and obeys O_NONBLOCK */ /* "read" behaves like the system call and obeys O_NONBLOCK */
int fmctdc_read(struct fmctdc_board *userb, int channel, struct fmctdc_time *t, int n, int fmctdc_read(struct fmctdc_board *userb, int channel, struct fmctdc_time *t,
int flags) int n, int flags)
{ {
__define_board(b, userb); __define_board(b, userb);
struct zio_control ctrl; struct zio_control ctrl;
...@@ -299,12 +299,12 @@ int fmctdc_read(struct fmctdc_board *userb, int channel, struct fmctdc_time *t, ...@@ -299,12 +299,12 @@ int fmctdc_read(struct fmctdc_board *userb, int channel, struct fmctdc_time *t,
int i, j, fd; int i, j, fd;
fd_set set; fd_set set;
if(channel < FMCTDC_CH_1 || channel > FMCTDC_NUM_CHANNELS) if (channel < FMCTDC_CH_1 || channel > FMCTDC_NUM_CHANNELS)
return -EINVAL; return -EINVAL;
fd = __fmctdc_open_channel(b, channel); fd = __fmctdc_open_channel(b, channel);
if (fd < 0) if (fd < 0)
return fd; /* errno already set */ return fd; /* errno already set */
for (i = 0; i < n;) { for (i = 0; i < n;) {
j = read(fd, &ctrl, sizeof(ctrl)); j = read(fd, &ctrl, sizeof(ctrl));
...@@ -334,7 +334,7 @@ int fmctdc_read(struct fmctdc_board *userb, int channel, struct fmctdc_time *t, ...@@ -334,7 +334,7 @@ int fmctdc_read(struct fmctdc_board *userb, int channel, struct fmctdc_time *t,
/* So, first sample and blocking read. Wait.. */ /* So, first sample and blocking read. Wait.. */
FD_ZERO(&set); FD_ZERO(&set);
FD_SET(fd, &set); FD_SET(fd, &set);
if (select(fd+1, &set, NULL, NULL, NULL) < 0) if (select(fd + 1, &set, NULL, NULL, NULL) < 0)
return -1; return -1;
continue; continue;
} }
...@@ -342,11 +342,12 @@ int fmctdc_read(struct fmctdc_board *userb, int channel, struct fmctdc_time *t, ...@@ -342,11 +342,12 @@ int fmctdc_read(struct fmctdc_board *userb, int channel, struct fmctdc_time *t,
} }
/* "fread" behaves like stdio: it reads all the samples */ /* "fread" behaves like stdio: it reads all the samples */
int fmctdc_fread(struct fmctdc_board *userb, int channel, struct fmctdc_time *t, int n) int fmctdc_fread(struct fmctdc_board *userb, int channel, struct fmctdc_time *t,
int n)
{ {
int i, loop; int i, loop;
for (i = 0; i < n; ) { for (i = 0; i < n;) {
loop = fmctdc_read(userb, channel, t + i, n - i, 0); loop = fmctdc_read(userb, channel, t + i, n - i, 0);
if (loop < 0) if (loop < 0)
return -1; return -1;
...@@ -366,48 +367,46 @@ int fmctdc_set_time(struct fmctdc_board *userb, struct fmctdc_time *t) ...@@ -366,48 +367,46 @@ int fmctdc_set_time(struct fmctdc_board *userb, struct fmctdc_time *t)
attrs[0] = t->seconds & 0xffffffff; attrs[0] = t->seconds & 0xffffffff;
attrs[1] = t->coarse; attrs[1] = t->coarse;
for (i = ARRAY_SIZE(names) - 1; i >= 0; i--) for (i = ARRAY_SIZE(names) - 1; i >= 0; i--) {
{ ret = fmctdc_sysfs_set(b, names[i], attrs + i);
ret = fmctdc_sysfs_set(b, names[i], attrs + i); if (ret < 0)
if(ret < 0) return ret;
return ret;
} }
return 0; return 0;
} }
int fmctdc_get_time(struct fmctdc_board *userb, struct fmctdc_time *t) int fmctdc_get_time(struct fmctdc_board *userb, struct fmctdc_time *t)
{ {
__define_board(b, userb); __define_board(b, userb);
uint32_t attrs[ARRAY_SIZE(names)]; uint32_t attrs[ARRAY_SIZE(names)];
int i, ret; int i, ret;
for (i = 0; i < ARRAY_SIZE(names); i++) for (i = 0; i < ARRAY_SIZE(names); i++) {
{ ret = fmctdc_sysfs_get(b, names[i], attrs + i);
ret = fmctdc_sysfs_get(b, names[i], attrs + i); if (ret < 0)
if(ret < 0) return ret;
return ret; }
}
t->seconds = attrs[0];
t->seconds = attrs[0]; t->coarse = attrs[1];
t->coarse = attrs[1]; t->frac = 0;
t->frac = 0;
return 0;
return 0;
} }
int fmctdc_set_host_time(struct fmctdc_board *userb) int fmctdc_set_host_time(struct fmctdc_board *userb)
{ {
__define_board(b, userb); __define_board(b, userb);
return __fmctdc_command(b, FT_CMD_SET_HOST_TIME); return __fmctdc_command(b, FT_CMD_SET_HOST_TIME);
} }
int fmctdc_wr_mode(struct fmctdc_board *userb, int on) int fmctdc_wr_mode(struct fmctdc_board *userb, int on)
{ {
__define_board(b, userb); __define_board(b, userb);
if (on) if (on)
return __fmctdc_command(b, FT_CMD_WR_ENABLE); return __fmctdc_command(b, FT_CMD_WR_ENABLE);
else else
return __fmctdc_command(b, FT_CMD_WR_DISABLE); return __fmctdc_command(b, FT_CMD_WR_DISABLE);
} }
extern int fmctdc_check_wr_mode(struct fmctdc_board *userb) extern int fmctdc_check_wr_mode(struct fmctdc_board *userb)
...@@ -416,13 +415,12 @@ extern int fmctdc_check_wr_mode(struct fmctdc_board *userb) ...@@ -416,13 +415,12 @@ extern int fmctdc_check_wr_mode(struct fmctdc_board *userb)
__define_board(b, userb); __define_board(b, userb);
ret = __fmctdc_command(b, FT_CMD_WR_QUERY); ret = __fmctdc_command(b, FT_CMD_WR_QUERY);
switch(ret) switch (ret) {
{ case 0:
case 0: return 1; /* no error: locked to WR */
return 1; /* no error: locked to WR */ case -EAGAIN:
case -EAGAIN: return 0; /* EAGAIN: not locked yet */
return 0; /* EAGAIN: not locked yet */ default:
default: return ret; /* other error code: just an error ;) */
return ret; /* other error code: just an error ;) */ }
}
} }
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
#include <stdint.h> #include <stdint.h>
enum fmctdc_channel { enum fmctdc_channel {
FMCTDC_CH_1 = 1, FMCTDC_CH_1 = 1,
FMCTDC_CH_2 = 2, FMCTDC_CH_2 = 2,
FMCTDC_CH_3 = 3, FMCTDC_CH_3 = 3,
FMCTDC_CH_4 = 4, FMCTDC_CH_4 = 4,
FMCTDC_CH_5 = 5, FMCTDC_CH_5 = 5,
FMCTDC_CH_LAST = 5, FMCTDC_CH_LAST = 5,
FMCTDC_NUM_CHANNELS = 5 FMCTDC_NUM_CHANNELS = 5
}; };
/* Opaque data type used as token */ /* Opaque data type used as token */
...@@ -49,17 +49,19 @@ extern int fmctdc_set_host_time(struct fmctdc_board *b); ...@@ -49,17 +49,19 @@ extern int fmctdc_set_host_time(struct fmctdc_board *b);
extern int fmctdc_set_acquisition(struct fmctdc_board *b, int enable); extern int fmctdc_set_acquisition(struct fmctdc_board *b, int enable);
extern int fmctdc_get_acquisition(struct fmctdc_board *b); extern int fmctdc_get_acquisition(struct fmctdc_board *b);
extern int fmctdc_set_termination(struct fmctdc_board *b, int channel, int enable); extern int fmctdc_set_termination(struct fmctdc_board *b, int channel,
int enable);
extern int fmctdc_get_termination(struct fmctdc_board *b, int channel); extern int fmctdc_get_termination(struct fmctdc_board *b, int channel);
extern int fmctdc_fread(struct fmctdc_board *b, int channel, struct fmctdc_time *t, int n); extern int fmctdc_fread(struct fmctdc_board *b, int channel,
struct fmctdc_time *t, int n);
extern int fmctdc_fileno_channel(struct fmctdc_board *b, int channel); extern int fmctdc_fileno_channel(struct fmctdc_board *b, int channel);
extern int fmctdc_read(struct fmctdc_board *b, int channel, struct fmctdc_time *t, int n, extern int fmctdc_read(struct fmctdc_board *b, int channel,
int flags); struct fmctdc_time *t, int n, int flags);
extern float fmctdc_read_temperature(struct fmctdc_board *b); extern float fmctdc_read_temperature(struct fmctdc_board *b);
extern int fmctdc_wr_mode(struct fmctdc_board *b, int on); extern int fmctdc_wr_mode(struct fmctdc_board *b, int on);
extern int fmctdc_check_wr_mode(struct fmctdc_board *b); extern int fmctdc_check_wr_mode(struct fmctdc_board *b);
#endif /* __FMCTDC_LIB_H__ */ #endif /* __FMCTDC_LIB_H__ */
\ No newline at end of file
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