Lines Matching +full:iio +full:- +full:consumer
1 // SPDX-License-Identifier: GPL-2.0-only
3 * TI ADC081C/ADC101C/ADC121C 8/10/12-bit ADC driver
14 * bits handled. For the 8-bit and 10-bit models the least-significant 4 or 2
24 #include <linux/iio/iio.h>
25 #include <linux/iio/buffer.h>
26 #include <linux/iio/trigger_consumer.h>
27 #include <linux/iio/triggered_buffer.h>
28 #include <linux/regulator/consumer.h>
46 static int adc081c_read_raw(struct iio_dev *iio, in adc081c_read_raw() argument
50 struct adc081c *adc = iio_priv(iio); in adc081c_read_raw()
55 err = i2c_smbus_read_word_swapped(adc->i2c, REG_CONV_RES); in adc081c_read_raw()
59 *value = (err & 0xFFF) >> (12 - adc->bits); in adc081c_read_raw()
63 err = regulator_get_voltage(adc->ref); in adc081c_read_raw()
68 *shift = adc->bits; in adc081c_read_raw()
76 return -EINVAL; in adc081c_read_raw()
87 .shift = 12 - (_bits), \
135 struct iio_dev *indio_dev = pf->indio_dev; in adc081c_trigger_handler()
139 ret = i2c_smbus_read_word_swapped(data->i2c, REG_CONV_RES); in adc081c_trigger_handler()
142 data->scan.channel = ret; in adc081c_trigger_handler()
143 iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, in adc081c_trigger_handler()
146 iio_trigger_notify_done(indio_dev->trig); in adc081c_trigger_handler()
157 struct iio_dev *iio; in adc081c_probe() local
162 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) in adc081c_probe()
163 return -EOPNOTSUPP; in adc081c_probe()
167 iio = devm_iio_device_alloc(&client->dev, sizeof(*adc)); in adc081c_probe()
168 if (!iio) in adc081c_probe()
169 return -ENOMEM; in adc081c_probe()
171 adc = iio_priv(iio); in adc081c_probe()
172 adc->i2c = client; in adc081c_probe()
173 adc->bits = model->bits; in adc081c_probe()
175 adc->ref = devm_regulator_get(&client->dev, "vref"); in adc081c_probe()
176 if (IS_ERR(adc->ref)) in adc081c_probe()
177 return PTR_ERR(adc->ref); in adc081c_probe()
179 err = regulator_enable(adc->ref); in adc081c_probe()
183 err = devm_add_action_or_reset(&client->dev, adc081c_reg_disable, in adc081c_probe()
184 adc->ref); in adc081c_probe()
188 iio->name = dev_name(&client->dev); in adc081c_probe()
189 iio->modes = INDIO_DIRECT_MODE; in adc081c_probe()
190 iio->info = &adc081c_info; in adc081c_probe()
192 iio->channels = model->channels; in adc081c_probe()
193 iio->num_channels = ADC081C_NUM_CHANNELS; in adc081c_probe()
195 err = devm_iio_triggered_buffer_setup(&client->dev, iio, NULL, in adc081c_probe()
198 dev_err(&client->dev, "iio triggered buffer setup failed\n"); in adc081c_probe()
202 return devm_iio_device_register(&client->dev, iio); in adc081c_probe()
239 MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");