public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Teodora Baluta <teodora.baluta@intel.com>, jic23@kernel.org
Cc: knaack.h@gmx.de, pmeerw@pmeerw.net, daniel.baluta@intel.com,
	dan.carpenter@oracle.com, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: accel: add support for Memsic MXC6255XC sensor
Date: Mon, 19 Oct 2015 12:52:50 +0200	[thread overview]
Message-ID: <5624CB82.4000600@metafoo.de> (raw)
In-Reply-To: <1444991368-14609-1-git-send-email-teodora.baluta@intel.com>

On 10/16/2015 12:29 PM, Teodora Baluta wrote:
> This patch adds a minimal implementation for the Memsic MXC6255XC
> orientation sensing accelerometer. The supported operations are reading
> raw acceleration values for X/Y axis that can be scaled using the
> exposed scale.
> 
> Signed-off-by: Teodora Baluta <teodora.baluta@intel.com>

Looks quite good in general, a few minor things inline.

[...]
> +/* scale value for +/- 2G measurement range */
> +static const int mxc6255_scale = 153829;
> +
> +static IIO_CONST_ATTR(in_accel_scale_available, MXC6255_SCALE_AVAIL);

If there is only one scale available it does not make too much sense to have
a scale_available attribute.

[..]
> +static int mxc6255_read_raw(struct iio_dev *indio_dev,
> +			    struct iio_chan_spec const *chan,
> +			    int *val, int *val2, long mask)
> +{
> +	struct mxc6255_data *data = iio_priv(indio_dev);
> +	unsigned int reg;
> +	int axis = chan->channel2 - 1;

1 is a bit of a magic constant here. Use IIO_MOD_X instead. Or even better
use chan->address.

> +	int ret;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		ret = regmap_read(data->regmap,
> +				  MXC6255_AXIS_TO_REG(axis), &reg);
> +		if (ret < 0) {
> +			dev_err(&data->client->dev,
> +				"Error reading axis %d\n", axis);
> +			return ret;
> +		}
> +
> +		*val = sign_extend32(reg, 7);
> +		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_SCALE:
> +		*val = 0;
> +		*val2 = mxc6255_scale;
> +		return IIO_VAL_INT_PLUS_MICRO;
> +	default:
> +		return -EINVAL;
> +	}
> +}
[...]
> +static int mxc6255_probe(struct i2c_client *client,
> +			 const struct i2c_device_id *id)
> +{
[...]
> +	ret = regmap_read(data->regmap, MXC6255_REG_CHIP_ID, &chip_id);
> +	if (ret < 0) {
> +		dev_err(&client->dev, "Error reading chip id %d\n", ret);
> +		return ret;
> +	}

Does it make sense to check whether chip ID matches the expected value, to
catch mistakes where the I2C address is incorrect?

> +
> +	dev_dbg(&client->dev, "Chip id %x\n", chip_id);
> +
> +	ret = devm_iio_device_register(&client->dev, indio_dev);
> +	if (ret < 0) {
> +		dev_err(&client->dev, "Could not register IIO device\n");
> +		return ret;
> +	}
> +
> +	return 0;
> +}
[...]

  reply	other threads:[~2015-10-19 10:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-16 10:29 [PATCH] iio: accel: add support for Memsic MXC6255XC sensor Teodora Baluta
2015-10-19 10:52 ` Lars-Peter Clausen [this message]
2015-10-19 14:30   ` Teodora Baluta
2015-10-19 11:08 ` Peter Meerwald
2015-10-19 14:34   ` Teodora Baluta

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=5624CB82.4000600@metafoo.de \
    --to=lars@metafoo.de \
    --cc=dan.carpenter@oracle.com \
    --cc=daniel.baluta@intel.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=teodora.baluta@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox