diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2016-09-01 12:44:40 +0300 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2016-09-18 13:28:21 +0300 |
commit | 0d1fb2d52d8b4a1124cb2db7d22c4131ad5805cf (patch) | |
tree | 33e6f6fe5223f60dac2c166749bd3fcecb2b0790 /drivers/iio/accel/kxsd9-spi.c | |
parent | ab04f734b08a404550ba5f8391307bad2145acff (diff) | |
download | linux-0d1fb2d52d8b4a1124cb2db7d22c4131ad5805cf.tar.xz |
iio: accel: kxsd9: Convert to use regmap for transport
This converts the KXSD9 driver to drop the custom transport
mechanism and just use regmap like everything else.
Tested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/accel/kxsd9-spi.c')
-rw-r--r-- | drivers/iio/accel/kxsd9-spi.c | 79 |
1 files changed, 17 insertions, 62 deletions
diff --git a/drivers/iio/accel/kxsd9-spi.c b/drivers/iio/accel/kxsd9-spi.c index a49c10cd7634..c5af51b7dd7e 100644 --- a/drivers/iio/accel/kxsd9-spi.c +++ b/drivers/iio/accel/kxsd9-spi.c @@ -3,75 +3,30 @@ #include <linux/spi/spi.h> #include <linux/module.h> #include <linux/slab.h> +#include <linux/regmap.h> #include "kxsd9.h" -#define KXSD9_READ(a) (0x80 | (a)) -#define KXSD9_WRITE(a) (a) - -static int kxsd9_spi_readreg(struct kxsd9_transport *tr, u8 address) -{ - struct spi_device *spi = tr->trdev; - - return spi_w8r8(spi, KXSD9_READ(address)); -} - -static int kxsd9_spi_writereg(struct kxsd9_transport *tr, u8 address, u8 val) -{ - struct spi_device *spi = tr->trdev; - - tr->tx[0] = KXSD9_WRITE(address), - tr->tx[1] = val; - return spi_write(spi, tr->tx, 2); -} - -static int kxsd9_spi_readval(struct kxsd9_transport *tr, u8 address) -{ - struct spi_device *spi = tr->trdev; - struct spi_transfer xfers[] = { - { - .bits_per_word = 8, - .len = 1, - .delay_usecs = 200, - .tx_buf = tr->tx, - }, { - .bits_per_word = 8, - .len = 2, - .rx_buf = tr->rx, - }, - }; - int ret; - - tr->tx[0] = KXSD9_READ(address); - ret = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers)); - if (!ret) - ret = (((u16)(tr->rx[0])) << 8) | (tr->rx[1]); - return ret; -} - static int kxsd9_spi_probe(struct spi_device *spi) { - struct kxsd9_transport *transport; - int ret; - - transport = devm_kzalloc(&spi->dev, sizeof(*transport), GFP_KERNEL); - if (!transport) - return -ENOMEM; + static const struct regmap_config config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = 0x0e, + }; + struct regmap *regmap; - transport->trdev = spi; - transport->readreg = kxsd9_spi_readreg; - transport->writereg = kxsd9_spi_writereg; - transport->readval = kxsd9_spi_readval; spi->mode = SPI_MODE_0; - spi_setup(spi); - - ret = kxsd9_common_probe(&spi->dev, - transport, - spi_get_device_id(spi)->name); - if (ret) - return ret; - - return 0; + regmap = devm_regmap_init_spi(spi, &config); + if (IS_ERR(regmap)) { + dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n", + __func__, PTR_ERR(regmap)); + return PTR_ERR(regmap); + } + + return kxsd9_common_probe(&spi->dev, + regmap, + spi_get_device_id(spi)->name); } static int kxsd9_spi_remove(struct spi_device *spi) |