Devicetree
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: <Jianping.Shen@de.bosch.com>
Cc: <lars@metafoo.de>, <robh@kernel.org>, <krzk+dt@kernel.org>,
	<conor+dt@kernel.org>, <dima.fedrau@gmail.com>,
	<marcelo.schmitt1@gmail.com>, <linux-iio@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<Christian.Lorenz3@de.bosch.com>,
	<Ulrike.Frauendorf@de.bosch.com>, <Kai.Dolde@de.bosch.com>
Subject: Re: [PATCH v4 2/2] iio: imu: smi330: Add driver
Date: Sat, 27 Sep 2025 15:44:28 +0100	[thread overview]
Message-ID: <20250927154428.381df54e@jic23-huawei> (raw)
In-Reply-To: <20250915160934.89208-3-Jianping.Shen@de.bosch.com>

On Mon, 15 Sep 2025 18:09:34 +0200
<Jianping.Shen@de.bosch.com> wrote:

> From: Jianping Shen <Jianping.Shen@de.bosch.com>
> 
> Add the iio driver for bosch imu smi330. The smi330 is a combined
> three axis angular rate and three axis acceleration sensor.
> 
> Signed-off-by: Jianping Shen <Jianping.Shen@de.bosch.com>

Applied to the testing branch of iio.git (which will be rebased on rc1)
with following diff;

diff --git a/drivers/iio/imu/smi330/Kconfig b/drivers/iio/imu/smi330/Kconfig
index 95b06f2317e8..915a5b6fb974 100644
--- a/drivers/iio/imu/smi330/Kconfig
+++ b/drivers/iio/imu/smi330/Kconfig
@@ -7,6 +7,7 @@ config SMI330
        tristate "Bosch Sensor SMI330 Inertial Measurement Unit"
        select IIO_BUFFER
        select IIO_TRIGGERED_BUFFER
+       depends on I2C || SPI
        help
          Enable support for the Bosch SMI330 IMU.
 
diff --git a/drivers/iio/imu/smi330/smi330_core.c b/drivers/iio/imu/smi330/smi330_core.c
index fdbc251d1f60..8571414d2a55 100644
--- a/drivers/iio/imu/smi330/smi330_core.c
+++ b/drivers/iio/imu/smi330/smi330_core.c
@@ -491,8 +491,6 @@ static int smi330_read_avail(struct iio_dev *indio_dev,
        default:
                return -EINVAL;
        }
-
-       return -EINVAL;
 }
 
 static int smi330_read_raw(struct iio_dev *indio_dev,

> diff --git a/drivers/iio/imu/smi330/Kconfig b/drivers/iio/imu/smi330/Kconfig
> new file mode 100644
> index 00000000000..95b06f2317e
> --- /dev/null
> +++ b/drivers/iio/imu/smi330/Kconfig
> @@ -0,0 +1,39 @@
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# SMI330 IMU driver
> +#
> +
> +config SMI330
> +	tristate "Bosch Sensor SMI330 Inertial Measurement Unit"
> +	select IIO_BUFFER
> +	select IIO_TRIGGERED_BUFFER
Why expose this as an option, whether or not either bus is supported?
At minimum this should be 
	depends on I2C || SPI

Often we just don't make this a selectable symbol though that
complicates the select statements here hence I've just made this tweak.

> +	help
> +	  Enable support for the Bosch SMI330 IMU.
> +
> +	  The driver supports different operation modes like polling,
> +	  data ready or fifo mode and advanced features like no-motion,
> +	  no-motion, any-motion or tilt detection.
> +
> +config SMI330_I2C
> +	tristate "Bosch SMI330 I2C driver"
> +	depends on I2C
> +	select SMI330
> +	select REGMAP_I2C
> +	help
> +	  Enable support for the Bosch SMI330 6-Axis IMU connected to I2C
> +	  interface.
> +
> +	  This driver can also be built as a module. If so, the module will be
> +	  called smi330_i2c.
> +
> +config SMI330_SPI
> +	tristate "Bosch SMI330 SPI driver"
> +	depends on SPI
> +	select SMI330
> +	select REGMAP_SPI
> +	help
> +	  Enable support for the Bosch SMI330 6-Axis IMU connected to SPI
> +	  interface.
> +
> +	  This driver can also be built as a module. If so, the module will be
> +	  called smi330_spi.


> diff --git a/drivers/iio/imu/smi330/smi330_core.c b/drivers/iio/imu/smi330/smi330_core.c
> new file mode 100644
> index 00000000000..fdbc251d1f6
> --- /dev/null
> +++ b/drivers/iio/imu/smi330/smi330_core.c

> +/* Register mask */
> +#define SMI330_CHIP_ID_MASK GENMASK(7, 0)
> +#define SMI330_ERR_FATAL_MASK BIT(0)
> +#define SMI330_ERR_ACC_CONF_MASK BIT(5)
> +#define SMI330_ERR_GYR_CONF_MASK BIT(6)
> +#define SMI330_STATUS_POR_MASK BIT(0)
> +#define SMI330_INT_STATUS_ACC_GYR_DRDY_MASK GENMASK(13, 12)
> +#define SMI330_CFG_ODR_MASK GENMASK(3, 0)
> +#define SMI330_CFG_RANGE_MASK GENMASK(6, 4)
> +#define SMI330_CFG_BW_MASK BIT(7)
> +#define SMI330_CFG_AVG_NUM_MASK GENMASK(10, 8)
> +#define SMI330_CFG_MODE_MASK GENMASK(14, 12)
> +#define SMI330_IO_INT_CTRL_INT1_MASK GENMASK(2, 0)
> +#define SMI330_IO_INT_CTRL_INT2_MASK GENMASK(10, 8)
> +#define SMI330_INT_CONF_LATCH_MASK BIT(0)
> +#define SMI330_INT_MAP2_ACC_DRDY_MASK GENMASK(11, 10)
> +#define SMI330_INT_MAP2_GYR_DRDY_MASK GENMASK(9, 8)
> +#define SMI330_INT_MAP2_DRDY_MASK \
> +	(SMI330_INT_MAP2_ACC_DRDY_MASK | SMI330_INT_MAP2_GYR_DRDY_MASK)

Trivial but I'm not sure this composite mask is useful. I would just
have used the two masks inline. I didn't bother modifying this though.



> +
> +static int smi330_read_avail(struct iio_dev *indio_dev,
> +			     struct iio_chan_spec const *chan, const int **vals,
> +			     int *type, int *length, long mask)
> +{
> +	switch (mask) {
> +	case IIO_CHAN_INFO_SCALE:
> +		if (chan->type == IIO_ACCEL) {
> +			*vals = smi330_accel_scale_attr.vals;
> +			*length = smi330_accel_scale_attr.len;
> +			*type = smi330_accel_scale_attr.type;
> +		} else {
> +			*vals = smi330_gyro_scale_attr.vals;
> +			*length = smi330_gyro_scale_attr.len;
> +			*type = smi330_gyro_scale_attr.type;
> +		}
> +		return IIO_AVAIL_LIST;
> +	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> +		*vals = smi330_average_attr.vals;
> +		*length = smi330_average_attr.len;
> +		*type = smi330_average_attr.type;
> +		*type = IIO_VAL_INT;
> +		return IIO_AVAIL_LIST;
> +	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
> +		*vals = smi330_bandwidth_attr.vals;
> +		*length = smi330_bandwidth_attr.len;
> +		*type = smi330_bandwidth_attr.type;
> +		return IIO_AVAIL_LIST;
> +	case IIO_CHAN_INFO_SAMP_FREQ:
> +		*vals = smi330_odr_attr.vals;
> +		*length = smi330_odr_attr.len;
> +		*type = smi330_odr_attr.type;
> +		return IIO_AVAIL_LIST;
> +	default:
> +		return -EINVAL;
> +	}
> +
Unreachable code. I'm a bit surprised the compiler didn't moan about this.

> +	return -EINVAL;
> +}

      reply	other threads:[~2025-09-27 14:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15 16:09 [PATCH v4 0/2] iio: imu: smi330: add bosch smi330 driver Jianping.Shen
2025-09-15 16:09 ` [PATCH v4 1/2] dt-bindings: iio: imu: smi330: Add binding Jianping.Shen
2025-09-16 19:32   ` Conor Dooley
2025-09-15 16:09 ` [PATCH v4 2/2] iio: imu: smi330: Add driver Jianping.Shen
2025-09-27 14:44   ` Jonathan Cameron [this message]

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=20250927154428.381df54e@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Christian.Lorenz3@de.bosch.com \
    --cc=Jianping.Shen@de.bosch.com \
    --cc=Kai.Dolde@de.bosch.com \
    --cc=Ulrike.Frauendorf@de.bosch.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dima.fedrau@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=robh@kernel.org \
    /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