Commit 71093c5e authored by Vaibhav Gupta's avatar Vaibhav Gupta Committed by Federico Vaga

software: kernel: update API for temperature read

In the case of error, the current API just reports via dev_err(), and
return a safe value. This is fine for callibration tools. But other
places, like sysfs, care about the eroor and the error code.

Thus, the API should return the error code in case of error, and the
tools which want a safe value, should do it in their own space.
Signed-off-by: 's avatarVaibhav Gupta <vaibhav.gupta@cern.ch>
parent 5fb01319
......@@ -167,12 +167,16 @@ void fa_calib_adc_config_chan(struct fa_dev *fa, unsigned int chan,
int range = fa->range[chan];
struct fa_calib_stanza *cal = &fa->calib.adc[range];
int gain;
int err;
if (fa_calib_is_compensation_on(fa)) {
int32_t delta_temp;
if (flags & FA_CALIB_FLAG_READ_TEMP)
temperature = fa_temperature_read(fa);
if (flags & FA_CALIB_FLAG_READ_TEMP) {
err = fa_temperature_read(fa, &temperature);
if(err)
temperature = 45000; /* 45.000 degrees as safe value */
}
delta_temp = (temperature / 10) - cal->temperature;
gain = fa_calib_adc_gain_fix(range, cal->gain[chan],
delta_temp);
......@@ -280,8 +284,11 @@ int fa_calib_dac_config_chan(struct fa_dev *fa, unsigned int chan,
if (fa_calib_is_compensation_on(fa)) {
int32_t delta_temp;
if (flags & FA_CALIB_FLAG_READ_TEMP)
temperature = fa_temperature_read(fa);
if (flags & FA_CALIB_FLAG_READ_TEMP) {
err = fa_temperature_read(fa, &temperature);
if(err)
temperature = 45000; /* 45.000 degrees as safe value */
}
delta_temp = (temperature / 10) - cal->temperature;
gain = fa_calib_dac_gain_fix(range, cal->gain[chan],
delta_temp);
......@@ -312,8 +319,11 @@ void fa_calib_config(struct fa_dev *fa)
{
int32_t temperature;
int i;
int err;
temperature = fa_temperature_read(fa);
err = fa_temperature_read(fa, &temperature);
if(err)
temperature = 45000; /* 45.000 degrees as safe value */
spin_lock(&fa->zdev->cset->lock);
for (i = 0; i < FA100M14B4C_NCHAN; ++i)
fa_calib_config_chan(fa, i, temperature, 0);
......
......@@ -126,19 +126,19 @@ bool fa_adc_is_output_randomizer(struct fa_dev *fa)
* DS18B20 returns units of 1/16 degree. We return units
* of 1/1000 of a degree instead.
*/
int32_t fa_temperature_read(struct fa_dev *fa)
int fa_temperature_read(struct fa_dev *fa, int32_t *temp)
{
uint32_t reg;
int16_t raw_temp;
reg = fa_ioread(fa, fa->fa_ow_base + 0x08);
if (reg & BIT(31)) {
dev_err(&fa->pdev->dev, "Temperature sensor failure\n");
return 45000; /* 45.000 degrees as save value */
return -EIO;
}
raw_temp = reg & 0xFFFF;
return (raw_temp * 1000UL + 8) / 16;
*temp = (int)((reg & 0xFFFF) * 1000UL + 8) / 16;
return 0;
}
/**
......
......@@ -22,6 +22,7 @@ static umode_t fa_hwmon_temp_is_visible(const void *_data,
static int fa_hwmon_temp_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
int ret;
int32_t value;
struct fa_dev *fa = dev_get_drvdata(dev);
......@@ -39,7 +40,12 @@ static int fa_hwmon_temp_read(struct device *dev, enum hwmon_sensor_types type,
return 0;
}
value = fa_temperature_read(fa);
ret = fa_temperature_read(fa, &value);
if(ret < 0){
dev_err(dev, "Could not read temperature: %d", ret);
return ret;
}
*val = (long)value;
......
......@@ -335,6 +335,7 @@ static int zfad_info_get(struct device *dev, struct zio_attribute *zattr,
struct fa_dev *fa = get_zfadc(dev);
void *baseoff = fa->fa_adc_csr_base;
int i, reg_index;
int err, temp;
i = FA100M14B4C_NCHAN;
......@@ -370,7 +371,10 @@ static int zfad_info_get(struct device *dev, struct zio_attribute *zattr,
/* ZIO automatically return the attribute value */
return 0;
case ZFA_SW_R_NOADDRES_TEMP:
*usr_val = fa_temperature_read(fa);
err = fa_temperature_read(fa, &temp);
if(err)
return err;
*usr_val = (uint32_t)temp;
return 0;
case ZFA_SW_CH1_OFFSET_ZERO:
i--;
......
......@@ -507,7 +507,7 @@ extern const struct zfa_field_desc zfad_regs[];
/* Functions exported by fa-core.c */
extern int zfad_fsm_command(struct fa_dev *fa, uint32_t command);
extern int zfad_convert_hw_range(uint32_t bitmask);
extern int32_t fa_temperature_read(struct fa_dev *fa);
extern int fa_temperature_read(struct fa_dev *fa, int *temp);
extern int fa_trigger_software(struct fa_dev *fa);
extern int fa_fsm_wait_state(struct fa_dev *fa,
enum fa100m14b4c_fsm_state state,
......
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