Merge branch 'for_linus' of git://cavan.codon.org.uk/platform-drivers-x86
[firefly-linux-kernel-4.4.55.git] / drivers / iio / dac / ad5504.c
index c0957a918e17128b31bf7c1a4fbf743253b3cca3..1e6449346b50868fadecda845b1f19af46a16c40 100644 (file)
  * @vref_mv:           actual reference voltage used
  * @pwr_down_mask      power down mask
  * @pwr_down_mode      current power down mode
+ * @data:              transfer buffer
  */
-
 struct ad5504_state {
        struct spi_device               *spi;
        struct regulator                *reg;
        unsigned short                  vref_mv;
        unsigned                        pwr_down_mask;
        unsigned                        pwr_down_mode;
+
+       __be16                          data[2] ____cacheline_aligned;
 };
 
 /**
@@ -66,31 +68,29 @@ enum ad5504_supported_device_ids {
        ID_AD5501,
 };
 
-static int ad5504_spi_write(struct spi_device *spi, u8 addr, u16 val)
+static int ad5504_spi_write(struct ad5504_state *st, u8 addr, u16 val)
 {
-       u16 tmp = cpu_to_be16(AD5504_CMD_WRITE |
-                             AD5504_ADDR(addr) |
+       st->data[0] = cpu_to_be16(AD5504_CMD_WRITE | AD5504_ADDR(addr) |
                              (val & AD5504_RES_MASK));
 
-       return spi_write(spi, (u8 *)&tmp, 2);
+       return spi_write(st->spi, &st->data[0], 2);
 }
 
-static int ad5504_spi_read(struct spi_device *spi, u8 addr)
+static int ad5504_spi_read(struct ad5504_state *st, u8 addr)
 {
-       u16 tmp = cpu_to_be16(AD5504_CMD_READ | AD5504_ADDR(addr));
-       u16 val;
        int ret;
-       struct spi_transfer     t = {
-                       .tx_buf         = &tmp,
-                       .rx_buf         = &val,
-                       .len            = 2,
-               };
-       ret = spi_sync_transfer(spi, &t, 1);
-
+       struct spi_transfer t = {
+           .tx_buf = &st->data[0],
+           .rx_buf = &st->data[1],
+           .len = 2,
+       };
+
+       st->data[0] = cpu_to_be16(AD5504_CMD_READ | AD5504_ADDR(addr));
+       ret = spi_sync_transfer(st->spi, &t, 1);
        if (ret < 0)
                return ret;
 
-       return be16_to_cpu(val) & AD5504_RES_MASK;
+       return be16_to_cpu(st->data[1]) & AD5504_RES_MASK;
 }
 
 static int ad5504_read_raw(struct iio_dev *indio_dev,
@@ -104,7 +104,7 @@ static int ad5504_read_raw(struct iio_dev *indio_dev,
 
        switch (m) {
        case IIO_CHAN_INFO_RAW:
-               ret = ad5504_spi_read(st->spi, chan->address);
+               ret = ad5504_spi_read(st, chan->address);
                if (ret < 0)
                        return ret;
 
@@ -133,7 +133,7 @@ static int ad5504_write_raw(struct iio_dev *indio_dev,
                if (val >= (1 << chan->scan_type.realbits) || val < 0)
                        return -EINVAL;
 
-               return ad5504_spi_write(st->spi, chan->address, val);
+               return ad5504_spi_write(st, chan->address, val);
        default:
                ret = -EINVAL;
        }
@@ -197,12 +197,12 @@ static ssize_t ad5504_write_dac_powerdown(struct iio_dev *indio_dev,
        else
                st->pwr_down_mask &= ~(1 << chan->channel);
 
-       ret = ad5504_spi_write(st->spi, AD5504_ADDR_CTRL,
+       ret = ad5504_spi_write(st, AD5504_ADDR_CTRL,
                                AD5504_DAC_PWRDWN_MODE(st->pwr_down_mode) |
                                AD5504_DAC_PWR(st->pwr_down_mask));
 
        /* writes to the CTRL register must be followed by a NOOP */
-       ad5504_spi_write(st->spi, AD5504_ADDR_NOOP, 0);
+       ad5504_spi_write(st, AD5504_ADDR_NOOP, 0);
 
        return ret ? ret : len;
 }
@@ -261,7 +261,11 @@ static const struct iio_chan_spec_ext_info ad5504_ext_info[] = {
        .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
        .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
        .address = AD5504_ADDR_DAC(_chan), \
-       .scan_type = IIO_ST('u', 12, 16, 0), \
+       .scan_type = { \
+               .sign = 'u', \
+               .realbits = 12, \
+               .storagebits = 16, \
+       }, \
        .ext_info = ad5504_ext_info, \
 }