Commit 55f47c19 authored by Federico Vaga's avatar Federico Vaga

drv: expose output randomizer option

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 61a6a3f6
......@@ -270,6 +270,10 @@ max-sample-mshot
Maximum number of samples that can be stored in the FPGA memory in
multi-shot mode
output-randomizer
It allows to enable or disable the *Data Output Randomizer* in the ADC
chip.
Timestamp Attributes
~~~~~~~~~~~~~~~~~~~~
......
......@@ -36,6 +36,55 @@ static const int zfad_hw_range[] = {
struct workqueue_struct *fa_workqueue;
/**
* Enable/Disable Data Output Randomizer
* @fa: the adc descriptor
* @enable:
*/
int fa_adc_output_randomizer_set(struct fa_dev *fa, bool enable)
{
uint32_t tx, rx;
int err;
tx = 0x8000;
tx |= (1 << 8);
err = fa_spi_xfer(fa, FA_SPI_SS_ADC, 16, tx, &rx);
if (err)
return err;
if (enable)
rx |= BIT(6);
else
rx &= ~BIT(6);
tx = 0x0000;
tx |= (1 << 8);
tx |= (rx & 0xFF);
err = fa_spi_xfer(fa, FA_SPI_SS_ADC, 16, tx, NULL);
if (err)
return err;
return 0;
}
/**
* Check if the Data Output Randomizer is enabled
* @fa: the adc descriptor
* Return: true if the feature is enabled, otherwise false
*/
bool fa_adc_is_output_randomizer(struct fa_dev *fa)
{
uint32_t tx, rx;
int err;
tx = 0x8000;
tx |= (1 << 8);
err = fa_spi_xfer(fa, FA_SPI_SS_ADC, 16, tx, &rx);
if (err)
return false;
return !!(rx & BIT(6));
}
/**
* Read FMC mezzanine temperature
* @fa: the adc descriptor
......
......@@ -123,6 +123,7 @@ static struct zio_attribute zfad_cset_ext_zattr[] = {
ZIO_PARAM_EXT("sample-frequency", ZIO_RO_PERM, ZFAT_SAMPLING_HZ, 0),
ZIO_PARAM_EXT("max-sample-mshot", ZIO_RO_PERM, ZFA_MULT_MAX_SAMP, 0),
ZIO_PARAM_EXT("sample-counter", ZIO_RO_PERM, ZFAT_CNT, 0),
ZIO_PARAM_EXT("output-randomizer", ZIO_RW_PERM, ZFA_SW_R_NOADDERS_RAND, 0),
};
#if 0 /* FIXME Unused until TLV control will be available */
......@@ -192,7 +193,8 @@ static int zfad_conf_set(struct device *dev, struct zio_attribute *zattr,
* programming of hardware is done at the end of the
* switch, in the catch-all final zfa_hardware_write()
*/
case ZFA_SW_R_NOADDERS_RAND:
return fa_adc_output_randomizer_set(fa, !!usr_val);
case ZFA_SW_R_NOADDERS_AUTO:
fa->enable_auto_start = usr_val;
return 0;
......@@ -369,6 +371,9 @@ static int zfad_info_get(struct device *dev, struct zio_attribute *zattr,
case ZFA_CHx_OFFSET:
*usr_val = fa->user_offset[to_zio_chan(dev)->index];
return 0;
case ZFA_SW_R_NOADDERS_RAND:
*usr_val = fa_adc_is_output_randomizer(fa);
return 0;
case ZFA_SW_R_NOADDRES_NBIT:
/*fallthrough*/
case ZFA_SW_R_NOADDERS_AUTO:
......
......@@ -362,6 +362,7 @@ enum fa_sw_param_id {
ZFA_SW_R_NOADDRES_TEMP,
ZFA_SW_R_NOADDERS_AUTO,
ZFA_SW_R_NOADDERS_RAND,
ZFA_SW_CH1_OFFSET_ZERO,
ZFA_SW_CH2_OFFSET_ZERO,
ZFA_SW_CH3_OFFSET_ZERO,
......@@ -616,7 +617,9 @@ extern int fa_fsm_wait_state(struct fa_dev *fa,
extern int fa_adc_data_pattern_set(struct fa_dev *fa, uint16_t pattern,
unsigned int enable);
extern int fa_adc_data_pattern_get(struct fa_dev *fa, uint16_t *pattern,
unsigned int *enable);
unsigned int *enable);
extern int fa_adc_output_randomizer_set(struct fa_dev *fa, bool enable);
extern bool fa_adc_is_output_randomizer(struct fa_dev *fa);
/* Temporarily, user values are the same as hardware values */
extern int zfad_convert_user_range(uint32_t user_val);
......
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