Commit 121354b2 authored by Song Qiang's avatar Song Qiang Committed by Jonathan Cameron

iio: magnetometer: Add driver support for PNI RM3100

PNI RM3100 is a high resolution, large signal immunity magnetometer,
composed of 3 single sensors and a processing chip with a MagI2C
interface.

Following functions are available:
 - Single-shot measurement from
   /sys/bus/iio/devices/iio:deviceX/in_magn_{axis}_raw
 - Triggerd buffer measurement.
 - DRDY pin for data ready trigger.
 - Both i2c and spi interface are supported.
 - Both interrupt and polling measurement is supported, depends on if
   the 'interrupts' in DT is declared.
Signed-off-by: default avatarSong Qiang <songqiang1304521@gmail.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 9a8d64fa
......@@ -11607,6 +11607,13 @@ M: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
S: Maintained
F: drivers/pnp/
PNI RM3100 IIO DRIVER
M: Song Qiang <songqiang1304521@gmail.com>
L: linux-iio@vger.kernel.org
S: Maintained
F: drivers/iio/magnetometer/rm3100*
F: Documentation/devicetree/bindings/iio/magnetometer/pni,rm3100.txt
POSIX CLOCKS and TIMERS
M: Thomas Gleixner <tglx@linutronix.de>
L: linux-kernel@vger.kernel.org
......
......@@ -175,4 +175,33 @@ config SENSORS_HMC5843_SPI
- hmc5843_core (core functions)
- hmc5843_spi (support for HMC5983)
config SENSORS_RM3100
tristate
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
config SENSORS_RM3100_I2C
tristate "PNI RM3100 3-Axis Magnetometer (I2C)"
depends on I2C
select SENSORS_RM3100
select REGMAP_I2C
help
Say Y here to add support for the PNI RM3100 3-Axis Magnetometer.
This driver can also be compiled as a module.
To compile this driver as a module, choose M here: the module
will be called rm3100-i2c.
config SENSORS_RM3100_SPI
tristate "PNI RM3100 3-Axis Magnetometer (SPI)"
depends on SPI_MASTER
select SENSORS_RM3100
select REGMAP_SPI
help
Say Y here to add support for the PNI RM3100 3-Axis Magnetometer.
This driver can also be compiled as a module.
To compile this driver as a module, choose M here: the module
will be called rm3100-spi.
endmenu
......@@ -24,3 +24,7 @@ obj-$(CONFIG_IIO_ST_MAGN_SPI_3AXIS) += st_magn_spi.o
obj-$(CONFIG_SENSORS_HMC5843) += hmc5843_core.o
obj-$(CONFIG_SENSORS_HMC5843_I2C) += hmc5843_i2c.o
obj-$(CONFIG_SENSORS_HMC5843_SPI) += hmc5843_spi.o
obj-$(CONFIG_SENSORS_RM3100) += rm3100-core.o
obj-$(CONFIG_SENSORS_RM3100_I2C) += rm3100-i2c.o
obj-$(CONFIG_SENSORS_RM3100_SPI) += rm3100-spi.o
This diff is collapsed.
// SPDX-License-Identifier: GPL-2.0
/*
* Support for PNI RM3100 3-axis geomagnetic sensor on a i2c bus.
*
* Copyright (C) 2018 Song Qiang <songqiang1304521@gmail.com>
*
* i2c slave address: 0x20 + SA1 << 1 + SA0.
*/
#include <linux/i2c.h>
#include <linux/module.h>
#include "rm3100.h"
static const struct regmap_config rm3100_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.rd_table = &rm3100_readable_table,
.wr_table = &rm3100_writable_table,
.volatile_table = &rm3100_volatile_table,
.cache_type = REGCACHE_RBTREE,
};
static int rm3100_probe(struct i2c_client *client)
{
struct regmap *regmap;
regmap = devm_regmap_init_i2c(client, &rm3100_regmap_config);
if (IS_ERR(regmap))
return PTR_ERR(regmap);
return rm3100_common_probe(&client->dev, regmap, client->irq);
}
static const struct of_device_id rm3100_dt_match[] = {
{ .compatible = "pni,rm3100", },
{ }
};
MODULE_DEVICE_TABLE(of, rm3100_dt_match);
static struct i2c_driver rm3100_driver = {
.driver = {
.name = "rm3100-i2c",
.of_match_table = rm3100_dt_match,
},
.probe_new = rm3100_probe,
};
module_i2c_driver(rm3100_driver);
MODULE_AUTHOR("Song Qiang <songqiang1304521@gmail.com>");
MODULE_DESCRIPTION("PNI RM3100 3-axis magnetometer i2c driver");
MODULE_LICENSE("GPL v2");
// SPDX-License-Identifier: GPL-2.0
/*
* Support for PNI RM3100 3-axis geomagnetic sensor on a spi bus.
*
* Copyright (C) 2018 Song Qiang <songqiang1304521@gmail.com>
*/
#include <linux/module.h>
#include <linux/spi/spi.h>
#include "rm3100.h"
static const struct regmap_config rm3100_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.rd_table = &rm3100_readable_table,
.wr_table = &rm3100_writable_table,
.volatile_table = &rm3100_volatile_table,
.read_flag_mask = 0x80,
.cache_type = REGCACHE_RBTREE,
};
static int rm3100_probe(struct spi_device *spi)
{
struct regmap *regmap;
int ret;
/* Actually this device supports both mode 0 and mode 3. */
spi->mode = SPI_MODE_0;
/* Data rates cannot exceed 1Mbits. */
spi->max_speed_hz = 1000000;
spi->bits_per_word = 8;
ret = spi_setup(spi);
if (ret)
return ret;
regmap = devm_regmap_init_spi(spi, &rm3100_regmap_config);
if (IS_ERR(regmap))
return PTR_ERR(regmap);
return rm3100_common_probe(&spi->dev, regmap, spi->irq);
}
static const struct of_device_id rm3100_dt_match[] = {
{ .compatible = "pni,rm3100", },
{ }
};
MODULE_DEVICE_TABLE(of, rm3100_dt_match);
static struct spi_driver rm3100_driver = {
.driver = {
.name = "rm3100-spi",
.of_match_table = rm3100_dt_match,
},
.probe = rm3100_probe,
};
module_spi_driver(rm3100_driver);
MODULE_AUTHOR("Song Qiang <songqiang1304521@gmail.com>");
MODULE_DESCRIPTION("PNI RM3100 3-axis magnetometer spi driver");
MODULE_LICENSE("GPL v2");
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2018 Song Qiang <songqiang1304521@gmail.com>
*/
#ifndef RM3100_CORE_H
#define RM3100_CORE_H
#include <linux/regmap.h>
extern const struct regmap_access_table rm3100_readable_table;
extern const struct regmap_access_table rm3100_writable_table;
extern const struct regmap_access_table rm3100_volatile_table;
int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq);
#endif /* RM3100_CORE_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment