iio: addac: ad74413r: update channel function set
Subsystems (3)
PATCH 1/1 iio: addac: ad74413r: update channel function set
According to the datasheet switching to a new channel function implies multiple steps.
All functions must be selected for a minimum of 130 μs before changing to another function.
The DAC_CODEx registers are not reset by changing channel functions. Prior to changing channel functions, it is recommended to set the DAC code to 0x0000 via the DAC_CODEx registers. Set the channel function to high impedance via the CH_FUNC_SETUPx registers before transitioning to the new channel function. After the new channel function is configured, it is recommended to wait 150 μs before updating the DAC code.
Even though the channel switch is done at only at probe, where a device reset is performed, that does not guarantee that the steps prior changing to new channel function should be neglected.
--- drivers/iio/addac/ad74413r.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/iio/addac/ad74413r.c +18 -0
@@ -441,12 +441,30 @@ static int ad74413r_set_channel_function(struct ad74413r_state *st, {int ret; + ret =regmap_update_bits (st->regmap, +AD74413R_REG_CH_FUNC_SETUP_X (channel), +AD74413R_CH_FUNC_SETUP_MASK , +CH_FUNC_HIGH_IMPEDANCE ); +if (ret) +return ret; + +/* Set DAC code to 0 prior to changing channel function */ + ret =ad74413r_set_channel_dac_code (st, channel,0 ); +if (ret) +return ret; + +/* Delay required before transition to new desired mode */ +usleep_range (130 ,150 ); + ret =regmap_update_bits (st->regmap,AD74413R_REG_CH_FUNC_SETUP_X (channel),AD74413R_CH_FUNC_SETUP_MASK , func);if (ret)return ret; +/* Delay required before updating the new DAC code */ +usleep_range (150 ,170 ); +if (func ==CH_FUNC_CURRENT_INPUT_LOOP_POWER ) ret = regmap_set_bits(st->regmap, AD74413R_REG_ADC_CONFIG_X(channel),
Signature · 1 line
2.42.0
Jonathan Cameron
maintainerQuoted 12 lines · On Mon, 11 Sep 2023 17:29:50 +0300 Antoniu Miclaus…
According to the datasheet switching to a new channel function implies multiple steps.
All functions must be selected for a minimum of 130 μs before changing to another function.
TheDAC_CODExregisters are not reset by changing channel functions. Prior to changing channel functions, it is recommended to set the DAC code to0x0000via theDAC_CODExregisters. Set the channel function to high impedance via theCH_FUNC_SETUPxregisters before transitioning to the new channel function. After the new channel function is configured, it is recommended to wait 150 μs before updating the DAC code.
Quoted 5 lines
Even though the channel switch is done at only at probe, where a device reset is performed, that does not guarantee that the steps prior changing to new channel function should be neglected.
Signed-off-by Antoniu Miclaus <[email protected]>
Given description and lack of fixes tag, I'm not treating this as a fix. Let me know if I should and provide a fixes tag in reply to this therad.
Applied to the togreg branch of iio.git and pushed out as testing. Thanks,
Jonathan
Quoted 39 lines
--- drivers/iio/addac/ad74413r.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)drivers/iio/addac/ad74413r.c +18
-0@@ -441,12 +441,30 @@ static int ad74413r_set_channel_function(struct ad74413r_state *st, {int ret; + ret =regmap_update_bits (st->regmap, +AD74413R_REG_CH_FUNC_SETUP_X (channel), +AD74413R_CH_FUNC_SETUP_MASK , +CH_FUNC_HIGH_IMPEDANCE ); +if (ret) +return ret; + +/* Set DAC code to 0 prior to changing channel function */ + ret =ad74413r_set_channel_dac_code (st, channel,0 ); +if (ret) +return ret; + +/* Delay required before transition to new desired mode */ +usleep_range (130 ,150 ); + ret =regmap_update_bits (st->regmap,AD74413R_REG_CH_FUNC_SETUP_X (channel),AD74413R_CH_FUNC_SETUP_MASK , func);if (ret)return ret; +/* Delay required before updating the new DAC code */ +usleep_range (150 ,170 ); +if (func ==CH_FUNC_CURRENT_INPUT_LOOP_POWER ) ret = regmap_set_bits(st->regmap, AD74413R_REG_ADC_CONFIG_X(channel),