iio: bmc150: Add SPI driver
authorMarkus Pargmann <mpa@pengutronix.de>
Mon, 21 Sep 2015 10:55:16 +0000 (12:55 +0200)
committerJonathan Cameron <jic23@kernel.org>
Sat, 3 Oct 2015 11:06:38 +0000 (12:06 +0100)
Add a simple SPI driver which initializes the spi regmap for the bmc150
core driver.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/accel/Kconfig
drivers/iio/accel/Makefile
drivers/iio/accel/bmc150-accel-spi.c [new file with mode: 0644]

index bb00770b63bdc5028e810359c5d4c5b68b22a0f7..969428dd63299af04e4200ae309f971463f3f5eb 100644 (file)
@@ -23,6 +23,7 @@ config BMC150_ACCEL
        select IIO_TRIGGERED_BUFFER
        select REGMAP
        select BMC150_ACCEL_I2C if I2C
+       select BMC150_ACCEL_SPI if SPI
        help
          Say yes here to build support for the following Bosch accelerometers:
          BMC150, BMI055, BMA250E, BMA222E, BMA255, BMA280.
@@ -35,6 +36,10 @@ config BMC150_ACCEL_I2C
        tristate
        select REGMAP_I2C
 
+config BMC150_ACCEL_SPI
+       tristate
+       select REGMAP_SPI
+
 config HID_SENSOR_ACCEL_3D
        depends on HID_SENSOR_HUB
        select IIO_BUFFER
index 80764363f7b8abdf3c972d2f8d4d5edd32bbe41c..7925f166e6e957c76cf7acc9862ea603f23d9ea0 100644 (file)
@@ -6,6 +6,7 @@
 obj-$(CONFIG_BMA180) += bma180.o
 obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o
 obj-$(CONFIG_BMC150_ACCEL_I2C) += bmc150-accel-i2c.o
+obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-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/bmc150-accel-spi.c b/drivers/iio/accel/bmc150-accel-spi.c
new file mode 100644 (file)
index 0000000..16b66f2
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * 3-axis accelerometer driver supporting SPI Bosch-Sensortec accelerometer chip
+ * Copyright © 2015 Pengutronix, Markus Pargmann <mpa@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/device.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/acpi.h>
+#include <linux/regmap.h>
+#include <linux/spi/spi.h>
+
+#include "bmc150-accel.h"
+
+static const struct regmap_config bmc150_spi_regmap_conf = {
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = 0x3f,
+};
+
+static int bmc150_accel_probe(struct spi_device *spi)
+{
+       struct regmap *regmap;
+       const struct spi_device_id *id = spi_get_device_id(spi);
+
+       regmap = devm_regmap_init_spi(spi, &bmc150_spi_regmap_conf);
+       if (IS_ERR(regmap)) {
+               dev_err(&spi->dev, "Failed to initialize spi regmap\n");
+               return PTR_ERR(regmap);
+       }
+
+       return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, id->name,
+                                      true);
+}
+
+static int bmc150_accel_remove(struct spi_device *spi)
+{
+       return bmc150_accel_core_remove(&spi->dev);
+}
+
+static const struct acpi_device_id bmc150_accel_acpi_match[] = {
+       {"BSBA0150",    bmc150},
+       {"BMC150A",     bmc150},
+       {"BMI055A",     bmi055},
+       {"BMA0255",     bma255},
+       {"BMA250E",     bma250e},
+       {"BMA222E",     bma222e},
+       {"BMA0280",     bma280},
+       { },
+};
+MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match);
+
+static const struct spi_device_id bmc150_accel_id[] = {
+       {"bmc150_accel",        bmc150},
+       {"bmi055_accel",        bmi055},
+       {"bma255",              bma255},
+       {"bma250e",             bma250e},
+       {"bma222e",             bma222e},
+       {"bma280",              bma280},
+       {}
+};
+MODULE_DEVICE_TABLE(spi, bmc150_accel_id);
+
+static struct spi_driver bmc150_accel_driver = {
+       .driver = {
+               .name   = "bmc150_accel_spi",
+               .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match),
+               .pm     = &bmc150_accel_pm_ops,
+       },
+       .probe          = bmc150_accel_probe,
+       .remove         = bmc150_accel_remove,
+       .id_table       = bmc150_accel_id,
+};
+module_spi_driver(bmc150_accel_driver);
+
+MODULE_AUTHOR("Markus Pargmann <mpa@pengutronix.de>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("BMC150 SPI accelerometer driver");