Lines Matching +full:rx +full:- +full:input +full:- +full:m

1 // SPDX-License-Identifier: GPL-2.0-only
6 * Copyright (c) 2018-2018 David Veenstra <davidjulianveenstra@gmail.com>
7 * Copyright (c) 2010-2010 Analog Devices Inc.
26 /* input clock on serial interface */
32 * struct ad2s1200_state - driver instance specific data.
33 * @lock: protects both the GPIO pins and the rx buffer.
37 * @rx: buffer for spi transfers.
44 __be16 rx __aligned(IIO_DMA_MINALIGN);
51 long m) in ad2s1200_read_raw() argument
56 switch (m) { in ad2s1200_read_raw()
58 switch (chan->type) { in ad2s1200_read_raw()
60 /* 2 * Pi / (2^12 - 1) ~= 0.001534355 */ in ad2s1200_read_raw()
70 return -EINVAL; in ad2s1200_read_raw()
74 mutex_lock(&st->lock); in ad2s1200_read_raw()
75 gpiod_set_value(st->sample, 0); in ad2s1200_read_raw()
79 gpiod_set_value(st->sample, 1); in ad2s1200_read_raw()
80 gpiod_set_value(st->rdvel, !!(chan->type == IIO_ANGL)); in ad2s1200_read_raw()
82 ret = spi_read(st->sdev, &st->rx, 2); in ad2s1200_read_raw()
84 mutex_unlock(&st->lock); in ad2s1200_read_raw()
88 switch (chan->type) { in ad2s1200_read_raw()
90 *val = be16_to_cpup(&st->rx) >> 4; in ad2s1200_read_raw()
93 *val = sign_extend32(be16_to_cpup(&st->rx) >> 4, 11); in ad2s1200_read_raw()
96 mutex_unlock(&st->lock); in ad2s1200_read_raw()
97 return -EINVAL; in ad2s1200_read_raw()
102 mutex_unlock(&st->lock); in ad2s1200_read_raw()
109 return -EINVAL; in ad2s1200_read_raw()
138 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad2s1200_probe()
140 return -ENOMEM; in ad2s1200_probe()
144 mutex_init(&st->lock); in ad2s1200_probe()
145 st->sdev = spi; in ad2s1200_probe()
147 st->sample = devm_gpiod_get(&spi->dev, "adi,sample", GPIOD_OUT_LOW); in ad2s1200_probe()
148 if (IS_ERR(st->sample)) { in ad2s1200_probe()
149 dev_err(&spi->dev, "Failed to claim SAMPLE gpio: err=%ld\n", in ad2s1200_probe()
150 PTR_ERR(st->sample)); in ad2s1200_probe()
151 return PTR_ERR(st->sample); in ad2s1200_probe()
154 st->rdvel = devm_gpiod_get(&spi->dev, "adi,rdvel", GPIOD_OUT_LOW); in ad2s1200_probe()
155 if (IS_ERR(st->rdvel)) { in ad2s1200_probe()
156 dev_err(&spi->dev, "Failed to claim RDVEL gpio: err=%ld\n", in ad2s1200_probe()
157 PTR_ERR(st->rdvel)); in ad2s1200_probe()
158 return PTR_ERR(st->rdvel); in ad2s1200_probe()
161 indio_dev->info = &ad2s1200_info; in ad2s1200_probe()
162 indio_dev->modes = INDIO_DIRECT_MODE; in ad2s1200_probe()
163 indio_dev->channels = ad2s1200_channels; in ad2s1200_probe()
164 indio_dev->num_channels = ARRAY_SIZE(ad2s1200_channels); in ad2s1200_probe()
165 indio_dev->name = spi_get_device_id(spi)->name; in ad2s1200_probe()
167 spi->max_speed_hz = AD2S1200_HZ; in ad2s1200_probe()
168 spi->mode = SPI_MODE_3; in ad2s1200_probe()
172 dev_err(&spi->dev, "spi_setup failed!\n"); in ad2s1200_probe()
176 return devm_iio_device_register(&spi->dev, indio_dev); in ad2s1200_probe()