diff options
| -rw-r--r-- | drivers/staging/iio/adc/ad7793.c | 25 | ||||
| -rw-r--r-- | drivers/staging/iio/adc/ad7793.h | 107 |
2 files changed, 123 insertions, 9 deletions
diff --git a/drivers/staging/iio/adc/ad7793.c b/drivers/staging/iio/adc/ad7793.c index 843550ddc2ea..ec0fbd43f4ee 100644 --- a/drivers/staging/iio/adc/ad7793.c +++ b/drivers/staging/iio/adc/ad7793.c | |||
| @@ -118,6 +118,12 @@ static int ad7793_setup(struct iio_dev *indio_dev, | |||
| 118 | unsigned long long scale_uv; | 118 | unsigned long long scale_uv; |
| 119 | u32 id; | 119 | u32 id; |
| 120 | 120 | ||
| 121 | if ((pdata->current_source_direction == AD7793_IEXEC1_IEXEC2_IOUT1 || | ||
| 122 | pdata->current_source_direction == AD7793_IEXEC1_IEXEC2_IOUT2) && | ||
| 123 | ((pdata->exitation_current != AD7793_IX_10uA) && | ||
| 124 | (pdata->exitation_current != AD7793_IX_210uA))) | ||
| 125 | return -EINVAL; | ||
| 126 | |||
| 121 | /* reset the serial interface */ | 127 | /* reset the serial interface */ |
| 122 | ret = spi_write(st->sd.spi, (u8 *)&ret, sizeof(ret)); | 128 | ret = spi_write(st->sd.spi, (u8 *)&ret, sizeof(ret)); |
| 123 | if (ret < 0) | 129 | if (ret < 0) |
| @@ -136,8 +142,18 @@ static int ad7793_setup(struct iio_dev *indio_dev, | |||
| 136 | goto out; | 142 | goto out; |
| 137 | } | 143 | } |
| 138 | 144 | ||
| 139 | st->mode = pdata->mode; | 145 | st->mode = AD7793_MODE_RATE(1); |
| 140 | st->conf = pdata->conf; | 146 | st->mode |= AD7793_MODE_CLKSRC(pdata->clock_src); |
| 147 | st->conf = AD7793_CONF_REFSEL(pdata->refsel); | ||
| 148 | st->conf |= AD7793_CONF_VBIAS(pdata->bias_voltage); | ||
| 149 | if (pdata->buffered) | ||
| 150 | st->conf |= AD7793_CONF_BUF; | ||
| 151 | if (pdata->boost_enable) | ||
| 152 | st->conf |= AD7793_CONF_BOOST; | ||
| 153 | if (pdata->burnout_current) | ||
| 154 | st->conf |= AD7793_CONF_BO_EN; | ||
| 155 | if (pdata->unipolar) | ||
| 156 | st->conf |= AD7793_CONF_UNIPOLAR; | ||
| 141 | 157 | ||
| 142 | ret = ad7793_set_mode(&st->sd, AD_SD_MODE_IDLE); | 158 | ret = ad7793_set_mode(&st->sd, AD_SD_MODE_IDLE); |
| 143 | if (ret) | 159 | if (ret) |
| @@ -147,8 +163,9 @@ static int ad7793_setup(struct iio_dev *indio_dev, | |||
| 147 | if (ret) | 163 | if (ret) |
| 148 | goto out; | 164 | goto out; |
| 149 | 165 | ||
| 150 | ret = ad_sd_write_reg(&st->sd, AD7793_REG_IO, | 166 | ret = ad_sd_write_reg(&st->sd, AD7793_REG_IO, 1, |
| 151 | sizeof(pdata->io), pdata->io); | 167 | pdata->exitation_current | |
| 168 | (pdata->current_source_direction << 2)); | ||
| 152 | if (ret) | 169 | if (ret) |
| 153 | goto out; | 170 | goto out; |
| 154 | 171 | ||
diff --git a/drivers/staging/iio/adc/ad7793.h b/drivers/staging/iio/adc/ad7793.h index 8fdd450a2cd9..9e905906da2f 100644 --- a/drivers/staging/iio/adc/ad7793.h +++ b/drivers/staging/iio/adc/ad7793.h | |||
| @@ -68,7 +68,7 @@ | |||
| 68 | #define AD7793_CONF_UNIPOLAR (1 << 12) /* Unipolar/Bipolar Enable */ | 68 | #define AD7793_CONF_UNIPOLAR (1 << 12) /* Unipolar/Bipolar Enable */ |
| 69 | #define AD7793_CONF_BOOST (1 << 11) /* Boost Enable */ | 69 | #define AD7793_CONF_BOOST (1 << 11) /* Boost Enable */ |
| 70 | #define AD7793_CONF_GAIN(x) (((x) & 0x7) << 8) /* Gain Select */ | 70 | #define AD7793_CONF_GAIN(x) (((x) & 0x7) << 8) /* Gain Select */ |
| 71 | #define AD7793_CONF_REFSEL (1 << 7) /* INT/EXT Reference Select */ | 71 | #define AD7793_CONF_REFSEL(x) ((x) << 6) /* INT/EXT Reference Select */ |
| 72 | #define AD7793_CONF_BUF (1 << 4) /* Buffered Mode Enable */ | 72 | #define AD7793_CONF_BUF (1 << 4) /* Buffered Mode Enable */ |
| 73 | #define AD7793_CONF_CHAN(x) ((x) & 0xf) /* Channel select */ | 73 | #define AD7793_CONF_CHAN(x) ((x) & 0xf) /* Channel select */ |
| 74 | #define AD7793_CONF_CHAN_MASK 0xf /* Channel select mask */ | 74 | #define AD7793_CONF_CHAN_MASK 0xf /* Channel select mask */ |
| @@ -105,11 +105,108 @@ | |||
| 105 | #define AD7793_IO_IXCEN_210uA (2 << 0) /* Excitation Current 210uA */ | 105 | #define AD7793_IO_IXCEN_210uA (2 << 0) /* Excitation Current 210uA */ |
| 106 | #define AD7793_IO_IXCEN_1mA (3 << 0) /* Excitation Current 1mA */ | 106 | #define AD7793_IO_IXCEN_1mA (3 << 0) /* Excitation Current 1mA */ |
| 107 | 107 | ||
| 108 | /** | ||
| 109 | * enum ad7793_clock_source - AD7793 clock source selection | ||
| 110 | * @AD7793_CLK_SRC_INT: Internal 64 kHz clock, not available at the CLK pin. | ||
| 111 | * @AD7793_CLK_SRC_INT_CO: Internal 64 kHz clock, available at the CLK pin. | ||
| 112 | * @AD7793_CLK_SRC_EXT: Use external clock. | ||
| 113 | * @AD7793_CLK_SRC_EXT_DIV2: Use external clock divided by 2. | ||
| 114 | */ | ||
| 115 | enum ad7793_clock_source { | ||
| 116 | AD7793_CLK_SRC_INT, | ||
| 117 | AD7793_CLK_SRC_INT_CO, | ||
| 118 | AD7793_CLK_SRC_EXT, | ||
| 119 | AD7793_CLK_SRC_EXT_DIV2, | ||
| 120 | }; | ||
| 121 | |||
| 122 | /** | ||
| 123 | * enum ad7793_bias_voltage - AD7793 bias voltage selection | ||
| 124 | * @AD7793_BIAS_VOLTAGE_DISABLED: Bias voltage generator disabled | ||
| 125 | * @AD7793_BIAS_VOLTAGE_AIN1: Bias voltage connected to AIN1(-). | ||
| 126 | * @AD7793_BIAS_VOLTAGE_AIN2: Bias voltage connected to AIN2(-). | ||
| 127 | * @AD7793_BIAS_VOLTAGE_AIN3: Bias voltage connected to AIN3(-). | ||
| 128 | * Only valid for AD7795/AD7796. | ||
| 129 | */ | ||
| 130 | enum ad7793_bias_voltage { | ||
| 131 | AD7793_BIAS_VOLTAGE_DISABLED, | ||
| 132 | AD7793_BIAS_VOLTAGE_AIN1, | ||
| 133 | AD7793_BIAS_VOLTAGE_AIN2, | ||
| 134 | AD7793_BIAS_VOLTAGE_AIN3, | ||
| 135 | }; | ||
| 136 | |||
| 137 | /** | ||
| 138 | * enum ad7793_refsel - AD7793 reference voltage selection | ||
| 139 | * @AD7793_REFSEL_REFIN1: External reference applied between REFIN1(+) | ||
| 140 | * and REFIN1(-). | ||
| 141 | * @AD7793_REFSEL_REFIN2: External reference applied between REFIN2(+) and | ||
| 142 | * and REFIN1(-). Only valid for AD7795/AD7796. | ||
| 143 | * @AD7793_REFSEL_INTERNAL: Internal 1.17 V reference. | ||
| 144 | */ | ||
| 145 | enum ad7793_refsel { | ||
| 146 | AD7793_REFSEL_REFIN1 = 0, | ||
| 147 | AD7793_REFSEL_REFIN2 = 1, | ||
| 148 | AD7793_REFSEL_INTERNAL = 2, | ||
| 149 | }; | ||
| 150 | |||
| 151 | /** | ||
| 152 | * enum ad7793_current_source_direction - AD7793 excitation current direction | ||
| 153 | * @AD7793_IEXEC1_IOUT1_IEXEC2_IOUT2: Current source IEXC1 connected to pin | ||
| 154 | * IOUT1, current source IEXC2 connected to pin IOUT2. | ||
| 155 | * @AD7793_IEXEC1_IOUT2_IEXEC2_IOUT1: Current source IEXC2 connected to pin | ||
| 156 | * IOUT1, current source IEXC1 connected to pin IOUT2. | ||
| 157 | * @AD7793_IEXEC1_IEXEC2_IOUT1: Both current sources connected to pin IOUT1. | ||
| 158 | * Only valid when the current sources are set to 10 uA or 210 uA. | ||
| 159 | * @AD7793_IEXEC1_IEXEC2_IOUT2: Both current sources connected to Pin IOUT2. | ||
| 160 | * Only valid when the current ources are set to 10 uA or 210 uA. | ||
| 161 | */ | ||
| 162 | enum ad7793_current_source_direction { | ||
| 163 | AD7793_IEXEC1_IOUT1_IEXEC2_IOUT2 = 0, | ||
| 164 | AD7793_IEXEC1_IOUT2_IEXEC2_IOUT1 = 1, | ||
| 165 | AD7793_IEXEC1_IEXEC2_IOUT1 = 2, | ||
| 166 | AD7793_IEXEC1_IEXEC2_IOUT2 = 3, | ||
| 167 | }; | ||
| 168 | |||
| 169 | /** | ||
| 170 | * enum ad7793_excitation_current - AD7793 excitation current selection | ||
| 171 | * @AD7793_IX_DISABLED: Excitation current Disabled. | ||
| 172 | * @AD7793_IX_10uA: Enable 10 micro-ampere excitation current. | ||
| 173 | * @AD7793_IX_210uA: Enable 210 micro-ampere excitation current. | ||
| 174 | * @AD7793_IX_1mA: Enable 1 milli-Ampere excitation current. | ||
| 175 | */ | ||
| 176 | enum ad7793_excitation_current { | ||
| 177 | AD7793_IX_DISABLED = 0, | ||
| 178 | AD7793_IX_10uA = 1, | ||
| 179 | AD7793_IX_210uA = 2, | ||
| 180 | AD7793_IX_1mA = 3, | ||
| 181 | }; | ||
| 182 | |||
| 183 | /** | ||
| 184 | * struct ad7793_platform_data - AD7793 platform data | ||
| 185 | * @vref_mv: Reference voltage in milli-Volt | ||
| 186 | * @clock_src: Clock source selection | ||
| 187 | * @burnout_current: If set to true the 100nA burnout current is enabled. | ||
| 188 | * @boost_enable: Enable boost for the bias voltage generator. | ||
| 189 | * @buffered: If set to true configure the device for buffered input mode. | ||
| 190 | * @unipolar: If set to true sample in unipolar mode, if set to false sample in | ||
| 191 | * bipolar mode. | ||
| 192 | * @refsel: Reference voltage selection | ||
| 193 | * @bias_voltage: Bias voltage selection | ||
| 194 | * @exitation_current: Excitation current selection | ||
| 195 | * @current_source_direction: Excitation current direction selection | ||
| 196 | */ | ||
| 108 | struct ad7793_platform_data { | 197 | struct ad7793_platform_data { |
| 109 | u16 vref_mv; | 198 | u16 vref_mv; |
| 110 | u16 mode; | 199 | |
| 111 | u16 conf; | 200 | enum ad7793_clock_source clock_src; |
| 112 | u8 io; | 201 | bool burnout_current; |
| 202 | bool boost_enable; | ||
| 203 | bool buffered; | ||
| 204 | bool unipolar; | ||
| 205 | |||
| 206 | enum ad7793_refsel refsel; | ||
| 207 | enum ad7793_bias_voltage bias_voltage; | ||
| 208 | enum ad7793_excitation_current exitation_current; | ||
| 209 | enum ad7793_current_source_direction current_source_direction; | ||
| 113 | }; | 210 | }; |
| 114 | 211 | ||
| 115 | #endif /* IIO_ADC_AD7793_H_ */ | 212 | #endif /* IIO_ADC_AD7793_H_ */ |
