Commit cb4e3fff authored by Federico Vaga's avatar Federico Vaga

kernel: get max mshot samples from hardware

In bitstream 4.1 there is a register that tells me what is the maximum
number of samples for each shot in multi-shot mode.

So with this patch I removed the hardcoded value and I retrieve at load time
the value from the hardware
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent f6f4b122
......@@ -343,6 +343,8 @@ static int __fa_init(struct fa_dev *fa)
/* Retrieve calibration from the eeprom and validate*/
fa_read_eeprom_calib(fa);
fa->mshot_max_samples = fa_readl(fa, fa->fa_adc_csr_base,
&zfad_regs[ZFA_MULT_MAX_SAMP]);
/* Force stop FSM to prevent early trigger fire */
fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[ZFA_CTL_FMS_CMD],
......
......@@ -78,6 +78,8 @@ const struct zfa_field_desc zfad_regs[] = {
[ZFA_CH4_GAIN] = {0x78, 0x0000FFFF, 0},
[ZFA_CH4_OFFSET] = {0x7C, 0x0000FFFF, 0},
[ZFA_CH4_SAT] = {0x80, 0x00007FFF, 0},
/* Other options */
[ZFA_MULT_MAX_SAMP] = {0x84, 0xFFFFFFFF, 0},
/* IRQ */
[ZFA_IRQ_ADC_DISABLE_MASK] = {0x00, 0x00000003, 0},
[ZFA_IRQ_ADC_ENABLE_MASK] = {0x04, 0x00000003, 0},
......
......@@ -67,8 +67,6 @@ enum fa100m14b4c_dev_ext_attr {
/* ADC DDR memory */
#define FA100M14B4C_MAX_ACQ_BYTE 0x10000000 /* 256MB */
/* In Multi shot mode samples go through a dpram which has a limited size */
#define FA100M14B4C_MAX_MSHOT_ACQ_BYTE 0x3FE8 /* 2045 samples (2045*8 bytes) */
enum fa100m14b4c_input_range {
FA100M14B4C_RANGE_10V = 0x0,
......@@ -195,6 +193,9 @@ enum zfadc_dregs_enum {
ZFA_CHx_GAIN,
ZFA_CHx_OFFSET,
ZFA_CHx_SAT,
/* Other options */
ZFA_MULT_MAX_SAMP,
/* end:declaration block requiring some order */
/* two wishbone core for IRQ: VIC, ADC */
ZFA_IRQ_ADC_DISABLE_MASK,
......@@ -342,6 +343,7 @@ struct fa_dev {
/* Acquisition */
unsigned int n_shots;
unsigned int n_fires;
unsigned int mshot_max_samples;
/* Statistic informations */
unsigned int n_dma_err;
......@@ -402,8 +404,9 @@ extern struct zio_trigger_type zfat_type;
static inline int zfat_overflow_detection(struct zio_ti *ti, unsigned int addr,
uint32_t val)
{
struct fa_dev *fa = ti->cset->zdev->priv_d;
struct zio_attribute *ti_zattr = ti->zattr_set.std_zattr;
uint32_t pre_t, post_t, nshot_t;
uint32_t pre_t, post_t, nshot_t, nsamples;
size_t shot_size;
if (!addr)
......@@ -424,18 +427,20 @@ static inline int zfat_overflow_detection(struct zio_ti *ti, unsigned int addr,
* post-sample by the ADC
* +2 because of the timetag at the end
*/
shot_size = ((pre_t + post_t + 1 + 2) * ti->cset->ssize) * FA100M14B4C_NCHAN;
nsamples = pre_t + post_t + 1;
shot_size = ((nsamples + 2) * ti->cset->ssize) * FA100M14B4C_NCHAN;
if ( (shot_size * nshot_t) > FA100M14B4C_MAX_ACQ_BYTE ) {
dev_err(&ti->head.dev, "Cannot acquire, dev memory overflow\n");
return -ENOMEM;
}
/* in case of multi shot, each shot cannot exceed the dpram size */
if ( (nshot_t > 1) &&
(shot_size > FA100M14B4C_MAX_MSHOT_ACQ_BYTE) ) {
(nsamples > fa->mshot_max_samples) ) {
dev_err(&ti->head.dev, "Cannot acquire such amount of samples "
"(shot_size: %d pre-samp:%d post-samp:%d) in multi shot mode."
"(req: %d , max: %d) in multi shot mode."
"dev memory overflow\n",
(int)shot_size, pre_t, post_t);
nsamples, fa->mshot_max_samples);
return -ENOMEM;
}
return 0;
......
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