staging:iio:hmc5843: Add support for spi hmc5983
authorJosef Gajdusek <atx@atalax.net>
Tue, 22 Jul 2014 15:03:00 +0000 (16:03 +0100)
committerJonathan Cameron <jic23@kernel.org>
Wed, 23 Jul 2014 20:48:24 +0000 (21:48 +0100)
This patch adds support for the hmc5983 spi interface.
This chip is almost identical to the hmc5883. The difference being added
temperature compensation, additional available sample rate (220Hz) and an SPI
interface.

Signed-off-by: Josef Gajdusek <atx@atx.name>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/staging/iio/magnetometer/Kconfig
drivers/staging/iio/magnetometer/Makefile
drivers/staging/iio/magnetometer/hmc5843_spi.c [new file with mode: 0644]

index c086f33b6311d1bc2163bed451accbbb819094ba..dec814a7a0735c809a9b8093b9c1782ab15de034 100644 (file)
@@ -22,4 +22,19 @@ config SENSORS_HMC5843_I2C
          - hmc5843_core (core functions)
          - hmc5843_i2c (support for HMC5843, HMC5883, HMC5883L and HMC5983)
 
+config SENSORS_HMC5843_SPI
+       tristate "Honeywell HMC5983 3-Axis Magnetometer (SPI)"
+       depends on SPI_MASTER
+       select SENSORS_HMC5843
+       select REGMAP_SPI
+       help
+         Say Y here to add support for the Honeywell HMC5983 3-Axis Magnetometer
+         (digital compass).
+
+         This driver can also be compiled as a set of modules.
+         If so, these modules will be created:
+         - hmc5843_core (core functions)
+         - hmc5843_spi (support for HMC5983)
+
+
 endmenu
index 65baf1c4da4237d079d2e760892047b73a7d36c8..33761a19a956f942e564967ca6c2029a0ddcb13c 100644 (file)
@@ -4,3 +4,4 @@
 
 obj-$(CONFIG_SENSORS_HMC5843)          += hmc5843_core.o
 obj-$(CONFIG_SENSORS_HMC5843_I2C)      += hmc5843_i2c.o
+obj-$(CONFIG_SENSORS_HMC5843_SPI)      += hmc5843_spi.o
diff --git a/drivers/staging/iio/magnetometer/hmc5843_spi.c b/drivers/staging/iio/magnetometer/hmc5843_spi.c
new file mode 100644 (file)
index 0000000..98c4b57
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * SPI driver for hmc5983
+ *
+ * Copyright (C) Josef Gajdusek <atx@atx.name>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * */
+
+#include <linux/module.h>
+#include <linux/spi/spi.h>
+#include <linux/iio/iio.h>
+
+#include "hmc5843.h"
+
+static const struct regmap_range hmc5843_readable_ranges[] = {
+               regmap_reg_range(0, HMC5843_ID_END),
+};
+
+static struct regmap_access_table hmc5843_readable_table = {
+               .yes_ranges = hmc5843_readable_ranges,
+               .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges),
+};
+
+static const struct regmap_range hmc5843_writable_ranges[] = {
+               regmap_reg_range(0, HMC5843_MODE_REG),
+};
+
+static struct regmap_access_table hmc5843_writable_table = {
+               .yes_ranges = hmc5843_writable_ranges,
+               .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges),
+};
+
+static const struct regmap_range hmc5843_volatile_ranges[] = {
+               regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG),
+};
+
+static struct regmap_access_table hmc5843_volatile_table = {
+               .yes_ranges = hmc5843_volatile_ranges,
+               .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges),
+};
+
+static struct regmap_config hmc5843_spi_regmap_config = {
+               .reg_bits = 8,
+               .val_bits = 8,
+
+               .rd_table = &hmc5843_readable_table,
+               .wr_table = &hmc5843_writable_table,
+               .volatile_table = &hmc5843_volatile_table,
+
+               /* Autoincrement address pointer */
+               .read_flag_mask = 0xc0,
+
+               .cache_type = REGCACHE_RBTREE,
+};
+
+static int hmc5843_spi_probe(struct spi_device *spi)
+{
+       int ret;
+
+       spi->mode = SPI_MODE_3;
+       spi->max_speed_hz = 8000000;
+       spi->bits_per_word = 8;
+       ret = spi_setup(spi);
+       if (ret)
+               return ret;
+
+       return hmc5843_common_probe(&spi->dev,
+                       devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config),
+                       HMC5983_ID);
+}
+
+static int hmc5843_spi_remove(struct spi_device *spi)
+{
+       return hmc5843_common_remove(&spi->dev);
+}
+
+static const struct spi_device_id hmc5843_id[] = {
+       { "hmc5983", HMC5983_ID },
+       { }
+};
+
+static struct spi_driver hmc5843_driver = {
+               .driver = {
+                               .name = "hmc5843",
+                               .pm = HMC5843_PM_OPS,
+                               .owner = THIS_MODULE,
+               },
+               .id_table = hmc5843_id,
+               .probe = hmc5843_spi_probe,
+               .remove = hmc5843_spi_remove,
+};
+
+module_spi_driver(hmc5843_driver);
+
+MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
+MODULE_DESCRIPTION("HMC5983 SPI driver");
+MODULE_LICENSE("GPL");