Lines Matching +full:vref +full:- +full:p

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.
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))
84 * [0-3] GPIO signal
87 * [6] Sets Vref range1(2.5v) or range2(5v)
95 * [0-3] GPIO direction
96 * [4-6] Different GPIO alarm mode configurations
100 * [10-11] N/A
150 .shift = 12 - (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()
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()
304 static irqreturn_t ti_ads7950_trigger_handler(int irq, void *p) in ti_ads7950_trigger_handler() argument
306 struct iio_poll_func *pf = p; in ti_ads7950_trigger_handler()
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()
349 int vref; in ti_ads7950_get_range() local
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()
355 if (vref < 0) in ti_ads7950_get_range()
356 return vref; in ti_ads7950_get_range()
358 vref /= 1000; in ti_ads7950_get_range()
361 if (st->cmd_settings_bitmask & TI_ADS7950_CR_RANGE_5V) in ti_ads7950_get_range()
362 vref *= 2; in ti_ads7950_get_range()
364 return vref; 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()
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()
604 "Failed to get regulator \"vref\"\n"); 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.can_sleep = true; in ti_ads7950_probe()
638 st->chip.base = -1; in ti_ads7950_probe()
639 st->chip.ngpio = TI_ADS7950_NUM_GPIOS; in ti_ads7950_probe()
640 st->chip.get_direction = ti_ads7950_get_direction; in ti_ads7950_probe()
641 st->chip.direction_input = ti_ads7950_direction_input; in ti_ads7950_probe()
642 st->chip.direction_output = ti_ads7950_direction_output; in ti_ads7950_probe()
643 st->chip.get = ti_ads7950_get; in ti_ads7950_probe()
644 st->chip.set = ti_ads7950_set; in ti_ads7950_probe()
646 ret = gpiochip_add_data(&st->chip, st); in ti_ads7950_probe()
648 dev_err(&spi->dev, "Failed to init GPIOs\n"); in ti_ads7950_probe()
659 regulator_disable(st->reg); in ti_ads7950_probe()
661 mutex_destroy(&st->slock); in ti_ads7950_probe()
671 gpiochip_remove(&st->chip); in ti_ads7950_remove()
674 regulator_disable(st->reg); in ti_ads7950_remove()
675 mutex_destroy(&st->slock); in ti_ads7950_remove()