summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Miguel Silva <rui.silva@linaro.org>2017-09-20 22:22:08 +0100
committerBryan O'Donoghue <bryan.odonoghue@linaro.org>2019-05-01 11:51:18 +0100
commit35281ecdf5e55fd44482916fba008a8610289fcf (patch)
tree2cdfe5c0a2b103a46fd370d3f291b392bf77f4b5
parent697b1ab55e6b0ae4f629b088e7cb9f7b9b16c0ea (diff)
iio: accel: fxos8700: add spi driver
Add driver to communicate over spi to fxos8700 accel/magnetometer combo device and use fxos8700_core for main tasks. Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
-rw-r--r--drivers/iio/accel/Kconfig5
-rw-r--r--drivers/iio/accel/Makefile1
-rw-r--r--drivers/iio/accel/fxos8700_spi.c71
3 files changed, 77 insertions, 0 deletions
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 1c7e74e69617..1aeca12181d5 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -139,6 +139,7 @@ config FXOS8700_ACCEL_MAGN
select IIO_BUFFER
select REGMAP
select FXOS8700_ACCEL_MAGN_I2C if I2C
+ select FXOS8700_ACCEL_MAGN_SPI if SPI
help
Say yes here to build support for the FXOS8700 accelerometer /
magnetometer.
@@ -149,6 +150,10 @@ config FXOS8700_ACCEL_MAGN_I2C
tristate
select REGMAP_I2C
+config FXOS8700_ACCEL_MAGN_SPI
+ tristate
+ select REGMAP_SPI
+
config HID_SENSOR_ACCEL_3D
depends on HID_SENSOR_HUB
select IIO_BUFFER
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index 1ffb24cf8267..f9f0c7356e99 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_DMARD09) += dmard09.o
obj-$(CONFIG_DMARD10) += dmard10.o
obj-$(CONFIG_FXOS8700_ACCEL_MAGN) += fxos8700_core.o
obj-$(CONFIG_FXOS8700_ACCEL_MAGN_I2C) += fxos8700_i2c.o
+obj-$(CONFIG_FXOS8700_ACCEL_MAGN_SPI) += fxos8700_spi.o
obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
obj-$(CONFIG_KXSD9) += kxsd9.o
diff --git a/drivers/iio/accel/fxos8700_spi.c b/drivers/iio/accel/fxos8700_spi.c
new file mode 100644
index 000000000000..234726a96410
--- /dev/null
+++ b/drivers/iio/accel/fxos8700_spi.c
@@ -0,0 +1,71 @@
+/*
+ * Driver for NXP Fxos8700 Accelerometer and Magnetometer - SPI
+ *
+ * Copyright (C) 2017 Linaro Ltd.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/regmap.h>
+#include <linux/spi/spi.h>
+
+#include "fxos8700.h"
+
+static const struct regmap_config fxos8700_regmap_spi_conf = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = FXOS8700_REG_NVM_DATA_BNK0,
+};
+
+static int fxos8700_spi_probe(struct spi_device *spi)
+{
+ const struct spi_device_id *id = spi_get_device_id(spi);
+ struct regmap *regmap;
+
+ regmap = devm_regmap_init_spi(spi, &fxos8700_regmap_spi_conf);
+ if (IS_ERR(regmap)) {
+ dev_err(&spi->dev, "Failed to register spi regmap: %ld\n",
+ PTR_ERR(regmap));
+ return PTR_ERR(regmap);
+ }
+
+ return fxos8700_core_probe(&spi->dev, regmap, id->name);
+}
+
+static int fxos8700_spi_remove(struct spi_device *spi)
+{
+ fxos8700_core_remove(&spi->dev);
+
+ return 0;
+}
+
+static const struct spi_device_id fxos8700_spi_id[] = {
+ { "fxos8700", 0 },
+ { }
+};
+MODULE_DEVICE_TABLE(spi, fxos8700_spi_id);
+
+#ifdef CONFIG_OF
+static const struct of_device_id fxos8700_spi_of_match[] = {
+ { .compatible = "nxp,fxos8700", },
+ { },
+};
+MODULE_DEVICE_TABLE(of, fxos8700_spi_of_match);
+#endif
+
+static struct spi_driver fxos8700_spi_driver = {
+ .driver = {
+ .name = "fxos8700_spi",
+ .pm = &fxos8700_pm_ops,
+ .of_match_table = of_match_ptr(fxos8700_spi_of_match),
+ },
+ .probe = fxos8700_spi_probe,
+ .remove = fxos8700_spi_remove,
+ .id_table = fxos8700_spi_id,
+};
+module_spi_driver(fxos8700_spi_driver);
+
+MODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("FXOS8700 SPI Accel and Magnet driver");