public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Justin Weiss <justin@justinweiss.com>
Cc: "Alex Lanzano" <lanzano.alex@gmail.com>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Derek J . Clark" <derekjohn.clark@gmail.com>,
	"Philip Müller" <philm@manjaro.org>
Subject: Re: [PATCH v3 2/6] iio: imu: bmi270: Provide chip info as configuration structure
Date: Tue, 22 Oct 2024 19:43:51 +0100	[thread overview]
Message-ID: <20241022194351.39c832d3@jic23-huawei> (raw)
In-Reply-To: <20241020220011.212395-3-justin@justinweiss.com>

On Sun, 20 Oct 2024 15:00:06 -0700
Justin Weiss <justin@justinweiss.com> wrote:

> Prepare the bmi270 driver to support similar devices like the bmi260.
> 
> Signed-off-by: Justin Weiss <justin@justinweiss.com>
In the interests of reducing how many patches are in flight I'll
pick this one as well. Can't go beyond this point though until patch 3
gets a DT RB.
> ---
>  drivers/iio/imu/bmi270/bmi270.h      | 11 ++++++++++-
>  drivers/iio/imu/bmi270/bmi270_core.c | 18 ++++++++++++++----
>  drivers/iio/imu/bmi270/bmi270_i2c.c  | 11 ++++++++---
>  drivers/iio/imu/bmi270/bmi270_spi.c  | 11 ++++++++---
>  4 files changed, 40 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/iio/imu/bmi270/bmi270.h b/drivers/iio/imu/bmi270/bmi270.h
> index 8ac20ad7ee94..93e5f387607b 100644
> --- a/drivers/iio/imu/bmi270/bmi270.h
> +++ b/drivers/iio/imu/bmi270/bmi270.h
> @@ -10,10 +10,19 @@ struct device;
>  struct bmi270_data {
>  	struct device *dev;
>  	struct regmap *regmap;
> +	const struct bmi270_chip_info *chip_info;
> +};
> +
> +struct bmi270_chip_info {
> +	const char *name;
> +	int chip_id;
> +	const char *fw_name;
>  };
>  
>  extern const struct regmap_config bmi270_regmap_config;
> +extern const struct bmi270_chip_info bmi270_chip_info;
>  
> -int bmi270_core_probe(struct device *dev, struct regmap *regmap);
> +int bmi270_core_probe(struct device *dev, struct regmap *regmap,
> +		      const struct bmi270_chip_info *chip_info);
>  
>  #endif  /* BMI270_H_ */
> diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/bmi270_core.c
> index e598c642178f..5f08d786fa21 100644
> --- a/drivers/iio/imu/bmi270/bmi270_core.c
> +++ b/drivers/iio/imu/bmi270/bmi270_core.c
> @@ -66,6 +66,13 @@ enum bmi270_scan {
>  	BMI270_SCAN_GYRO_Z,
>  };
>  
> +const struct bmi270_chip_info bmi270_chip_info = {
> +	.name = "bmi270",
> +	.chip_id = BMI270_CHIP_ID_VAL,
> +	.fw_name = BMI270_INIT_DATA_FILE,
> +};
> +EXPORT_SYMBOL_NS_GPL(bmi270_chip_info, IIO_BMI270);
> +
>  static int bmi270_get_data(struct bmi270_data *bmi270_device,
>  			   int chan_type, int axis, int *val)
>  {
> @@ -150,7 +157,7 @@ static int bmi270_validate_chip_id(struct bmi270_data *bmi270_device)
>  	if (ret)
>  		return dev_err_probe(dev, ret, "Failed to read chip id");
>  
> -	if (chip_id != BMI270_CHIP_ID_VAL)
> +	if (chip_id != bmi270_device->chip_info->chip_id)
>  		dev_info(dev, "Unknown chip id 0x%x", chip_id);
>  
>  	return 0;
> @@ -183,7 +190,8 @@ static int bmi270_write_calibration_data(struct bmi270_data *bmi270_device)
>  		return dev_err_probe(dev, ret,
>  				     "Failed to prepare device to load init data");
>  
> -	ret = request_firmware(&init_data, BMI270_INIT_DATA_FILE, dev);
> +	ret = request_firmware(&init_data,
> +			       bmi270_device->chip_info->fw_name, dev);
>  	if (ret)
>  		return dev_err_probe(dev, ret, "Failed to load init data file");
>  
> @@ -270,7 +278,8 @@ static int bmi270_chip_init(struct bmi270_data *bmi270_device)
>  	return bmi270_configure_imu(bmi270_device);
>  }
>  
> -int bmi270_core_probe(struct device *dev, struct regmap *regmap)
> +int bmi270_core_probe(struct device *dev, struct regmap *regmap,
> +		      const struct bmi270_chip_info *chip_info)
>  {
>  	int ret;
>  	struct bmi270_data *bmi270_device;
> @@ -283,6 +292,7 @@ int bmi270_core_probe(struct device *dev, struct regmap *regmap)
>  	bmi270_device = iio_priv(indio_dev);
>  	bmi270_device->dev = dev;
>  	bmi270_device->regmap = regmap;
> +	bmi270_device->chip_info = chip_info;
>  
>  	ret = bmi270_chip_init(bmi270_device);
>  	if (ret)
> @@ -290,7 +300,7 @@ int bmi270_core_probe(struct device *dev, struct regmap *regmap)
>  
>  	indio_dev->channels = bmi270_channels;
>  	indio_dev->num_channels = ARRAY_SIZE(bmi270_channels);
> -	indio_dev->name = "bmi270";
> +	indio_dev->name = chip_info->name;
>  	indio_dev->modes = INDIO_DIRECT_MODE;
>  	indio_dev->info = &bmi270_info;
>  
> diff --git a/drivers/iio/imu/bmi270/bmi270_i2c.c b/drivers/iio/imu/bmi270/bmi270_i2c.c
> index d59161f23f9a..394f27996059 100644
> --- a/drivers/iio/imu/bmi270/bmi270_i2c.c
> +++ b/drivers/iio/imu/bmi270/bmi270_i2c.c
> @@ -17,22 +17,27 @@ static int bmi270_i2c_probe(struct i2c_client *client)
>  {
>  	struct regmap *regmap;
>  	struct device *dev = &client->dev;
> +	const struct bmi270_chip_info *chip_info;
> +
> +	chip_info = i2c_get_match_data(client);
> +	if (!chip_info)
> +		return -ENODEV;
>  
>  	regmap = devm_regmap_init_i2c(client, &bmi270_i2c_regmap_config);
>  	if (IS_ERR(regmap))
>  		return dev_err_probe(dev, PTR_ERR(regmap),
>  				     "Failed to init i2c regmap");
>  
> -	return bmi270_core_probe(dev, regmap);
> +	return bmi270_core_probe(dev, regmap, chip_info);
>  }
>  
>  static const struct i2c_device_id bmi270_i2c_id[] = {
> -	{ "bmi270", 0 },
> +	{ "bmi270", (kernel_ulong_t)&bmi270_chip_info },
>  	{ }
>  };
>  
>  static const struct of_device_id bmi270_of_match[] = {
> -	{ .compatible = "bosch,bmi270" },
> +	{ .compatible = "bosch,bmi270", .data = &bmi270_chip_info },
>  	{ }
>  };
>  
> diff --git a/drivers/iio/imu/bmi270/bmi270_spi.c b/drivers/iio/imu/bmi270/bmi270_spi.c
> index b53784d4a1f4..7c2062c660d9 100644
> --- a/drivers/iio/imu/bmi270/bmi270_spi.c
> +++ b/drivers/iio/imu/bmi270/bmi270_spi.c
> @@ -49,6 +49,11 @@ static int bmi270_spi_probe(struct spi_device *spi)
>  {
>  	struct regmap *regmap;
>  	struct device *dev = &spi->dev;
> +	const struct bmi270_chip_info *chip_info;
> +
> +	chip_info = spi_get_device_match_data(spi);
> +	if (!chip_info)
> +		return -ENODEV;
>  
>  	regmap = devm_regmap_init(dev, &bmi270_regmap_bus, dev,
>  				  &bmi270_spi_regmap_config);
> @@ -56,16 +61,16 @@ static int bmi270_spi_probe(struct spi_device *spi)
>  		return dev_err_probe(dev, PTR_ERR(regmap),
>  				     "Failed to init i2c regmap");
>  
> -	return bmi270_core_probe(dev, regmap);
> +	return bmi270_core_probe(dev, regmap, chip_info);
>  }
>  
>  static const struct spi_device_id bmi270_spi_id[] = {
> -	{ "bmi270" },
> +	{ "bmi270", (kernel_ulong_t)&bmi270_chip_info },
>  	{ }
>  };
>  
>  static const struct of_device_id bmi270_of_match[] = {
> -	{ .compatible = "bosch,bmi270" },
> +	{ .compatible = "bosch,bmi270", .data = &bmi270_chip_info },
>  	{ }
>  };
>  


  reply	other threads:[~2024-10-22 18:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-20 22:00 [PATCH v3 0/6] Add i2c driver for Bosch BMI260 IMU Justin Weiss
2024-10-20 22:00 ` [PATCH v3 1/6] iio: imu: bmi270: Remove unused FREQUENCY / SCALE attributes Justin Weiss
2024-10-22 18:41   ` Jonathan Cameron
2024-10-20 22:00 ` [PATCH v3 2/6] iio: imu: bmi270: Provide chip info as configuration structure Justin Weiss
2024-10-22 18:43   ` Jonathan Cameron [this message]
2024-10-20 22:00 ` [PATCH v3 3/6] dt-bindings: iio: imu: bmi270: Add Bosch BMI260 Justin Weiss
2024-10-21  7:38   ` Krzysztof Kozlowski
2024-10-22 15:51     ` Justin Weiss
2024-10-20 22:00 ` [PATCH v3 4/6] iio: imu: bmi270: Add support for BMI260 Justin Weiss
2024-10-22 15:50   ` Justin Weiss
2024-10-22 16:54     ` Andy Shevchenko
2024-10-22 19:34       ` Jonathan Cameron
2024-10-25 15:42         ` Justin Weiss
2024-10-25 16:34           ` Andy Shevchenko
2024-10-24  6:40     ` Philip Müller
2024-10-24  7:01       ` Andy Shevchenko
2024-10-20 22:00 ` [PATCH v3 5/6] iio: imu: bmi270: Add triggered buffer for Bosch BMI270 IMU Justin Weiss
2024-10-20 22:00 ` [PATCH v3 6/6] iio: imu: bmi270: Add scale and sampling frequency to " Justin Weiss

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=20241022194351.39c832d3@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=derekjohn.clark@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=justin@justinweiss.com \
    --cc=krzk+dt@kernel.org \
    --cc=lanzano.alex@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=philm@manjaro.org \
    --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