Skip to content

Commit 7ab37ef

Browse files
committed
drivers: adc: ad7124: added support for pd-switch-enable
Added support for the low side power switch pin used for switching DUTs attached to the ADC. The switch is configured though the drivers device tree. Signed-off-by: Noah Stephens <[email protected]>
1 parent 786c9fb commit 7ab37ef

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

drivers/adc/adc_ad7124.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,14 @@ LOG_MODULE_REGISTER(adc_ad7124, CONFIG_ADC_LOG_LEVEL);
119119
#define AD7124_ADC_CTRL_REG_MODE_MSK GENMASK(5, 2)
120120

121121
/* IO Control 1 register bits */
122+
#define AD7124_IO_CONTROL_1_REG_PDSW_EN BIT(15)
122123
#define AD7124_IOUT1_CURRENT_MSK GENMASK(13, 11)
123124
#define AD7124_IOUT0_CURRENT_MSK GENMASK(10, 8)
124125
#define AD7124_IOUT1_CHANNEL_MSK GENMASK(7, 4)
125126
#define AD7124_IOUT0_CHANNEL_MSK GENMASK(3, 0)
126127
#define AD7124_IOUT_MSK \
127-
(AD7124_IOUT1_CURRENT_MSK | AD7124_IOUT0_CURRENT_MSK | AD7124_IOUT1_CHANNEL_MSK | \
128-
AD7124_IOUT0_CHANNEL_MSK)
128+
(AD7124_IO_CONTROL_1_REG_PDSW_EN, AD7124_IOUT1_CURRENT_MSK | AD7124_IOUT0_CURRENT_MSK | \
129+
AD7124_IOUT1_CHANNEL_MSK | AD7124_IOUT0_CHANNEL_MSK)
129130

130131
/* Current source configuration bits */
131132
#define AD7124_CURRENT_SOURCE_IOUT_MSK BIT(3)
@@ -264,6 +265,7 @@ struct adc_ad7124_config {
264265
enum ad7124_device_type active_device;
265266
uint8_t resolution;
266267
bool ref_en;
268+
bool pdsw_en;
267269
};
268270

269271
struct adc_ad7124_data {
@@ -710,6 +712,7 @@ static int adc_ad7124_setup_cfg(const struct device *dev, const struct ad7124_ch
710712
int configuration_setup = 0;
711713
int configuration_mask = 0;
712714
int ref_internal = 0;
715+
int pd_switch = 0;
713716

714717
if (cfg->props.bipolar) {
715718
configuration_setup |= AD7124_CFG_REG_BIPOLAR;
@@ -737,6 +740,10 @@ static int adc_ad7124_setup_cfg(const struct device *dev, const struct ad7124_ch
737740
ref_internal = AD7124_ADC_CTRL_REG_REF_EN;
738741
}
739742

743+
if (config->pdsw_en) {
744+
pd_switch = AD7124_IO_CONTROL_1_REG_PDSW_EN;
745+
}
746+
740747
if (cfg->props.refsel == INTERNAL_REF) {
741748
ret = adc_ad7124_reg_write_msk(dev, AD7124_ADC_CONTROL, AD7124_ADC_CONTROL_REG_LEN,
742749
ref_internal, AD7124_ADC_CTRL_REG_REF_EN);
@@ -745,6 +752,12 @@ static int adc_ad7124_setup_cfg(const struct device *dev, const struct ad7124_ch
745752
}
746753
}
747754

755+
ret = adc_ad7124_reg_write_msk(dev, AD7124_IO_CONTROL_1, AD7124_IO_CONTROL_1_REG_LEN,
756+
pd_switch, AD7124_IO_CONTROL_1_REG_PDSW_EN);
757+
if (ret) {
758+
return ret;
759+
}
760+
748761
return 0;
749762
}
750763

@@ -1447,6 +1460,7 @@ static DEVICE_API(adc, adc_ad7124_api) = {
14471460
.power_mode = DT_INST_PROP(inst, power_mode), \
14481461
.active_device = DT_INST_PROP(inst, active_device), \
14491462
.ref_en = DT_INST_PROP(inst, reference_enable), \
1463+
.pdsw_en = DT_INST_PROP(inst, pd_switch_enable), \
14501464
}; \
14511465
static struct adc_ad7124_data adc_ad7124_data##inst = { \
14521466
ADC_CONTEXT_INIT_LOCK(adc_ad7124_data##inst, ctx), \

dts/bindings/adc/adi,ad7124-adc.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ properties:
1717
- true: Enable internal reference
1818
- false: Disable internal reference
1919
20+
pd-switch-enable:
21+
type: boolean
22+
default: false
23+
description: |
24+
Enable internal low side power switch for AD7124
25+
- true: The switch is in the open position
26+
- false: The switched is in the closed position
27+
The default configuration places the switch in the
28+
closed position for control setup upon power-up
29+
or after reset.
30+
2031
filter-type-mask:
2132
type: int
2233
default: 0

0 commit comments

Comments
 (0)