Lines Matching +full:dual +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright 2010-2011 Analog Devices Inc.
28 #define AD7887_REF_DIS BIT(5) /* on-chip reference disable */
29 #define AD7887_DUAL BIT(4) /* dual-channel mode */
30 #define AD7887_CH_AIN1 BIT(3) /* convert on channel 1, DUAL=1 */
31 #define AD7887_CH_AIN0 0 /* convert on channel 0, DUAL=0,1 */
35 #define AD7887_PM_MODE4 3 /* standby mode */
44 * struct ad7887_chip_info - chip specific information
48 * @dual_channels: channels specification in dual mode
49 * @num_dual_channels: number of channels in dual mode
86 switch (*indio_dev->active_scan_mask) { in ad7887_ring_preenable()
88 st->ring_msg = &st->msg[AD7887_CH0]; in ad7887_ring_preenable()
91 st->ring_msg = &st->msg[AD7887_CH1]; in ad7887_ring_preenable()
93 spi_sync(st->spi, st->ring_msg); in ad7887_ring_preenable()
96 st->ring_msg = &st->msg[AD7887_CH0_CH1]; in ad7887_ring_preenable()
108 return spi_sync(st->spi, &st->msg[AD7887_CH0]); in ad7887_ring_postdisable()
114 struct iio_dev *indio_dev = pf->indio_dev; in ad7887_trigger_handler()
118 b_sent = spi_sync(st->spi, st->ring_msg); in ad7887_trigger_handler()
122 iio_push_to_buffers_with_timestamp(indio_dev, st->data, in ad7887_trigger_handler()
125 iio_trigger_notify_done(indio_dev->trig); in ad7887_trigger_handler()
137 int ret = spi_sync(st->spi, &st->msg[ch]); in ad7887_scan_direct()
141 return (st->data[(ch * 2)] << 8) | st->data[(ch * 2) + 1]; in ad7887_scan_direct()
156 return -EBUSY; in ad7887_read_raw()
157 ret = ad7887_scan_direct(st, chan->address); in ad7887_read_raw()
162 *val = ret >> chan->scan_type.shift; in ad7887_read_raw()
163 *val &= GENMASK(chan->scan_type.realbits - 1, 0); in ad7887_read_raw()
166 if (st->reg) { in ad7887_read_raw()
167 *val = regulator_get_voltage(st->reg); in ad7887_read_raw()
172 *val = st->chip_info->int_vref_mv; in ad7887_read_raw()
175 *val2 = chan->scan_type.realbits; in ad7887_read_raw()
179 return -EINVAL; in ad7887_read_raw()
236 const struct ad7887_platform_data *pdata = dev_get_platdata(&spi->dev); in ad7887_probe()
239 uint8_t mode; in ad7887_probe() local
242 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad7887_probe()
244 return -ENOMEM; in ad7887_probe()
248 st->reg = devm_regulator_get_optional(&spi->dev, "vref"); in ad7887_probe()
249 if (IS_ERR(st->reg)) { in ad7887_probe()
250 if (PTR_ERR(st->reg) != -ENODEV) in ad7887_probe()
251 return PTR_ERR(st->reg); in ad7887_probe()
253 st->reg = NULL; in ad7887_probe()
256 if (st->reg) { in ad7887_probe()
257 ret = regulator_enable(st->reg); in ad7887_probe()
261 ret = devm_add_action_or_reset(&spi->dev, ad7887_reg_disable, st->reg); in ad7887_probe()
266 st->chip_info = in ad7887_probe()
267 &ad7887_chip_info_tbl[spi_get_device_id(spi)->driver_data]; in ad7887_probe()
269 st->spi = spi; in ad7887_probe()
271 indio_dev->name = spi_get_device_id(spi)->name; in ad7887_probe()
272 indio_dev->info = &ad7887_info; in ad7887_probe()
273 indio_dev->modes = INDIO_DIRECT_MODE; in ad7887_probe()
277 mode = AD7887_PM_MODE4; in ad7887_probe()
278 if (!st->reg) in ad7887_probe()
279 mode |= AD7887_REF_DIS; in ad7887_probe()
280 if (pdata && pdata->en_dual) in ad7887_probe()
281 mode |= AD7887_DUAL; in ad7887_probe()
283 st->tx_cmd_buf[0] = AD7887_CH_AIN0 | mode; in ad7887_probe()
285 st->xfer[0].rx_buf = &st->data[0]; in ad7887_probe()
286 st->xfer[0].tx_buf = &st->tx_cmd_buf[0]; in ad7887_probe()
287 st->xfer[0].len = 2; in ad7887_probe()
289 spi_message_init(&st->msg[AD7887_CH0]); in ad7887_probe()
290 spi_message_add_tail(&st->xfer[0], &st->msg[AD7887_CH0]); in ad7887_probe()
292 if (pdata && pdata->en_dual) { in ad7887_probe()
293 st->tx_cmd_buf[2] = AD7887_CH_AIN1 | mode; in ad7887_probe()
295 st->xfer[1].rx_buf = &st->data[0]; in ad7887_probe()
296 st->xfer[1].tx_buf = &st->tx_cmd_buf[2]; in ad7887_probe()
297 st->xfer[1].len = 2; in ad7887_probe()
299 st->xfer[2].rx_buf = &st->data[2]; in ad7887_probe()
300 st->xfer[2].tx_buf = &st->tx_cmd_buf[0]; in ad7887_probe()
301 st->xfer[2].len = 2; in ad7887_probe()
303 spi_message_init(&st->msg[AD7887_CH0_CH1]); in ad7887_probe()
304 spi_message_add_tail(&st->xfer[1], &st->msg[AD7887_CH0_CH1]); in ad7887_probe()
305 spi_message_add_tail(&st->xfer[2], &st->msg[AD7887_CH0_CH1]); in ad7887_probe()
307 st->xfer[3].rx_buf = &st->data[2]; in ad7887_probe()
308 st->xfer[3].tx_buf = &st->tx_cmd_buf[2]; in ad7887_probe()
309 st->xfer[3].len = 2; in ad7887_probe()
311 spi_message_init(&st->msg[AD7887_CH1]); in ad7887_probe()
312 spi_message_add_tail(&st->xfer[3], &st->msg[AD7887_CH1]); in ad7887_probe()
314 indio_dev->channels = st->chip_info->dual_channels; in ad7887_probe()
315 indio_dev->num_channels = st->chip_info->num_dual_channels; in ad7887_probe()
317 indio_dev->channels = st->chip_info->channels; in ad7887_probe()
318 indio_dev->num_channels = st->chip_info->num_channels; in ad7887_probe()
321 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, in ad7887_probe()
327 return devm_iio_device_register(&spi->dev, indio_dev); in ad7887_probe()