summaryrefslogtreecommitdiff
path: root/drivers/iio/humidity/hts221_spi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio/humidity/hts221_spi.c')
-rw-r--r--drivers/iio/humidity/hts221_spi.c81
1 files changed, 19 insertions, 62 deletions
diff --git a/drivers/iio/humidity/hts221_spi.c b/drivers/iio/humidity/hts221_spi.c
index 55b29b53b9d1..9c005f037026 100644
--- a/drivers/iio/humidity/hts221_spi.c
+++ b/drivers/iio/humidity/hts221_spi.c
@@ -12,76 +12,33 @@
#include <linux/module.h>
#include <linux/spi/spi.h>
#include <linux/slab.h>
-#include "hts221.h"
-
-#define SENSORS_SPI_READ 0x80
-#define SPI_AUTO_INCREMENT 0x40
-
-static int hts221_spi_read(struct device *dev, u8 addr, int len, u8 *data)
-{
- int err;
- struct spi_device *spi = to_spi_device(dev);
- struct iio_dev *iio_dev = spi_get_drvdata(spi);
- struct hts221_hw *hw = iio_priv(iio_dev);
-
- struct spi_transfer xfers[] = {
- {
- .tx_buf = hw->tb.tx_buf,
- .bits_per_word = 8,
- .len = 1,
- },
- {
- .rx_buf = hw->tb.rx_buf,
- .bits_per_word = 8,
- .len = len,
- }
- };
-
- if (len > 1)
- addr |= SPI_AUTO_INCREMENT;
- hw->tb.tx_buf[0] = addr | SENSORS_SPI_READ;
-
- err = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers));
- if (err < 0)
- return err;
-
- memcpy(data, hw->tb.rx_buf, len * sizeof(u8));
-
- return len;
-}
-
-static int hts221_spi_write(struct device *dev, u8 addr, int len, u8 *data)
-{
- struct spi_device *spi = to_spi_device(dev);
- struct iio_dev *iio_dev = spi_get_drvdata(spi);
- struct hts221_hw *hw = iio_priv(iio_dev);
-
- struct spi_transfer xfers = {
- .tx_buf = hw->tb.tx_buf,
- .bits_per_word = 8,
- .len = len + 1,
- };
-
- if (len >= HTS221_TX_MAX_LENGTH)
- return -ENOMEM;
+#include <linux/regmap.h>
- if (len > 1)
- addr |= SPI_AUTO_INCREMENT;
- hw->tb.tx_buf[0] = addr;
- memcpy(&hw->tb.tx_buf[1], data, len);
+#include "hts221.h"
- return spi_sync_transfer(spi, &xfers, 1);
-}
+#define HTS221_SPI_READ BIT(7)
+#define HTS221_SPI_AUTO_INCREMENT BIT(6)
-static const struct hts221_transfer_function hts221_transfer_fn = {
- .read = hts221_spi_read,
- .write = hts221_spi_write,
+static const struct regmap_config hts221_spi_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .write_flag_mask = HTS221_SPI_AUTO_INCREMENT,
+ .read_flag_mask = HTS221_SPI_READ | HTS221_SPI_AUTO_INCREMENT,
};
static int hts221_spi_probe(struct spi_device *spi)
{
+ struct regmap *regmap;
+
+ regmap = devm_regmap_init_spi(spi, &hts221_spi_regmap_config);
+ if (IS_ERR(regmap)) {
+ dev_err(&spi->dev, "Failed to register spi regmap %d\n",
+ (int)PTR_ERR(regmap));
+ return PTR_ERR(regmap);
+ }
+
return hts221_probe(&spi->dev, spi->irq,
- spi->modalias, &hts221_transfer_fn);
+ spi->modalias, regmap);
}
static const struct of_device_id hts221_spi_of_match[] = {