From: Jonathan Cameron <jic23@kernel.org>
To: "Vianney le Clément de Saint-Marcq"
<vianney.leclement@essensium.com>,
linux-iio@vger.kernel.org
Cc: "Arnout Vandecappelle (Essensium/Mind)" <arnout@mind.be>
Subject: Re: [PATCH v2 5/7] iio: mlx90614: Add emissivity setting
Date: Sat, 28 Mar 2015 12:46:37 +0000 [thread overview]
Message-ID: <5516A2AD.2030701@kernel.org> (raw)
In-Reply-To: <1427212459-31585-6-git-send-email-vianney.leclement@essensium.com>
On 24/03/15 15:54, Vianney le Clément de Saint-Marcq wrote:
> The mapping from the 16-bit EEPROM value to the decimal 0-1 range is
> approximate. A special case ensures 0xFFFF shows as 1.0 instead of
> 0.999998565.
>
> Writing to EEPROM requires an explicit erase by writing zero. In
> addition, it takes 20ms for the erase/write to complete. During this
> time no EEPROM register should be accessed. Therefore, two msleep()s
> are added to the write function and a mutex protects against concurrent
> access.
>
> Signed-off-by: Vianney le Clément de Saint-Marcq <vianney.leclement@essensium.com>
> Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
>
Fine other than change to calibemissivity.
> ---
>
> v2: * remove iir, fir, and gain attributes
> * refactor emissivity to use IIO_CHAN_INFO_EMISSIVITY
> ---
> drivers/iio/temperature/mlx90614.c | 106 +++++++++++++++++++++++++++++++++++--
> 1 file changed, 103 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/temperature/mlx90614.c b/drivers/iio/temperature/mlx90614.c
> index a112fc9..b981d1e 100644
> --- a/drivers/iio/temperature/mlx90614.c
> +++ b/drivers/iio/temperature/mlx90614.c
> @@ -12,12 +12,13 @@
> *
> * (7-bit I2C slave address 0x5a, 100KHz bus speed only!)
> *
> - * TODO: sleep mode, configuration EEPROM
> + * TODO: sleep mode, filter configuration
> */
>
> #include <linux/err.h>
> #include <linux/i2c.h>
> #include <linux/module.h>
> +#include <linux/delay.h>
>
> #include <linux/iio/iio.h>
>
> @@ -53,8 +54,47 @@
>
> struct mlx90614_data {
> struct i2c_client *client;
> + struct mutex lock; /* for EEPROM access only */
> };
>
> +/*
> + * Erase an address and write word.
> + * The mutex must be locked before calling.
> + */
> +static s32 mlx90614_write_word(const struct i2c_client *client, u8 command,
> + u16 value)
> +{
> + /*
> + * Note: The mlx90614 requires a PEC on writing but does not send us a
> + * valid PEC on reading. Hence, we cannot set I2C_CLIENT_PEC in
> + * i2c_client.flags. As a workaround, we use i2c_smbus_xfer here.
> + */
> + union i2c_smbus_data data;
> + s32 ret;
> +
> + dev_dbg(&client->dev, "Writing 0x%x to address 0x%x", value, command);
> +
> + data.word = 0x0000; /* erase command */
> + ret = i2c_smbus_xfer(client->adapter, client->addr,
> + client->flags | I2C_CLIENT_PEC,
> + I2C_SMBUS_WRITE, command,
> + I2C_SMBUS_WORD_DATA, &data);
> + if (ret < 0)
> + return ret;
> +
> + msleep(MLX90614_TIMING_EEPROM);
> +
> + data.word = value; /* actual write */
> + ret = i2c_smbus_xfer(client->adapter, client->addr,
> + client->flags | I2C_CLIENT_PEC,
> + I2C_SMBUS_WRITE, command,
> + I2C_SMBUS_WORD_DATA, &data);
> +
> + msleep(MLX90614_TIMING_EEPROM);
> +
> + return ret;
> +}
> +
> static int mlx90614_read_raw(struct iio_dev *indio_dev,
> struct iio_chan_spec const *channel, int *val,
> int *val2, long mask)
> @@ -97,6 +137,61 @@ static int mlx90614_read_raw(struct iio_dev *indio_dev,
> case IIO_CHAN_INFO_SCALE:
> *val = 20;
> return IIO_VAL_INT;
> + case IIO_CHAN_INFO_EMISSIVITY: /* 1/65535 / LSB */
> + mutex_lock(&data->lock);
> + ret = i2c_smbus_read_word_data(data->client,
> + MLX90614_EMISSIVITY);
> + mutex_unlock(&data->lock);
> +
> + if (ret < 0)
> + return ret;
> +
> + if (ret == 65535) {
> + *val = 1;
> + *val2 = 0;
> + } else {
> + *val = 0;
> + *val2 = ret * 15259; /* 1/65535 ~ 0.000015259 */
> + }
> + return IIO_VAL_INT_PLUS_NANO;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int mlx90614_write_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *channel, int val,
> + int val2, long mask)
> +{
> + struct mlx90614_data *data = iio_priv(indio_dev);
> + s32 ret;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_EMISSIVITY: /* 1/65535 / LSB */
> + if (val < 0 || val2 < 0 || val > 1 || (val == 1 && val2 != 0))
> + return -EINVAL;
> + val = val * 65535 + val2 / 15259; /* 1/65535 ~ 0.000015259 */
> +
> + mutex_lock(&data->lock);
> + ret = mlx90614_write_word(data->client, MLX90614_EMISSIVITY,
> + val);
> + mutex_unlock(&data->lock);
> +
> + if (ret < 0)
> + return ret;
> + return 0;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int mlx90614_write_raw_get_fmt(struct iio_dev *indio_dev,
> + const struct iio_chan_spec const *channel,
> + long mask)
> +{
> + switch (mask) {
> + case IIO_CHAN_INFO_EMISSIVITY:
> + return IIO_VAL_INT_PLUS_NANO;
> default:
> return -EINVAL;
> }
> @@ -115,7 +210,8 @@ static const struct iio_chan_spec mlx90614_channels[] = {
> .type = IIO_TEMP,
> .modified = 1,
> .channel2 = IIO_MOD_TEMP_OBJECT,
> - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_EMISSIVITY),
> .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
> BIT(IIO_CHAN_INFO_SCALE),
> },
> @@ -125,7 +221,8 @@ static const struct iio_chan_spec mlx90614_channels[] = {
> .modified = 1,
> .channel = 1,
> .channel2 = IIO_MOD_TEMP_OBJECT,
> - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_EMISSIVITY),
> .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
> BIT(IIO_CHAN_INFO_SCALE),
> },
> @@ -133,6 +230,8 @@ static const struct iio_chan_spec mlx90614_channels[] = {
>
> static const struct iio_info mlx90614_info = {
> .read_raw = mlx90614_read_raw,
> + .write_raw = mlx90614_write_raw,
> + .write_raw_get_fmt = mlx90614_write_raw_get_fmt,
> .driver_module = THIS_MODULE,
> };
>
> @@ -166,6 +265,7 @@ static int mlx90614_probe(struct i2c_client *client,
> data = iio_priv(indio_dev);
> i2c_set_clientdata(client, indio_dev);
> data->client = client;
> + mutex_init(&data->lock);
>
> indio_dev->dev.parent = &client->dev;
> indio_dev->name = id->name;
>
next prev parent reply other threads:[~2015-03-28 12:46 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-24 15:54 [PATCH v2 0/7] iio: mlx90614 enhancements Vianney le Clément de Saint-Marcq
2015-03-24 15:54 ` Vianney le Clément de Saint-Marcq
2015-03-24 15:54 ` [PATCH v2 1/7] iio: mlx90614: Refactor register symbols Vianney le Clément de Saint-Marcq
2015-03-28 12:40 ` Jonathan Cameron
2015-03-24 15:54 ` [PATCH v2 2/7] iio: mlx90614: Add symbols for accessible registers Vianney le Clément de Saint-Marcq
2015-03-24 15:54 ` [PATCH v2 3/7] iio: mlx90614: Support devices with dual IR sensor Vianney le Clément de Saint-Marcq
2015-03-28 12:44 ` Jonathan Cameron
2015-03-24 15:54 ` [PATCH v2 4/7] iio: core: Introduce IIO_CHAN_INFO_EMISSIVITY Vianney le Clément de Saint-Marcq
2015-03-24 16:02 ` Lars-Peter Clausen
2015-03-28 12:45 ` Jonathan Cameron
2015-03-24 15:54 ` [PATCH v2 5/7] iio: mlx90614: Add emissivity setting Vianney le Clément de Saint-Marcq
2015-03-28 12:46 ` Jonathan Cameron [this message]
2015-03-24 15:54 ` [PATCH v2 6/7] iio: mlx90614: Add power management Vianney le Clément de Saint-Marcq
2015-03-24 15:54 ` Vianney le Clément de Saint-Marcq
2015-03-28 12:54 ` Jonathan Cameron
2015-03-28 12:54 ` Jonathan Cameron
2015-03-24 15:54 ` [PATCH v2 7/7] iio: mlx90614: Check for errors in read values Vianney le Clément de Saint-Marcq
2015-03-28 13:43 ` 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=5516A2AD.2030701@kernel.org \
--to=jic23@kernel.org \
--cc=arnout@mind.be \
--cc=linux-iio@vger.kernel.org \
--cc=vianney.leclement@essensium.com \
/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.