Lines Matching +full:spi +full:- +full:gpio
5 * Copyright (c) 2018-2018 David Veenstra <davidjulianveenstra@gmail.com>
6 * Copyright (c) 2010-2010 Analog Devices Inc.
16 #include <linux/gpio.h>
17 #include <linux/gpio/consumer.h>
20 #include <linux/spi/spi.h>
35 * struct ad2s1200_state - driver instance specific data.
36 * @lock: protects both the GPIO pins and the rx buffer.
37 * @sdev: spi device.
38 * @sample: GPIO pin SAMPLE.
39 * @rdvel: GPIO pin RDVEL.
40 * @rx: buffer for spi transfers.
61 switch (chan->type) { in ad2s1200_read_raw()
63 /* 2 * Pi / (2^12 - 1) ~= 0.001534355 */ in ad2s1200_read_raw()
73 return -EINVAL; in ad2s1200_read_raw()
77 mutex_lock(&st->lock); in ad2s1200_read_raw()
78 gpiod_set_value(st->sample, 0); in ad2s1200_read_raw()
82 gpiod_set_value(st->sample, 1); in ad2s1200_read_raw()
83 gpiod_set_value(st->rdvel, !!(chan->type == IIO_ANGL)); in ad2s1200_read_raw()
85 ret = spi_read(st->sdev, &st->rx, 2); in ad2s1200_read_raw()
87 mutex_unlock(&st->lock); in ad2s1200_read_raw()
91 switch (chan->type) { in ad2s1200_read_raw()
93 *val = be16_to_cpup(&st->rx) >> 4; in ad2s1200_read_raw()
96 *val = sign_extend32(be16_to_cpup(&st->rx) >> 4, 11); in ad2s1200_read_raw()
99 mutex_unlock(&st->lock); in ad2s1200_read_raw()
100 return -EINVAL; in ad2s1200_read_raw()
105 mutex_unlock(&st->lock); in ad2s1200_read_raw()
112 return -EINVAL; in ad2s1200_read_raw()
135 static int ad2s1200_probe(struct spi_device *spi) in ad2s1200_probe() argument
141 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad2s1200_probe()
143 return -ENOMEM; in ad2s1200_probe()
145 spi_set_drvdata(spi, indio_dev); in ad2s1200_probe()
147 mutex_init(&st->lock); in ad2s1200_probe()
148 st->sdev = spi; in ad2s1200_probe()
150 st->sample = devm_gpiod_get(&spi->dev, "adi,sample", GPIOD_OUT_LOW); in ad2s1200_probe()
151 if (IS_ERR(st->sample)) { in ad2s1200_probe()
152 dev_err(&spi->dev, "Failed to claim SAMPLE gpio: err=%ld\n", in ad2s1200_probe()
153 PTR_ERR(st->sample)); in ad2s1200_probe()
154 return PTR_ERR(st->sample); in ad2s1200_probe()
157 st->rdvel = devm_gpiod_get(&spi->dev, "adi,rdvel", GPIOD_OUT_LOW); in ad2s1200_probe()
158 if (IS_ERR(st->rdvel)) { in ad2s1200_probe()
159 dev_err(&spi->dev, "Failed to claim RDVEL gpio: err=%ld\n", in ad2s1200_probe()
160 PTR_ERR(st->rdvel)); in ad2s1200_probe()
161 return PTR_ERR(st->rdvel); in ad2s1200_probe()
164 indio_dev->dev.parent = &spi->dev; in ad2s1200_probe()
165 indio_dev->info = &ad2s1200_info; in ad2s1200_probe()
166 indio_dev->modes = INDIO_DIRECT_MODE; in ad2s1200_probe()
167 indio_dev->channels = ad2s1200_channels; in ad2s1200_probe()
168 indio_dev->num_channels = ARRAY_SIZE(ad2s1200_channels); in ad2s1200_probe()
169 indio_dev->name = spi_get_device_id(spi)->name; in ad2s1200_probe()
171 spi->max_speed_hz = AD2S1200_HZ; in ad2s1200_probe()
172 spi->mode = SPI_MODE_3; in ad2s1200_probe()
173 ret = spi_setup(spi); in ad2s1200_probe()
176 dev_err(&spi->dev, "spi_setup failed!\n"); in ad2s1200_probe()
180 return devm_iio_device_register(&spi->dev, indio_dev); in ad2s1200_probe()
195 MODULE_DEVICE_TABLE(spi, ad2s1200_id);
209 MODULE_DESCRIPTION("Analog Devices AD2S1200/1205 Resolver to Digital SPI driver");