linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Joachim Eastwood <manabian@gmail.com>,
	jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: accel: add Freescale MMA7455L 3-axis accelerometer driver
Date: Mon, 19 Oct 2015 12:45:25 +0200	[thread overview]
Message-ID: <5624C9C5.6000002@metafoo.de> (raw)
In-Reply-To: <1445120719-29685-1-git-send-email-manabian@gmail.com>

On 10/18/2015 12:25 AM, Joachim Eastwood wrote:
> Add support for Freescale MMA7455L 3-axis in 10-bit mode with both
> I2C and SPI bus support. This is a rather simple driver that
> currently doesn't support all the hardware features of MMA7455L.
> 
> Tested on Embedded Artists' LPC4357 Dev Kit using I2C bus.
> 
> Signed-off-by: Joachim Eastwood <manabian@gmail.com>

Looks pretty good in general.

[...];
> +
> +static int mma7455_drdy(struct mma7455_data *mma7455)
> +{
> +	unsigned int reg;
> +	int tries = 10;
> +	int ret;
> +
> +	while (tries-- > 0) {
> +		ret = regmap_read(mma7455->regmap, MMA7455_REG_STATUS, &reg);
> +		if (ret)
> +			return ret;
> +
> +		if (reg & MMA7455_STATUS_DRDY)
> +			return 0;
> +
> +		msleep(20);

I'm not to sure about this, when the IRQ fires the data should either be
ready or not, no? Are there any corner cases where waiting for up to 200 ms
will generate valid data, whereas not waiting wont?

> +	}
> +
> +	dev_warn(mma7455->dev, "data not ready\n");
> +
> +	return -EIO;
> +}
> +
[...]
> +static int mma7455_read_raw(struct iio_dev *indio_dev,
> +			    struct iio_chan_spec const *chan,
> +			    int *val, int *val2, long mask)
> +{
> +	struct mma7455_data *mma7455 = iio_priv(indio_dev);
> +	unsigned int reg = 0;
> +	int ret;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		if (iio_buffer_enabled(indio_dev))
> +			return -EBUSY;
> +
> +		ret = mma7455_drdy(mma7455);
> +		if (ret)
> +			return ret;
> +
> +		ret = regmap_bulk_read(mma7455->regmap, chan->scan_index * 2,
> +				       &reg, sizeof(s16));

reg is unsigned int while you only read 16 bit. This will cause endianess
issues. If you read a hardware register from a external peripheral always
use __{be,le}{8,16,32} according to the hardware layout and then use the
proper conversion functions {be,le}{8,16,32}_to_cpu() to convert the value
to CPU endianness.

> +		if (ret)
> +			return ret;
> +
> +		*val = sign_extend32(reg, 9);
> +
> +		return IIO_VAL_INT;
> +
[...]
> +static ssize_t mma7455_show_scale_avail(struct device *dev,
> +					struct device_attribute *attr,
> +					char *buf)
> +{
> +	return scnprintf(buf, PAGE_SIZE, "0.%u\n", MMA7455_10BIT_SCALE);
> +}

It doesn't make sense to have this at the moment when there is only one
valid scale available.

[...]
> +static int __init mma7455_modinit(void)
> +{
> +	int ret;
> +#if IS_ENABLED(CONFIG_I2C)
> +	ret = i2c_add_driver(&mma7455_i2c_driver);
> +	if (ret)
> +		pr_err("failed to register MMA7455L I2C driver: %d\n", ret);
> +#endif
> +#if IS_ENABLED(CONFIG_SPI_MASTER)
> +	ret = spi_register_driver(&mma7455_spi_driver);
> +	if (ret)
> +		pr_err("failed to register MMA7455L SPI driver: %d\n", ret);
> +#endif

I know there are a fair amount of bad examples in the IIO tree for this,
which do the same thing. But the SPI and the I2C parts should go into
different modules, otherwise you run into issues if one of them is built-in
while the other is built as a module. The bmg160 gyro driver is a good
example on how to do handle this.

> +	return ret;
> +}
> +module_init(mma7455_modinit);


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

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-17 22:25 [PATCH] iio: accel: add Freescale MMA7455L 3-axis accelerometer driver Joachim Eastwood
2015-10-19 10:45 ` Lars-Peter Clausen [this message]
2015-10-19 12:19   ` Joachim Eastwood
2015-10-19 12:23     ` Lars-Peter Clausen
2015-10-19 12:38       ` Joachim Eastwood
2015-10-19 11:00 ` Peter Meerwald
2015-10-19 12:26   ` Joachim Eastwood
2015-10-19 12:38     ` Peter Meerwald
2015-10-19 11:10 ` Martin Kepplinger
2015-10-19 12:34   ` Joachim Eastwood
2015-10-19 12:56     ` Martin Kepplinger
2015-10-19 13:43       ` Joachim Eastwood
2015-10-19 14:09         ` Martin Kepplinger
2015-10-19 14:14           ` Lars-Peter Clausen
2015-10-19 19:00 ` [PATCH v2] iio: accel: add Freescale MMA7455L/MMA7456L " Joachim Eastwood
2015-10-19 21:07   ` Joachim Eastwood
2015-10-20  7:48   ` Martin Kepplinger
2015-10-20 11:03     ` Joachim Eastwood
2015-10-25 11:29       ` Jonathan Cameron
2015-10-20  8:05   ` Lars-Peter Clausen
2015-10-20 11:00     ` Joachim Eastwood
2015-10-20 11:05       ` Lars-Peter Clausen
2015-10-20 11:52         ` Joachim Eastwood
2015-10-20 20:50 ` [PATCH v3] " Joachim Eastwood
2015-10-25 11:45   ` Jonathan Cameron
2015-10-29 17:34     ` Joachim Eastwood
2015-10-30 10:00       ` Jonathan Cameron
2015-10-31 12:49 ` [PATCH v4] " Joachim Eastwood
2015-10-31 21:37   ` Martin Kepplinger
2015-11-01 18:01     ` Jonathan Cameron
2015-11-02 11:07       ` Martin Kepplinger
2015-11-08 15:47         ` Jonathan Cameron
2015-11-01 18:01   ` Jonathan Cameron
2015-11-01 18:02     ` Jonathan Cameron
2015-11-03 22:17       ` Joachim Eastwood
2015-11-08 15:49         ` 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=5624C9C5.6000002@metafoo.de \
    --to=lars@metafoo.de \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=manabian@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).