Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Link: https://lore.kernel.org/r/20230911142950.216687-1-antoniu.miclaus@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Antoniu Miclaus and committed by
Jonathan Cameron
e670bfe2 22da192f

+18
+18
drivers/iio/addac/ad74413r.c
··· 442 442 int ret; 443 443 444 444 ret = regmap_update_bits(st->regmap, 445 + AD74413R_REG_CH_FUNC_SETUP_X(channel), 446 + AD74413R_CH_FUNC_SETUP_MASK, 447 + CH_FUNC_HIGH_IMPEDANCE); 448 + if (ret) 449 + return ret; 450 + 451 + /* Set DAC code to 0 prior to changing channel function */ 452 + ret = ad74413r_set_channel_dac_code(st, channel, 0); 453 + if (ret) 454 + return ret; 455 + 456 + /* Delay required before transition to new desired mode */ 457 + usleep_range(130, 150); 458 + 459 + ret = regmap_update_bits(st->regmap, 445 460 AD74413R_REG_CH_FUNC_SETUP_X(channel), 446 461 AD74413R_CH_FUNC_SETUP_MASK, func); 447 462 if (ret) 448 463 return ret; 464 + 465 + /* Delay required before updating the new DAC code */ 466 + usleep_range(150, 170); 449 467 450 468 if (func == CH_FUNC_CURRENT_INPUT_LOOP_POWER) 451 469 ret = regmap_set_bits(st->regmap,