summaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc/ti-ads7950.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-10-01 18:13:42 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-10-01 18:13:42 -0700
commit1c4ccab04a214604eff40e26649cdf00a7930506 (patch)
tree836084fe8b5b5f1e2b75adf59cd3d7dcbb8cd9af /drivers/iio/adc/ti-ads7950.c
parente2c3860ba27d21f991bf9b81d64589f7c9e087c1 (diff)
parent8911a43bc198877fad9f4b0246a866b26bb547ab (diff)
Merge tag 'iio-for-4.20b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes: Second set of IIO new device support features and cleanup for the 4.20 cycle. One merge commit in here to bring in the SPI_CS_WORD flag patches that are also going via the SPI tree. There are a few more fixes than normal for a pull targetting the next merge window. These are all long term issues and as we are late in the cycle, they can wait. New device support * ad7606 - Add support fo the ad7605-4 driver. This driver is still in staging but is heading in the right direction to graduate, motivated partly by the requirement for this device support. * ST VL53L0X ToF ranging sensor - New minimal driver. Interrupt support to follow. New features * SPI_CS_WORD optimization allows long transfers with the chip select toggled every 16bits. There is a software fallback as well to let drivers not care about whether the hardware supports it. * bh1750 - Device tree support and bindings. * ti-ads7950 - Use the SPI_CS_WORD optmization to save lots of cpu cycles (assuming the hardware supports it) Fixes and cleanups * ad5064 - Fix some long incorrect regulator error handling that preventing enabling the internal regulator. * ad7606 - The ad7606 doesn't actually have a 2.5V range and the values provided for scale have always been wrong. Fix them. - Drop some wrong kernel-doc (things that don't exist) - Add missing kernel-doc * at91-adc - Fixing missing ack of dataready on sysfs channel reads to avoid spurious interrupts. - Fix a wrong channel numbers in triggered_buffer_mode * hmc5843 - Fix incorrect part number in a comment. * imx25-gcq - Fix a device_node leak in an error path. * meson-saradc - Drop an unused and pointless define. - Use of_device_get_match_data instead of opencoding - Tidy up how meson_sar_adc_param is accessed. - Rework prior to adding some temperature sensor support. * tag 'iio-for-4.20b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: iio: ad5064: Fix regulator handling iio: adc: meson-saradc: use the address attribute from iio_chan_spec iio: adc: meson-saradc: do not use meson_sar_adc_iio_channels directly iio: adc: at91: fix wrong channel number in triggered buffer mode iio: adc: at91: fix acking DRDY irq on simple conversions iio: adc: meson-saradc: simplify access to meson_sar_adc_param iio: adc: meson-saradc: use of_device_get_match_data iio: adc: meson-saradc: remove #define MESON_SAR_ADC_DELTA_10_TS_C_SHIFT iio: light: bh1750: Add device tree support dt-bindings: iio: light: bh1750: Add device tree binding documentation staging:iio:ad7606: Add support for the ad7605-4 iio: proximity: Add driver support for ST's VL53L0X ToF ranging sensor. staging:iio:ad7606: update structs with doc annotations iio: magnetometer: hmc5843: Fixed a comment error. iio: adc: imx25-gcq: Fix leak of device_node in mx25_gcq_setup_cfgs() iio: adc: ti-ads7950: use SPI_CS_WORD to reduce CPU usage spi: add software implementation for SPI_CS_WORD spi: add new SPI_CS_WORD flag staging:iio:ad7606: Remove incorrect kernel doc annotations staging:iio:ad7606: fix voltage scales
Diffstat (limited to 'drivers/iio/adc/ti-ads7950.c')
-rw-r--r--drivers/iio/adc/ti-ads7950.c53
1 files changed, 31 insertions, 22 deletions
diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c
index a5bd5944bc66..0ad63592cc3c 100644
--- a/drivers/iio/adc/ti-ads7950.c
+++ b/drivers/iio/adc/ti-ads7950.c
@@ -51,7 +51,7 @@
struct ti_ads7950_state {
struct spi_device *spi;
- struct spi_transfer ring_xfer[TI_ADS7950_MAX_CHAN + 2];
+ struct spi_transfer ring_xfer;
struct spi_transfer scan_single_xfer[3];
struct spi_message ring_msg;
struct spi_message scan_single_msg;
@@ -65,11 +65,11 @@ struct ti_ads7950_state {
* DMA (thus cache coherency maintenance) requires the
* transfer buffers to live in their own cache lines.
*/
- __be16 rx_buf[TI_ADS7950_MAX_CHAN + TI_ADS7950_TIMESTAMP_SIZE]
+ u16 rx_buf[TI_ADS7950_MAX_CHAN + 2 + TI_ADS7950_TIMESTAMP_SIZE]
____cacheline_aligned;
- __be16 tx_buf[TI_ADS7950_MAX_CHAN];
- __be16 single_tx;
- __be16 single_rx;
+ u16 tx_buf[TI_ADS7950_MAX_CHAN + 2];
+ u16 single_tx;
+ u16 single_rx;
};
@@ -108,7 +108,7 @@ enum ti_ads7950_id {
.realbits = bits, \
.storagebits = 16, \
.shift = 12 - (bits), \
- .endianness = IIO_BE, \
+ .endianness = IIO_CPU, \
}, \
}
@@ -249,23 +249,14 @@ static int ti_ads7950_update_scan_mode(struct iio_dev *indio_dev,
len = 0;
for_each_set_bit(i, active_scan_mask, indio_dev->num_channels) {
cmd = TI_ADS7950_CR_WRITE | TI_ADS7950_CR_CHAN(i) | st->settings;
- st->tx_buf[len++] = cpu_to_be16(cmd);
+ st->tx_buf[len++] = cmd;
}
/* Data for the 1st channel is not returned until the 3rd transfer */
- len += 2;
- for (i = 0; i < len; i++) {
- if ((i + 2) < len)
- st->ring_xfer[i].tx_buf = &st->tx_buf[i];
- if (i >= 2)
- st->ring_xfer[i].rx_buf = &st->rx_buf[i - 2];
- st->ring_xfer[i].len = 2;
- st->ring_xfer[i].cs_change = 1;
- }
- /* make sure last transfer's cs_change is not set */
- st->ring_xfer[len - 1].cs_change = 0;
+ st->tx_buf[len++] = 0;
+ st->tx_buf[len++] = 0;
- spi_message_init_with_transfers(&st->ring_msg, st->ring_xfer, len);
+ st->ring_xfer.len = len * 2;
return 0;
}
@@ -281,7 +272,7 @@ static irqreturn_t ti_ads7950_trigger_handler(int irq, void *p)
if (ret < 0)
goto out;
- iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf,
+ iio_push_to_buffers_with_timestamp(indio_dev, &st->rx_buf[2],
iio_get_time_ns(indio_dev));
out:
@@ -298,13 +289,13 @@ static int ti_ads7950_scan_direct(struct iio_dev *indio_dev, unsigned int ch)
mutex_lock(&indio_dev->mlock);
cmd = TI_ADS7950_CR_WRITE | TI_ADS7950_CR_CHAN(ch) | st->settings;
- st->single_tx = cpu_to_be16(cmd);
+ st->single_tx = cmd;
ret = spi_sync(st->spi, &st->scan_single_msg);
if (ret)
goto out;
- ret = be16_to_cpu(st->single_rx);
+ ret = st->single_rx;
out:
mutex_unlock(&indio_dev->mlock);
@@ -378,6 +369,14 @@ static int ti_ads7950_probe(struct spi_device *spi)
const struct ti_ads7950_chip_info *info;
int ret;
+ spi->bits_per_word = 16;
+ spi->mode |= SPI_CS_WORD;
+ ret = spi_setup(spi);
+ if (ret < 0) {
+ dev_err(&spi->dev, "Error in spi setup\n");
+ return ret;
+ }
+
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
if (!indio_dev)
return -ENOMEM;
@@ -398,6 +397,16 @@ static int ti_ads7950_probe(struct spi_device *spi)
indio_dev->num_channels = info->num_channels;
indio_dev->info = &ti_ads7950_info;
+ /* build spi ring message */
+ spi_message_init(&st->ring_msg);
+
+ st->ring_xfer.tx_buf = &st->tx_buf[0];
+ st->ring_xfer.rx_buf = &st->rx_buf[0];
+ /* len will be set later */
+ st->ring_xfer.cs_change = true;
+
+ spi_message_add_tail(&st->ring_xfer, &st->ring_msg);
+
/*
* Setup default message. The sample is read at the end of the first
* transfer, then it takes one full cycle to convert the sample and one