drivers: adc: adc_ad559x: fix 5593 adc read

The AD5593 conversion result also contains the channel read and not just a
value:
| adc channel (3 bits) | adc value (12 bits) |

This value was not removed from the result before using it as an adc value.

Reuse the AD5592 code to fix the issue.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
This commit is contained in:
Jeppe Odgaard 2024-05-22 08:46:56 +02:00 committed by Alberto Escolar
commit 052eb6180d

View file

@ -130,9 +130,6 @@ static int adc_ad559x_read_channel(const struct device *dev, uint8_t channel, ui
if (ret < 0) {
return ret;
}
*result = sys_get_be16((uint8_t *)&val);
} else {
/*
* Invalid data:
@ -145,31 +142,31 @@ static int adc_ad559x_read_channel(const struct device *dev, uint8_t channel, ui
if (ret < 0) {
return ret;
}
val = sys_be16_to_cpu(val);
/*
* Invalid data:
* See "ADC section" in "Theory of operation" chapter.
* Valid ADC result has MSB bit set to 0.
*/
if ((val & AD559X_ADC_RES_IND_BIT) != 0) {
return -EAGAIN;
}
/*
* Invalid channel converted:
* See "ADC section" in "Theory of operation" chapter.
* Conversion result contains channel number which should match requested channel.
*/
conv_channel = FIELD_GET(AD559X_ADC_RES_CHAN_MASK, val);
if (conv_channel != channel) {
return -EIO;
}
*result = val & AD559X_ADC_RES_VAL_MASK;
}
val = sys_be16_to_cpu(val);
/*
* Invalid data:
* See AD5592 "ADC section" in "Theory of operation" chapter.
* Valid ADC result has MSB bit set to 0.
*/
if ((val & AD559X_ADC_RES_IND_BIT) != 0) {
return -EAGAIN;
}
/*
* Invalid channel converted:
* See AD5592 "ADC section" in "Theory of operation" chapter.
* Conversion result contains channel number which should match requested channel.
*/
conv_channel = FIELD_GET(AD559X_ADC_RES_CHAN_MASK, val);
if (conv_channel != channel) {
return -EIO;
}
*result = val & AD559X_ADC_RES_VAL_MASK;
return 0;
}