Lines Matching refs:st
60 #define TI_ADS7950_MAN_CMD_SETTINGS(st) \ argument
61 (TI_ADS7950_MAN_CMD(TI_ADS7950_CR_WRITE | st->cmd_settings_bitmask))
63 #define TI_ADS7950_GPIO_CMD_SETTINGS(st) \ argument
64 (TI_ADS7950_GPIO_CMD(st->gpio_cmd_settings_bitmask))
286 struct ti_ads7950_state *st = iio_priv(indio_dev); in ti_ads7950_update_scan_mode() local
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()
308 struct ti_ads7950_state *st = iio_priv(indio_dev); in ti_ads7950_trigger_handler() local
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()
328 struct ti_ads7950_state *st = iio_priv(indio_dev); in ti_ads7950_scan_direct() local
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()
347 static int ti_ads7950_get_range(struct ti_ads7950_state *st) in ti_ads7950_get_range() argument
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()
371 struct ti_ads7950_state *st = iio_priv(indio_dev); in ti_ads7950_read_raw() local
388 ret = ti_ads7950_get_range(st); in ti_ads7950_read_raw()
409 struct ti_ads7950_state *st = gpiochip_get_data(chip); in ti_ads7950_set() local
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()
426 struct ti_ads7950_state *st = gpiochip_get_data(chip); in ti_ads7950_get() local
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()
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()
462 struct ti_ads7950_state *st = gpiochip_get_data(chip); in ti_ads7950_get_direction() local
465 return !(st->gpio_cmd_settings_bitmask & BIT(offset)); in ti_ads7950_get_direction()
471 struct ti_ads7950_state *st = gpiochip_get_data(chip); in _ti_ads7950_set_direction() local
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()
507 static int ti_ads7950_init_hw(struct ti_ads7950_state *st) in ti_ads7950_init_hw() argument
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()
534 struct ti_ads7950_state *st; in ti_ads7950_probe() local
547 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ti_ads7950_probe()
551 st = iio_priv(indio_dev); in ti_ads7950_probe()
555 st->spi = spi; 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()
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()
621 ret = ti_ads7950_init_hw(st); 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()
659 regulator_disable(st->reg); in ti_ads7950_probe()
661 mutex_destroy(&st->slock); in ti_ads7950_probe()
669 struct ti_ads7950_state *st = iio_priv(indio_dev); in ti_ads7950_remove() local
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()