All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Mike Looijmans <mike.looijmans@topic.nl>
Cc: jic23@kernel.org, linux-iio@vger.kernel.org, knaack.h@gmx.de,
	lars@metafoo.de, pmeerw@pmeerw.net
Subject: Re: [PATCH v3] iio: accel: Add support for the Bosch-Sensortec BMI088
Date: Sun, 22 Mar 2020 02:16:28 +0200	[thread overview]
Message-ID: <20200322001628.GA2824675@smile.fi.intel.com> (raw)
In-Reply-To: <20200319154842.1950-1-mike.looijmans@topic.nl>

On Thu, Mar 19, 2020 at 04:48:42PM +0100, Mike Looijmans wrote:
> The BMI088 is a combined module with both accelerometer and gyroscope.
> This adds the accelerometer driver support for the SPI interface.
> The gyroscope part is already supported by the BMG160 driver.

...

> +#include <linux/acpi.h>

How this is being used?

...

> +EXPORT_SYMBOL_GPL(bmi088_regmap_conf);
> +
> +

Too many blank lines

...

> +#ifdef CONFIG_PM

Hmm... Why do you need this? Doesn't PM runtime have the stubs for !PM case?

> +#else
> +static int bmi088_accel_set_power_state(struct bmi088_accel_data *data,
> +	bool on)
> +{
> +	return 0;
> +}
> +#endif

...

> +	ret = regmap_write(data->regmap, BMI088_ACCEL_REG_PWR_CTRL,
> +				on_off ? 0x4 : 0x0);
> +	if (ret < 0) {

Why all these ' < 0'? I don't remember that regmap API returns positive numbers
from this type of calls.

...

> +
> +static int bmi088_accel_set_sample_freq(struct bmi088_accel_data *data, int val)
> +{
> +	unsigned int value = BMI088_ACCEL_MODE_ODR_1600;
> +	unsigned int freq = 1600;
> +	int ret;
> +
> +	if (val < 12 || val > 1600)
> +		return -EINVAL;

> +	while (freq > val && value > BMI088_ACCEL_MODE_ODR_12_5) {
> +		--value;
> +		freq >>= 1;
> +	}

You can use bit operations instead of loop.

> +	ret = regmap_update_bits(data->regmap, BMI088_ACCEL_REG_ACC_CONF,
> +				 0x0f, value);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;

	return regmap_...(...);

> +}

...

> +static int bmi088_accel_get_temp(struct bmi088_accel_data *data, int *val)
> +{
> +	int ret;
> +	__s16 temp;
> +
> +	mutex_lock(&data->mutex);

> +	ret = regmap_bulk_read(data->regmap, BMI088_ACCEL_REG_TEMP,
> +			       &data->buffer, 2);

sizeof() ?

> +	temp = get_unaligned_be16(data->buffer);
> +
> +	mutex_unlock(&data->mutex);
> +
> +	if (ret < 0)
> +		return ret;
> +
> +	*val = temp >> 5;
> +
> +	return IIO_VAL_INT;
> +}

...

> +static int bmi088_accel_get_axis(struct bmi088_accel_data *data,
> +				 struct iio_chan_spec const *chan,
> +				 int *val)
> +{
> +	int ret;

> +	__s16 raw_val;

s16 ?
Also applies to the rest.

> +	return IIO_VAL_INT;
> +}

...

> +static int bmi088_accel_write_raw(struct iio_dev *indio_dev,
> +				  struct iio_chan_spec const *chan,
> +				  int val, int val2, long mask)
> +{
> +	struct bmi088_accel_data *data = iio_priv(indio_dev);
> +	int ret;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_SAMP_FREQ:
> +		mutex_lock(&data->mutex);
> +		ret = bmi088_accel_set_sample_freq(data, val);
> +		mutex_unlock(&data->mutex);
> +		break;
> +	default:
> +		ret = -EINVAL;
> +	}
> +

> +	return ret;

Replace break with this?

> +}

...

> +static struct attribute *bmi088_accel_attributes[] = {
> +	&iio_const_attr_sampling_frequency_available.dev_attr.attr,

> +	NULL,

Terminators are good w/o comma.

> +};

...

> +static const unsigned long bmi088_accel_scan_masks[] = {
> +				BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z),
> +				0};

Indentation issues.

> +
> +

Too many blank lines.

...

> +	/* Validate chip ID */
> +	for (i = 0; i < ARRAY_SIZE(bmi088_accel_chip_info_tbl); i++) {
> +		if (bmi088_accel_chip_info_tbl[i].chip_id == val) {
> +			data->chip_info = &bmi088_accel_chip_info_tbl[i];
> +			break;
> +		}
> +	}

> +

No need for this blank line.

> +	if (!data->chip_info) {

More usual pattern to check loop counter against array size.

> +		dev_err(dev, "Invalid chip %x\n", val);
> +		return -ENODEV;
> +	}

...

> +	/* Set Default Range */
> +	ret = regmap_write(data->regmap, BMI088_ACCEL_REG_ACC_RANGE,
> +			   BMI088_ACCEL_RANGE_6G);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;

	return regmap_...();

...

> +	ret = iio_device_register(indio_dev);
> +	if (ret < 0) {
> +		dev_err(dev, "Unable to register iio device\n");
> +		return ret;
> +	}
> +
> +	return 0;

	if (ret)
		dev_err();
	return ret;

...

> +	ret = bmi088_accel_set_mode(data, BMI088_ACCEL_MODE_SUSPEND);
> +	if (ret < 0)
> +		return -EAGAIN;

Is this error code dictated by PM runtime API?
Otherwise
	return bmi088_...();

> +
> +	return 0;

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2020-03-22  0:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-13 14:04 [PATCH] iio: accel: Add support for the Bosch-Sensortec BMI088 Mike Looijmans
2020-03-15 12:02 ` Jonathan Cameron
2020-03-16  6:27   ` Mike Looijmans
2020-03-16 12:49     ` Jonathan Cameron
2020-03-16  7:32   ` [PATCH v2] " Mike Looijmans
2020-03-16 14:54     ` Lars-Peter Clausen
2020-03-17 13:58       ` Mike Looijmans
2020-03-19 15:48     ` [PATCH v3] " Mike Looijmans
2020-03-22  0:16       ` Andy Shevchenko [this message]
2020-03-23  9:21         ` Mike Looijmans
2020-03-23 10:45           ` Andy Shevchenko
2020-03-23 16:40             ` Jonathan Cameron
2020-03-22 17:47       ` Jonathan Cameron
2020-03-17 13:55   ` [PATCH] " Mike Looijmans

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=20200322001628.GA2824675@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=mike.looijmans@topic.nl \
    --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.