Commit 1ab5931a authored by Alessandro Rubini's avatar Alessandro Rubini

kernel: redefine calibration, less error-prone

This commit redefines the calibration data structure. Mainly, it now
is a single structure. This allows to turn a constant number into a
sizeof and manage the whole structure as a single entity, preparing
for better management (like checking it is valid and fix endianness).
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 8e7db1cf
......@@ -386,12 +386,12 @@ static int zfad_set_range(struct fa_dev *fa, struct zio_channel *chan,
/* Apply the ADC calibration value for the offset */
i = zfad_get_chx_index(ZFA_CHx_OFFSET, chan);
cal_val = fa->adc_cal_data[range].offset[chan->index];
cal_val = fa->calib.adc[range].offset[chan->index];
dev_dbg(&chan->head.dev, "offset calibration value 0x%x\n", cal_val);
zfa_common_conf_set(fa, i, cal_val);
/* Apply the ADC calibration value for the gain */
i = zfad_get_chx_index(ZFA_CHx_GAIN, chan);
cal_val = fa->adc_cal_data[range].gain[chan->index];
cal_val = fa->calib.adc[range].gain[chan->index];
dev_dbg(&chan->head.dev, "gain calibration value 0x%x\n", cal_val);
zfa_common_conf_set(fa, i, cal_val);
......@@ -427,16 +427,19 @@ static int zfad_apply_user_offset(struct fa_dev *fa, struct zio_channel *chan,
if (range != ZFA_RANGE_OPEN) {
/* Get calibration offset and gain for DAC */
offset = fa->dac_cal_data[range].offset[chan->index];
gain = fa->dac_cal_data[range].gain[chan->index];
dev_dbg(&chan->head.dev, "Appling offset (%d, 0x%x, 0x%x, 0x%x)\n",
chan->index, range, gain, offset);
/* Calculate calibrater value for DAC */
cal_val = ((((usr_val - 0x8000 + offset) << 15) * gain) >> 30);
cal_val += 0x8000;
} else { /* Open range */
cal_val = usr_val;
offset = fa->calib.dac[range].offset[chan->index];
gain = fa->calib.dac[range].gain[chan->index];
} else {
/* open input channel: apply no-conversion values */
gain = 0x8000;
offset = 0;
}
dev_dbg(&chan->head.dev, "Appling offset (%d, 0x%x, 0x%x, 0x%x)\n",
chan->index, range, gain, offset);
/* Calculate value for DAC chip -- FIXME */
cal_val = ((((usr_val - 0x8000 + offset) << 15) * gain) >> 30);
cal_val += 0x8000;
if (cal_val > 0xFFFF)
cal_val = 0xFFFF;
......@@ -1054,11 +1057,8 @@ static int zfad_zio_probe(struct zio_device *zdev)
/* Save also the pointer to the real zio_device */
fa->zdev = zdev;
/*
* Get Calibration Data. ADC calibration value and DAC calibration
* value are consecutive; I can fill both array with a single memcpy
*/
memcpy(fa->adc_cal_data, fa->fmc->eeprom + FA_CAL_PTR, FA_CAL_LEN);
/* Retrieve calibration data from the eeprom. FIXME: verify it */
memcpy(&fa->calib, fa->fmc->eeprom + FA_CAL_OFFSET, sizeof(fa->calib));
/* Configure GPIO for IRQ */
fa->fmc->op->gpio_config(fa->fmc, zfat_gpio_cfg,
......
......@@ -30,28 +30,30 @@ extern int enable_auto_start;
#define FA_MAX_ACQ_BYTE 0x10000000 /* 256MB */
/* ADC Calibration */
#define FA_CAL_PTR 0x0100 /* Pointer to calibration data in EEPROM (256 Byte) */
#define FA_CAL_LEN 108 /* Length of the calibration data */
enum fa_input_range {
ZFA_RANGE_10V = 0x0,
ZFA_RANGE_1V,
ZFA_RANGE_100mV,
ZFA_RANGE_OPEN, /* Channel disconnected from ADC */
};
/*
* fa_calibration_data: Calibration item
* @offset calibration data for 4 channels
* @gain calibration data for 4 channels
* @temp calibration data temperature
*/
struct fa_calibration_data {
uint16_t offset[4];
uint16_t gain[4];
uint16_t temp;
#define ZFA_RANGE_MIN 0 /* 10V above */
#define ZFA_RANGE_MAX 2 /* 100mV above */
/* ADC and DAC Calibration, from EEPROM */
struct fa_calib_stanza {
int16_t offset[4]; /* One per channel */
uint16_t gain[4]; /* One per channel */
uint16_t temperature;
};
struct fa_calib {
struct fa_calib_stanza adc[3]; /* For input, one per range */
struct fa_calib_stanza dac[3]; /* For user offset, one per range */
};
#define FA_CAL_OFFSET 0x0100 /* Offset in EEPROM */
/*
* dma_item: The information about a DMA transfer
* @start_addr: pointer where start to retrieve data from device memory
......@@ -109,8 +111,7 @@ struct fa_dev {
int temp; /* temperature: scaled by 4 bits */
/* Calibration Data */
struct fa_calibration_data adc_cal_data[3];
struct fa_calibration_data dac_cal_data[3];
struct fa_calib calib;
/* DMA attributes */
struct sg_table sgt;
......
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