Commit 03b262f2 authored by Gregor Boirie's avatar Gregor Boirie Committed by Jonathan Cameron

iio:pressure: initial zpa2326 barometer support

Introduce driver for Murata ZPA2326 pressure and temperature sensor:
http://www.murata.com/en-us/products/productdetail?partno=ZPA2326-0311A-RSigned-off-by: default avatarGregor Boirie <gregor.boirie@parrot.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 063e3303
Murata ZPA2326 pressure sensor
Pressure sensor from Murata with SPI and I2C bus interfaces.
Required properties:
- compatible: "murata,zpa2326"
- reg: the I2C address or SPI chip select the device will respond to
Recommended properties for SPI bus usage:
- spi-max-frequency: maximum SPI bus frequency as documented in
Documentation/devicetree/bindings/spi/spi-bus.txt
Optional properties:
- vref-supply: an optional regulator that needs to be on to provide VREF
power to the sensor
- vdd-supply: an optional regulator that needs to be on to provide VDD
power to the sensor
- interrupt-parent: phandle to the parent interrupt controller as documented in
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
- interrupts: interrupt mapping for IRQ as documented in
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
Example:
zpa2326@5c {
compatible = "murata,zpa2326";
reg = <0x5c>;
interrupt-parent = <&gpio>;
interrupts = <12>;
vdd-supply = <&ldo_1v8_gnss>;
};
...@@ -187,4 +187,26 @@ config HP206C ...@@ -187,4 +187,26 @@ config HP206C
This driver can also be built as a module. If so, the module will This driver can also be built as a module. If so, the module will
be called hp206c. be called hp206c.
config ZPA2326
tristate "Murata ZPA2326 pressure sensor driver"
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
select REGMAP
select ZPA2326_I2C if I2C
select ZPA2326_SPI if SPI_MASTER
help
Say Y here to build support for the Murata ZPA2326 pressure and
temperature sensor.
To compile this driver as a module, choose M here: the module will
be called zpa2326.
config ZPA2326_I2C
tristate
select REGMAP_I2C
config ZPA2326_SPI
tristate
select REGMAP_SPI
endmenu endmenu
...@@ -22,6 +22,9 @@ st_pressure-y := st_pressure_core.o ...@@ -22,6 +22,9 @@ st_pressure-y := st_pressure_core.o
st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o
obj-$(CONFIG_T5403) += t5403.o obj-$(CONFIG_T5403) += t5403.o
obj-$(CONFIG_HP206C) += hp206c.o obj-$(CONFIG_HP206C) += hp206c.o
obj-$(CONFIG_ZPA2326) += zpa2326.o
obj-$(CONFIG_ZPA2326_I2C) += zpa2326_i2c.o
obj-$(CONFIG_ZPA2326_SPI) += zpa2326_spi.o
obj-$(CONFIG_IIO_ST_PRESS_I2C) += st_pressure_i2c.o obj-$(CONFIG_IIO_ST_PRESS_I2C) += st_pressure_i2c.o
obj-$(CONFIG_IIO_ST_PRESS_SPI) += st_pressure_spi.o obj-$(CONFIG_IIO_ST_PRESS_SPI) += st_pressure_spi.o
This diff is collapsed.
/*
* Murata ZPA2326 pressure and temperature sensor IIO driver
*
* Copyright (c) 2016 Parrot S.A.
*
* Author: Gregor Boirie <gregor.boirie@parrot.com>
*
* 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.
*
* 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.
*/
#ifndef _ZPA2326_H
#define _ZPA2326_H
/* Register map. */
#define ZPA2326_REF_P_XL_REG (0x8)
#define ZPA2326_REF_P_L_REG (0x9)
#define ZPA2326_REF_P_H_REG (0xa)
#define ZPA2326_DEVICE_ID_REG (0xf)
#define ZPA2326_DEVICE_ID (0xb9)
#define ZPA2326_RES_CONF_REG (0x10)
#define ZPA2326_CTRL_REG0_REG (0x20)
#define ZPA2326_CTRL_REG0_ONE_SHOT BIT(0)
#define ZPA2326_CTRL_REG0_ENABLE BIT(1)
#define ZPA2326_CTRL_REG1_REG (0x21)
#define ZPA2326_CTRL_REG1_MASK_DATA_READY BIT(2)
#define ZPA2326_CTRL_REG2_REG (0x22)
#define ZPA2326_CTRL_REG2_SWRESET BIT(2)
#define ZPA2326_CTRL_REG3_REG (0x23)
#define ZPA2326_CTRL_REG3_ODR_SHIFT (4)
#define ZPA2326_CTRL_REG3_ENABLE_MEAS BIT(7)
#define ZPA2326_INT_SOURCE_REG (0x24)
#define ZPA2326_INT_SOURCE_DATA_READY BIT(2)
#define ZPA2326_THS_P_LOW_REG (0x25)
#define ZPA2326_THS_P_HIGH_REG (0x26)
#define ZPA2326_STATUS_REG (0x27)
#define ZPA2326_STATUS_P_DA BIT(1)
#define ZPA2326_STATUS_FIFO_E BIT(2)
#define ZPA2326_STATUS_P_OR BIT(5)
#define ZPA2326_PRESS_OUT_XL_REG (0x28)
#define ZPA2326_PRESS_OUT_L_REG (0x29)
#define ZPA2326_PRESS_OUT_H_REG (0x2a)
#define ZPA2326_TEMP_OUT_L_REG (0x2b)
#define ZPA2326_TEMP_OUT_H_REG (0x2c)
struct device;
struct regmap;
bool zpa2326_isreg_writeable(struct device *dev, unsigned int reg);
bool zpa2326_isreg_readable(struct device *dev, unsigned int reg);
bool zpa2326_isreg_precious(struct device *dev, unsigned int reg);
/**
* zpa2326_probe() - Instantiate and register core ZPA2326 IIO device
* @parent: Hardware sampling device the created IIO device will be a child of.
* @name: Arbitrary name to identify the device.
* @irq: Interrupt line, negative if none.
* @hwid: Expected device hardware id.
* @regmap: Registers map used to abstract underlying bus accesses.
*
* Return: Zero when successful, a negative error code otherwise.
*/
int zpa2326_probe(struct device *parent,
const char *name,
int irq,
unsigned int hwid,
struct regmap *regmap);
/**
* zpa2326_remove() - Unregister and destroy core ZPA2326 IIO device.
* @parent: Hardware sampling device the IIO device to remove is a child of.
*/
void zpa2326_remove(const struct device *parent);
#ifdef CONFIG_PM
#include <linux/pm.h>
extern const struct dev_pm_ops zpa2326_pm_ops;
#define ZPA2326_PM_OPS (&zpa2326_pm_ops)
#else
#define ZPA2326_PM_OPS (NULL)
#endif
#endif
/*
* Murata ZPA2326 I2C pressure and temperature sensor driver
*
* Copyright (c) 2016 Parrot S.A.
*
* Author: Gregor Boirie <gregor.boirie@parrot.com>
*
* 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.
*
* 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.
*/
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/i2c.h>
#include <linux/of_device.h>
#include "zpa2326.h"
/*
* read_flag_mask:
* - address bit 7 must be set to request a register read operation
*/
static const struct regmap_config zpa2326_regmap_i2c_config = {
.reg_bits = 8,
.val_bits = 8,
.writeable_reg = zpa2326_isreg_writeable,
.readable_reg = zpa2326_isreg_readable,
.precious_reg = zpa2326_isreg_precious,
.max_register = ZPA2326_TEMP_OUT_H_REG,
.read_flag_mask = BIT(7),
.cache_type = REGCACHE_NONE,
};
static unsigned int zpa2326_i2c_hwid(const struct i2c_client *client)
{
#define ZPA2326_SA0(_addr) (_addr & BIT(0))
#define ZPA2326_DEVICE_ID_SA0_SHIFT (1)
/* Identification register bit 1 mirrors device address bit 0. */
return (ZPA2326_DEVICE_ID |
(ZPA2326_SA0(client->addr) << ZPA2326_DEVICE_ID_SA0_SHIFT));
}
static int zpa2326_probe_i2c(struct i2c_client *client,
const struct i2c_device_id *i2c_id)
{
struct regmap *regmap;
regmap = devm_regmap_init_i2c(client, &zpa2326_regmap_i2c_config);
if (IS_ERR(regmap)) {
dev_err(&client->dev, "failed to init registers map");
return PTR_ERR(regmap);
}
return zpa2326_probe(&client->dev, i2c_id->name, client->irq,
zpa2326_i2c_hwid(client), regmap);
}
static int zpa2326_remove_i2c(struct i2c_client *client)
{
zpa2326_remove(&client->dev);
return 0;
}
static const struct i2c_device_id zpa2326_i2c_ids[] = {
{ "zpa2326", 0 },
{ },
};
MODULE_DEVICE_TABLE(i2c, zpa2326_i2c_ids);
#if defined(CONFIG_OF)
static const struct of_device_id zpa2326_i2c_matches[] = {
{ .compatible = "murata,zpa2326" },
{ }
};
MODULE_DEVICE_TABLE(of, zpa2326_i2c_matches);
#endif
static struct i2c_driver zpa2326_i2c_driver = {
.driver = {
.name = "zpa2326-i2c",
.of_match_table = of_match_ptr(zpa2326_i2c_matches),
.pm = ZPA2326_PM_OPS,
},
.probe = zpa2326_probe_i2c,
.remove = zpa2326_remove_i2c,
.id_table = zpa2326_i2c_ids,
};
module_i2c_driver(zpa2326_i2c_driver);
MODULE_AUTHOR("Gregor Boirie <gregor.boirie@parrot.com>");
MODULE_DESCRIPTION("I2C driver for Murata ZPA2326 pressure sensor");
MODULE_LICENSE("GPL v2");
/*
* Murata ZPA2326 SPI pressure and temperature sensor driver
*
* Copyright (c) 2016 Parrot S.A.
*
* Author: Gregor Boirie <gregor.boirie@parrot.com>
*
* 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.
*
* 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.
*/
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/spi/spi.h>
#include <linux/of_device.h>
#include "zpa2326.h"
/*
* read_flag_mask:
* - address bit 7 must be set to request a register read operation
* - address bit 6 must be set to request register address auto increment
*/
static const struct regmap_config zpa2326_regmap_spi_config = {
.reg_bits = 8,
.val_bits = 8,
.writeable_reg = zpa2326_isreg_writeable,
.readable_reg = zpa2326_isreg_readable,
.precious_reg = zpa2326_isreg_precious,
.max_register = ZPA2326_TEMP_OUT_H_REG,
.read_flag_mask = BIT(7) | BIT(6),
.cache_type = REGCACHE_NONE,
};
static int zpa2326_probe_spi(struct spi_device *spi)
{
struct regmap *regmap;
int err;
regmap = devm_regmap_init_spi(spi, &zpa2326_regmap_spi_config);
if (IS_ERR(regmap)) {
dev_err(&spi->dev, "failed to init registers map");
return PTR_ERR(regmap);
}
/*
* Enforce SPI slave settings to prevent from DT misconfiguration.
*
* Clock is idle high. Sampling happens on trailing edge, i.e., rising
* edge. Maximum bus frequency is 1 MHz. Registers are 8 bits wide.
*/
spi->mode = SPI_MODE_3;
spi->max_speed_hz = min(spi->max_speed_hz, 1000000U);
spi->bits_per_word = 8;
err = spi_setup(spi);
if (err < 0)
return err;
return zpa2326_probe(&spi->dev, spi_get_device_id(spi)->name,
spi->irq, ZPA2326_DEVICE_ID, regmap);
}
static int zpa2326_remove_spi(struct spi_device *spi)
{
zpa2326_remove(&spi->dev);
return 0;
}
static const struct spi_device_id zpa2326_spi_ids[] = {
{ "zpa2326", 0 },
{ },
};
MODULE_DEVICE_TABLE(spi, zpa2326_spi_ids);
#if defined(CONFIG_OF)
static const struct of_device_id zpa2326_spi_matches[] = {
{ .compatible = "murata,zpa2326" },
{ }
};
MODULE_DEVICE_TABLE(of, zpa2326_spi_matches);
#endif
static struct spi_driver zpa2326_spi_driver = {
.driver = {
.name = "zpa2326-spi",
.of_match_table = of_match_ptr(zpa2326_spi_matches),
.pm = ZPA2326_PM_OPS,
},
.probe = zpa2326_probe_spi,
.remove = zpa2326_remove_spi,
.id_table = zpa2326_spi_ids,
};
module_spi_driver(zpa2326_spi_driver);
MODULE_AUTHOR("Gregor Boirie <gregor.boirie@parrot.com>");
MODULE_DESCRIPTION("SPI driver for Murata ZPA2326 pressure sensor");
MODULE_LICENSE("GPL v2");
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