Lines Matching +full:data +full:- +full:bits
1 // SPDX-License-Identifier: GPL-2.0
12 * Copyright (C) 2013 Texas Instruments Incorporated - https://www.ti.com/
36 * Device tree users encode that via the vref-supply regulator.
52 /* val = value, dec = left shift, bits = number of bits of the mask */
53 #define TI_ADS7950_EXTRACT(val, dec, bits) \ argument
54 (((val) >> (dec)) & ((1 << (bits)) - 1))
61 (TI_ADS7950_MAN_CMD(TI_ADS7950_CR_WRITE | st->cmd_settings_bitmask))
64 (TI_ADS7950_GPIO_CMD(st->gpio_cmd_settings_bitmask))
81 * Bitmask of lower 7 bits used for configuration
82 * These bits only can be written when TI_ADS7950_CR_WRITE
84 * [0-3] GPIO signal
89 * Bits present on Manual/Auto1/Auto2 commands
95 * [0-3] GPIO direction
96 * [4-6] Different GPIO alarm mode configurations
100 * [10-11] N/A
136 #define TI_ADS7950_V_CHAN(index, bits) \ argument
148 .realbits = bits, \
150 .shift = 12 - (bits), \
155 #define DECLARE_TI_ADS7950_4_CHANNELS(name, bits) \ argument
157 TI_ADS7950_V_CHAN(0, bits), \
158 TI_ADS7950_V_CHAN(1, bits), \
159 TI_ADS7950_V_CHAN(2, bits), \
160 TI_ADS7950_V_CHAN(3, bits), \
164 #define DECLARE_TI_ADS7950_8_CHANNELS(name, bits) \ argument
166 TI_ADS7950_V_CHAN(0, bits), \
167 TI_ADS7950_V_CHAN(1, bits), \
168 TI_ADS7950_V_CHAN(2, bits), \
169 TI_ADS7950_V_CHAN(3, bits), \
170 TI_ADS7950_V_CHAN(4, bits), \
171 TI_ADS7950_V_CHAN(5, bits), \
172 TI_ADS7950_V_CHAN(6, bits), \
173 TI_ADS7950_V_CHAN(7, bits), \
177 #define DECLARE_TI_ADS7950_12_CHANNELS(name, bits) \ argument
179 TI_ADS7950_V_CHAN(0, bits), \
180 TI_ADS7950_V_CHAN(1, bits), \
181 TI_ADS7950_V_CHAN(2, bits), \
182 TI_ADS7950_V_CHAN(3, bits), \
183 TI_ADS7950_V_CHAN(4, bits), \
184 TI_ADS7950_V_CHAN(5, bits), \
185 TI_ADS7950_V_CHAN(6, bits), \
186 TI_ADS7950_V_CHAN(7, bits), \
187 TI_ADS7950_V_CHAN(8, bits), \
188 TI_ADS7950_V_CHAN(9, bits), \
189 TI_ADS7950_V_CHAN(10, bits), \
190 TI_ADS7950_V_CHAN(11, bits), \
194 #define DECLARE_TI_ADS7950_16_CHANNELS(name, bits) \ argument
196 TI_ADS7950_V_CHAN(0, bits), \
197 TI_ADS7950_V_CHAN(1, bits), \
198 TI_ADS7950_V_CHAN(2, bits), \
199 TI_ADS7950_V_CHAN(3, bits), \
200 TI_ADS7950_V_CHAN(4, bits), \
201 TI_ADS7950_V_CHAN(5, bits), \
202 TI_ADS7950_V_CHAN(6, bits), \
203 TI_ADS7950_V_CHAN(7, bits), \
204 TI_ADS7950_V_CHAN(8, bits), \
205 TI_ADS7950_V_CHAN(9, bits), \
206 TI_ADS7950_V_CHAN(10, bits), \
207 TI_ADS7950_V_CHAN(11, bits), \
208 TI_ADS7950_V_CHAN(12, bits), \
209 TI_ADS7950_V_CHAN(13, bits), \
210 TI_ADS7950_V_CHAN(14, bits), \
211 TI_ADS7950_V_CHAN(15, bits), \
290 for_each_set_bit(i, active_scan_mask, indio_dev->num_channels) { in ti_ads7950_update_scan_mode()
292 st->tx_buf[len++] = cmd; in ti_ads7950_update_scan_mode()
295 /* Data for the 1st channel is not returned until the 3rd transfer */ in ti_ads7950_update_scan_mode()
296 st->tx_buf[len++] = 0; in ti_ads7950_update_scan_mode()
297 st->tx_buf[len++] = 0; in ti_ads7950_update_scan_mode()
299 st->ring_xfer.len = len * 2; in ti_ads7950_update_scan_mode()
307 struct iio_dev *indio_dev = pf->indio_dev; in ti_ads7950_trigger_handler()
311 mutex_lock(&st->slock); in ti_ads7950_trigger_handler()
312 ret = spi_sync(st->spi, &st->ring_msg); in ti_ads7950_trigger_handler()
316 iio_push_to_buffers_with_timestamp(indio_dev, &st->rx_buf[2], in ti_ads7950_trigger_handler()
320 mutex_unlock(&st->slock); in ti_ads7950_trigger_handler()
321 iio_trigger_notify_done(indio_dev->trig); in ti_ads7950_trigger_handler()
331 mutex_lock(&st->slock); in ti_ads7950_scan_direct()
333 st->single_tx = cmd; in ti_ads7950_scan_direct()
335 ret = spi_sync(st->spi, &st->scan_single_msg); in ti_ads7950_scan_direct()
339 ret = st->single_rx; in ti_ads7950_scan_direct()
342 mutex_unlock(&st->slock); in ti_ads7950_scan_direct()
351 if (st->vref_mv) { in ti_ads7950_get_range()
352 vref = st->vref_mv; in ti_ads7950_get_range()
354 vref = regulator_get_voltage(st->reg); in ti_ads7950_get_range()
361 if (st->cmd_settings_bitmask & TI_ADS7950_CR_RANGE_5V) in ti_ads7950_get_range()
376 ret = ti_ads7950_scan_direct(indio_dev, chan->address); in ti_ads7950_read_raw()
380 if (chan->address != TI_ADS7950_EXTRACT(ret, 12, 4)) in ti_ads7950_read_raw()
381 return -EIO; in ti_ads7950_read_raw()
383 *val = TI_ADS7950_EXTRACT(ret, chan->scan_type.shift, in ti_ads7950_read_raw()
384 chan->scan_type.realbits); in ti_ads7950_read_raw()
393 *val2 = (1 << chan->scan_type.realbits) - 1; in ti_ads7950_read_raw()
398 return -EINVAL; in ti_ads7950_read_raw()
411 mutex_lock(&st->slock); in ti_ads7950_set()
414 st->cmd_settings_bitmask |= BIT(offset); in ti_ads7950_set()
416 st->cmd_settings_bitmask &= ~BIT(offset); in ti_ads7950_set()
418 st->single_tx = TI_ADS7950_MAN_CMD_SETTINGS(st); in ti_ads7950_set()
419 spi_sync(st->spi, &st->scan_single_msg); in ti_ads7950_set()
421 mutex_unlock(&st->slock); in ti_ads7950_set()
429 mutex_lock(&st->slock); in ti_ads7950_get()
432 if (st->gpio_cmd_settings_bitmask & BIT(offset)) { in ti_ads7950_get()
433 ret = st->cmd_settings_bitmask & BIT(offset); in ti_ads7950_get()
437 /* GPIO data bit sets SDO bits 12-15 to GPIO input */ in ti_ads7950_get()
438 st->cmd_settings_bitmask |= TI_ADS7950_CR_GPIO_DATA; in ti_ads7950_get()
439 st->single_tx = TI_ADS7950_MAN_CMD_SETTINGS(st); in ti_ads7950_get()
440 ret = spi_sync(st->spi, &st->scan_single_msg); in ti_ads7950_get()
444 ret = ((st->single_rx >> 12) & BIT(offset)) ? 1 : 0; in ti_ads7950_get()
447 st->cmd_settings_bitmask &= ~TI_ADS7950_CR_GPIO_DATA; in ti_ads7950_get()
448 st->single_tx = TI_ADS7950_MAN_CMD_SETTINGS(st); in ti_ads7950_get()
449 ret = spi_sync(st->spi, &st->scan_single_msg); in ti_ads7950_get()
454 mutex_unlock(&st->slock); in ti_ads7950_get()
465 return !(st->gpio_cmd_settings_bitmask & BIT(offset)); in ti_ads7950_get_direction()
474 mutex_lock(&st->slock); in _ti_ads7950_set_direction()
477 if (input && (st->gpio_cmd_settings_bitmask & BIT(offset))) in _ti_ads7950_set_direction()
478 st->gpio_cmd_settings_bitmask &= ~BIT(offset); in _ti_ads7950_set_direction()
479 else if (!input && !(st->gpio_cmd_settings_bitmask & BIT(offset))) in _ti_ads7950_set_direction()
480 st->gpio_cmd_settings_bitmask |= BIT(offset); in _ti_ads7950_set_direction()
484 st->single_tx = TI_ADS7950_GPIO_CMD_SETTINGS(st); in _ti_ads7950_set_direction()
485 ret = spi_sync(st->spi, &st->scan_single_msg); in _ti_ads7950_set_direction()
488 mutex_unlock(&st->slock); in _ti_ads7950_set_direction()
511 mutex_lock(&st->slock); in ti_ads7950_init_hw()
515 st->cmd_settings_bitmask = TI_ADS7950_CR_RANGE_5V; in ti_ads7950_init_hw()
516 st->single_tx = TI_ADS7950_MAN_CMD_SETTINGS(st); in ti_ads7950_init_hw()
517 ret = spi_sync(st->spi, &st->scan_single_msg); in ti_ads7950_init_hw()
522 st->gpio_cmd_settings_bitmask = 0x0; in ti_ads7950_init_hw()
523 st->single_tx = TI_ADS7950_GPIO_CMD_SETTINGS(st); in ti_ads7950_init_hw()
524 ret = spi_sync(st->spi, &st->scan_single_msg); in ti_ads7950_init_hw()
527 mutex_unlock(&st->slock); in ti_ads7950_init_hw()
539 spi->bits_per_word = 16; in ti_ads7950_probe()
540 spi->mode |= SPI_CS_WORD; in ti_ads7950_probe()
543 dev_err(&spi->dev, "Error in spi setup\n"); in ti_ads7950_probe()
547 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ti_ads7950_probe()
549 return -ENOMEM; in ti_ads7950_probe()
555 st->spi = spi; in ti_ads7950_probe()
557 info = &ti_ads7950_chip_info[spi_get_device_id(spi)->driver_data]; in ti_ads7950_probe()
559 indio_dev->name = spi_get_device_id(spi)->name; in ti_ads7950_probe()
560 indio_dev->modes = INDIO_DIRECT_MODE; in ti_ads7950_probe()
561 indio_dev->channels = info->channels; in ti_ads7950_probe()
562 indio_dev->num_channels = info->num_channels; in ti_ads7950_probe()
563 indio_dev->info = &ti_ads7950_info; in ti_ads7950_probe()
566 spi_message_init(&st->ring_msg); in ti_ads7950_probe()
568 st->ring_xfer.tx_buf = &st->tx_buf[0]; in ti_ads7950_probe()
569 st->ring_xfer.rx_buf = &st->rx_buf[0]; in ti_ads7950_probe()
572 spi_message_add_tail(&st->ring_xfer, &st->ring_msg); in ti_ads7950_probe()
579 * just dummy data sent while the chip is converting the sample that in ti_ads7950_probe()
583 st->scan_single_xfer[0].tx_buf = &st->single_tx; in ti_ads7950_probe()
584 st->scan_single_xfer[0].len = 2; in ti_ads7950_probe()
585 st->scan_single_xfer[0].cs_change = 1; in ti_ads7950_probe()
586 st->scan_single_xfer[1].tx_buf = &st->single_tx; in ti_ads7950_probe()
587 st->scan_single_xfer[1].len = 2; in ti_ads7950_probe()
588 st->scan_single_xfer[1].cs_change = 1; in ti_ads7950_probe()
589 st->scan_single_xfer[2].rx_buf = &st->single_rx; in ti_ads7950_probe()
590 st->scan_single_xfer[2].len = 2; in ti_ads7950_probe()
592 spi_message_init_with_transfers(&st->scan_single_msg, in ti_ads7950_probe()
593 st->scan_single_xfer, 3); in ti_ads7950_probe()
596 if (ACPI_COMPANION(&spi->dev)) in ti_ads7950_probe()
597 st->vref_mv = TI_ADS7950_VA_MV_ACPI_DEFAULT; in ti_ads7950_probe()
599 mutex_init(&st->slock); in ti_ads7950_probe()
601 st->reg = devm_regulator_get(&spi->dev, "vref"); in ti_ads7950_probe()
602 if (IS_ERR(st->reg)) { in ti_ads7950_probe()
603 ret = dev_err_probe(&spi->dev, PTR_ERR(st->reg), in ti_ads7950_probe()
608 ret = regulator_enable(st->reg); in ti_ads7950_probe()
610 dev_err(&spi->dev, "Failed to enable regulator \"vref\"\n"); in ti_ads7950_probe()
617 dev_err(&spi->dev, "Failed to setup triggered buffer\n"); in ti_ads7950_probe()
623 dev_err(&spi->dev, "Failed to init adc chip\n"); in ti_ads7950_probe()
629 dev_err(&spi->dev, "Failed to register iio device\n"); in ti_ads7950_probe()
634 st->chip.label = dev_name(&st->spi->dev); in ti_ads7950_probe()
635 st->chip.parent = &st->spi->dev; in ti_ads7950_probe()
636 st->chip.owner = THIS_MODULE; in ti_ads7950_probe()
637 st->chip.base = -1; in ti_ads7950_probe()
638 st->chip.ngpio = TI_ADS7950_NUM_GPIOS; in ti_ads7950_probe()
639 st->chip.get_direction = ti_ads7950_get_direction; in ti_ads7950_probe()
640 st->chip.direction_input = ti_ads7950_direction_input; in ti_ads7950_probe()
641 st->chip.direction_output = ti_ads7950_direction_output; in ti_ads7950_probe()
642 st->chip.get = ti_ads7950_get; in ti_ads7950_probe()
643 st->chip.set = ti_ads7950_set; in ti_ads7950_probe()
645 ret = gpiochip_add_data(&st->chip, st); in ti_ads7950_probe()
647 dev_err(&spi->dev, "Failed to init GPIOs\n"); in ti_ads7950_probe()
658 regulator_disable(st->reg); in ti_ads7950_probe()
660 mutex_destroy(&st->slock); in ti_ads7950_probe()
670 gpiochip_remove(&st->chip); in ti_ads7950_remove()
673 regulator_disable(st->reg); in ti_ads7950_remove()
674 mutex_destroy(&st->slock); in ti_ads7950_remove()
695 { .compatible = "ti,ads7950", .data = &ti_ads7950_chip_info[TI_ADS7950] },
696 { .compatible = "ti,ads7951", .data = &ti_ads7950_chip_info[TI_ADS7951] },
697 { .compatible = "ti,ads7952", .data = &ti_ads7950_chip_info[TI_ADS7952] },
698 { .compatible = "ti,ads7953", .data = &ti_ads7950_chip_info[TI_ADS7953] },
699 { .compatible = "ti,ads7954", .data = &ti_ads7950_chip_info[TI_ADS7954] },
700 { .compatible = "ti,ads7955", .data = &ti_ads7950_chip_info[TI_ADS7955] },
701 { .compatible = "ti,ads7956", .data = &ti_ads7950_chip_info[TI_ADS7956] },
702 { .compatible = "ti,ads7957", .data = &ti_ads7950_chip_info[TI_ADS7957] },
703 { .compatible = "ti,ads7958", .data = &ti_ads7950_chip_info[TI_ADS7958] },
704 { .compatible = "ti,ads7959", .data = &ti_ads7950_chip_info[TI_ADS7959] },
705 { .compatible = "ti,ads7960", .data = &ti_ads7950_chip_info[TI_ADS7960] },
706 { .compatible = "ti,ads7961", .data = &ti_ads7950_chip_info[TI_ADS7961] },