From: Jonathan Cameron <jic23@kernel.org>
To: Ludovic Tancerel <ludovic.tancerel@maplehightech.com>,
knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
linux-iio@vger.kernel.org, William.Markezana@meas-spec.com
Subject: Re: [PATCH v4 5/7] Add ms5637 meas-spec driver support
Date: Sun, 4 Oct 2015 15:22:08 +0100 [thread overview]
Message-ID: <56113610.3000907@kernel.org> (raw)
In-Reply-To: <1443708822-8580-6-git-send-email-ludovic.tancerel@maplehightech.com>
On 01/10/15 15:13, Ludovic Tancerel wrote:
> Support for MS5637 temperature & pressure sensor
>
> Signed-off-by: Ludovic Tancerel <ludovic.tancerel@maplehightech.com>
Applied,
> ---
> drivers/iio/pressure/Kconfig | 11 +++
> drivers/iio/pressure/Makefile | 1 +
> drivers/iio/pressure/ms5637.c | 186 ++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 198 insertions(+)
> create mode 100644 drivers/iio/pressure/ms5637.c
>
> diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig
> index fa62950..dd12d52 100644
> --- a/drivers/iio/pressure/Kconfig
> +++ b/drivers/iio/pressure/Kconfig
> @@ -79,6 +79,17 @@ config MS5611_SPI
> To compile this driver as a module, choose M here: the module will
> be called ms5611_spi.
>
> +config MS5637
> + tristate "Measurement Specialties MS5637 pressure & temperature sensor"
> + depends on I2C
> + select IIO_MS_SENSORS_I2C
> + help
> + If you say yes here you get support for the Measurement Specialties
> + MS5637 pressure and temperature sensor.
> +
> + This driver can also be built as a module. If so, the module will
> + be called ms5637.
> +
> config IIO_ST_PRESS
> tristate "STMicroelectronics pressure sensor Driver"
> depends on (I2C || SPI_MASTER) && SYSFS
> diff --git a/drivers/iio/pressure/Makefile b/drivers/iio/pressure/Makefile
> index a4f98f8..46571c96 100644
> --- a/drivers/iio/pressure/Makefile
> +++ b/drivers/iio/pressure/Makefile
> @@ -10,6 +10,7 @@ obj-$(CONFIG_MPL3115) += mpl3115.o
> obj-$(CONFIG_MS5611) += ms5611_core.o
> obj-$(CONFIG_MS5611_I2C) += ms5611_i2c.o
> obj-$(CONFIG_MS5611_SPI) += ms5611_spi.o
> +obj-$(CONFIG_MS5637) += ms5637.o
> obj-$(CONFIG_IIO_ST_PRESS) += st_pressure.o
> st_pressure-y := st_pressure_core.o
> st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o
> diff --git a/drivers/iio/pressure/ms5637.c b/drivers/iio/pressure/ms5637.c
> new file mode 100644
> index 0000000..e3ad9d3
> --- /dev/null
> +++ b/drivers/iio/pressure/ms5637.c
> @@ -0,0 +1,186 @@
> +/*
> + * ms5637.c - Support for Measurement-Specialties ms5637
> + * pressure & temperature sensor
> + *
> + * Copyright (c) 2015 Measurement-Specialties
> + *
> + * Licensed under the GPL-2.
> + *
> + * (7-bit I2C slave address 0x76)
> + *
> + * Datasheet:
> + * http://www.meas-spec.com/downloads/MS5637-02BA03.pdf
> + */
> +#include <linux/init.h>
> +#include <linux/device.h>
> +#include <linux/kernel.h>
> +#include <linux/stat.h>
> +#include <linux/module.h>
> +#include <linux/i2c.h>
> +#include <linux/iio/iio.h>
> +#include <linux/iio/sysfs.h>
> +#include <linux/mutex.h>
> +
> +#include "../common/ms_sensors/ms_sensors_i2c.h"
> +
> +static const int ms5637_samp_freq[6] = { 960, 480, 240, 120, 60, 30 };
> +/* String copy of the above const for readability purpose */
> +static const char ms5637_show_samp_freq[] = "960 480 240 120 60 30";
> +
> +static int ms5637_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *channel, int *val,
> + int *val2, long mask)
> +{
> + int ret;
> + int temperature;
> + unsigned int pressure;
> + struct ms_tp_dev *dev_data = iio_priv(indio_dev);
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_PROCESSED:
> + ret = ms_sensors_read_temp_and_pressure(dev_data,
> + &temperature,
> + &pressure);
> + if (ret)
> + return ret;
> +
> + switch (channel->type) {
> + case IIO_TEMP: /* in milli °C */
> + *val = temperature;
> +
> + return IIO_VAL_INT;
> + case IIO_PRESSURE: /* in kPa */
> + *val = pressure / 1000;
> + *val2 = (pressure % 1000) * 1000;
> +
> + return IIO_VAL_INT_PLUS_MICRO;
> + default:
> + return -EINVAL;
> + }
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + *val = ms5637_samp_freq[dev_data->res_index];
> +
> + return IIO_VAL_INT;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int ms5637_write_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int val, int val2, long mask)
> +{
> + struct ms_tp_dev *dev_data = iio_priv(indio_dev);
> + int i;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + i = ARRAY_SIZE(ms5637_samp_freq);
> + while (i-- > 0)
> + if (val == ms5637_samp_freq[i])
> + break;
> + if (i < 0)
> + return -EINVAL;
> + dev_data->res_index = i;
> +
> + return 0;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static const struct iio_chan_spec ms5637_channels[] = {
> + {
> + .type = IIO_TEMP,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
> + },
> + {
> + .type = IIO_PRESSURE,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
> + }
> +};
> +
> +static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(ms5637_show_samp_freq);
> +
> +static struct attribute *ms5637_attributes[] = {
> + &iio_const_attr_sampling_frequency_available.dev_attr.attr,
> + NULL,
> +};
> +
> +static const struct attribute_group ms5637_attribute_group = {
> + .attrs = ms5637_attributes,
> +};
> +
> +static const struct iio_info ms5637_info = {
> + .read_raw = ms5637_read_raw,
> + .write_raw = ms5637_write_raw,
> + .attrs = &ms5637_attribute_group,
> + .driver_module = THIS_MODULE,
> +};
> +
> +static int ms5637_probe(struct i2c_client *client,
> + const struct i2c_device_id *id)
> +{
> + struct ms_tp_dev *dev_data;
> + struct iio_dev *indio_dev;
> + int ret;
> +
> + if (!i2c_check_functionality(client->adapter,
> + I2C_FUNC_SMBUS_READ_WORD_DATA |
> + I2C_FUNC_SMBUS_WRITE_BYTE |
> + I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
> + dev_err(&client->dev,
> + "Adapter does not support some i2c transaction\n");
> + return -ENODEV;
> + }
> +
> + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dev_data));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + dev_data = iio_priv(indio_dev);
> + dev_data->client = client;
> + dev_data->res_index = 5;
> + mutex_init(&dev_data->lock);
> +
> + indio_dev->info = &ms5637_info;
> + indio_dev->name = id->name;
> + indio_dev->dev.parent = &client->dev;
> + indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->channels = ms5637_channels;
> + indio_dev->num_channels = ARRAY_SIZE(ms5637_channels);
> +
> + i2c_set_clientdata(client, indio_dev);
> +
> + ret = ms_sensors_reset(client, 0x1E, 3000);
> + if (ret)
> + return ret;
> +
> + ret = ms_sensors_tp_read_prom(dev_data);
> + if (ret)
> + return ret;
> +
> + return devm_iio_device_register(&client->dev, indio_dev);
> +}
> +
> +static const struct i2c_device_id ms5637_id[] = {
> + {"ms5637", 0},
> + {}
> +};
> +
> +static struct i2c_driver ms5637_driver = {
> + .probe = ms5637_probe,
> + .id_table = ms5637_id,
> + .driver = {
> + .name = "ms5637"
> + },
> +};
> +
> +module_i2c_driver(ms5637_driver);
> +
> +MODULE_DESCRIPTION("Measurement-Specialties ms5637 temperature & pressure driver");
> +MODULE_AUTHOR("William Markezana <william.markezana@meas-spec.com>");
> +MODULE_AUTHOR("Ludovic Tancerel <ludovic.tancerel@maplehightech.com>");
> +MODULE_LICENSE("GPL v2");
>
next prev parent reply other threads:[~2015-10-04 14:22 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-01 14:13 [PATCH v4 0/7] iio: TSYS01, TSYS02D, HTU21, MS5637, MS8607, Measurement Specialties driver developments Ludovic Tancerel
2015-10-01 14:13 ` [PATCH v4 1/7] Add meas-spec sensors common part Ludovic Tancerel
2015-10-04 14:04 ` Jonathan Cameron
2015-10-05 16:28 ` ludovic.tancerel
2015-10-01 14:13 ` [PATCH v4 2/7] Add tsys01 meas-spec driver support Ludovic Tancerel
2015-10-04 14:04 ` Jonathan Cameron
2015-10-01 14:13 ` [PATCH v4 3/7] Add tsys02d " Ludovic Tancerel
2015-10-04 14:04 ` Jonathan Cameron
2015-10-01 14:13 ` [PATCH v4 4/7] Add htu21 " Ludovic Tancerel
2015-10-04 14:10 ` Jonathan Cameron
2015-10-04 14:21 ` Jonathan Cameron
2015-10-01 14:13 ` [PATCH v4 5/7] Add ms5637 " Ludovic Tancerel
2015-10-04 14:22 ` Jonathan Cameron [this message]
2015-10-01 14:13 ` [PATCH v4 6/7] Add ms8607 " Ludovic Tancerel
2015-10-04 14:26 ` Jonathan Cameron
2015-10-01 14:13 ` [PATCH v4 7/7] Typo correction in ms5611 Kconfig Ludovic Tancerel
2015-10-04 14:26 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56113610.3000907@kernel.org \
--to=jic23@kernel.org \
--cc=William.Markezana@meas-spec.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=ludovic.tancerel@maplehightech.com \
--cc=pmeerw@pmeerw.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.