Lines Matching +full:adc +full:- +full:vref

1 // SPDX-License-Identifier: GPL-2.0-only
3 * MAX1241 low-power, 12-bit serial ADC
5 * Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX1240-MAX1241.pdf
25 struct regulator *vref; member
41 static int max1241_read(struct max1241 *adc) in max1241_read() argument
57 .rx_buf = &adc->data, in max1241_read()
62 return spi_sync_transfer(adc->spi, xfers, ARRAY_SIZE(xfers)); in max1241_read()
70 struct max1241 *adc = iio_priv(indio_dev); in max1241_read_raw() local
74 mutex_lock(&adc->lock); in max1241_read_raw()
76 if (adc->shutdown) { in max1241_read_raw()
77 gpiod_set_value(adc->shutdown, 0); in max1241_read_raw()
79 ret = max1241_read(adc); in max1241_read_raw()
80 gpiod_set_value(adc->shutdown, 1); in max1241_read_raw()
82 ret = max1241_read(adc); in max1241_read_raw()
85 mutex_unlock(&adc->lock); in max1241_read_raw()
89 *val = (be16_to_cpu(adc->data) >> 3) & MAX1241_VAL_MASK; in max1241_read_raw()
91 mutex_unlock(&adc->lock); in max1241_read_raw()
94 vref_uV = regulator_get_voltage(adc->vref); in max1241_read_raw()
104 return -EINVAL; in max1241_read_raw()
114 struct max1241 *adc = data; in max1241_disable_vref_action() local
115 struct device *dev = &adc->spi->dev; in max1241_disable_vref_action()
118 err = regulator_disable(adc->vref); in max1241_disable_vref_action()
120 dev_err(dev, "could not disable vref regulator.\n"); in max1241_disable_vref_action()
125 struct device *dev = &spi->dev; in max1241_probe()
127 struct max1241 *adc; in max1241_probe() local
130 indio_dev = devm_iio_device_alloc(dev, sizeof(*adc)); in max1241_probe()
132 return -ENOMEM; in max1241_probe()
134 adc = iio_priv(indio_dev); in max1241_probe()
135 adc->spi = spi; in max1241_probe()
136 mutex_init(&adc->lock); in max1241_probe()
143 adc->vref = devm_regulator_get(dev, "vref"); in max1241_probe()
144 if (IS_ERR(adc->vref)) in max1241_probe()
145 return dev_err_probe(dev, PTR_ERR(adc->vref), in max1241_probe()
146 "failed to get vref regulator\n"); in max1241_probe()
148 ret = regulator_enable(adc->vref); in max1241_probe()
152 ret = devm_add_action_or_reset(dev, max1241_disable_vref_action, adc); in max1241_probe()
154 dev_err(dev, "could not set up vref regulator cleanup action\n"); in max1241_probe()
158 adc->shutdown = devm_gpiod_get_optional(dev, "shutdown", in max1241_probe()
160 if (IS_ERR(adc->shutdown)) in max1241_probe()
161 return dev_err_probe(dev, PTR_ERR(adc->shutdown), in max1241_probe()
164 if (adc->shutdown) in max1241_probe()
165 dev_dbg(dev, "shutdown pin passed, low-power mode enabled"); in max1241_probe()
167 dev_dbg(dev, "no shutdown pin passed, low-power mode disabled"); in max1241_probe()
169 indio_dev->name = spi_get_device_id(spi)->name; in max1241_probe()
170 indio_dev->info = &max1241_info; in max1241_probe()
171 indio_dev->modes = INDIO_DIRECT_MODE; in max1241_probe()
172 indio_dev->channels = max1241_channels; in max1241_probe()
173 indio_dev->num_channels = ARRAY_SIZE(max1241_channels); in max1241_probe()
200 MODULE_DESCRIPTION("MAX1241 ADC driver");