From: Tomas Melin <tomas.melin@vaisala.com>
To: Sean Nyekjaer <sean@geanix.com>,
jic23@kernel.org, linux-iio@vger.kernel.org,
andy.shevchenko@gmail.com, lars@metafoo.de, Nuno.Sa@analog.com,
robh+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 1/6] iio: accel: add support for FXLS8962AF/FXLS8964AF accelerometers
Date: Fri, 30 Apr 2021 12:25:48 +0300 [thread overview]
Message-ID: <ab6fffc8-2e40-47b4-24f2-6ec5b7803915@vaisala.com> (raw)
In-Reply-To: <20210429122806.3814330-1-sean@geanix.com>
Hi,
few comments inline below.
Thanks,
Tomas
On 4/29/21 3:28 PM, Sean Nyekjaer wrote:
> Add basic support for NXP FXLS8962AF/FXLS8964AF Automotive
> accelerometers.
> It will allow setting up scale/gain and reading x,y,z
> axis.
>
> Datasheet: https://www.nxp.com/docs/en/data-sheet/FXLS8962AF.pdf
> Datasheet: https://www.nxp.com/docs/en/data-sheet/FXLS8964AF.pdf
> Signed-off-by: Sean Nyekjaer <sean@geanix.com>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> ---
> Changes for v2:
> - Addressed Kconfig comments
> - Using regmap_read_poll_timeout()
> - Addresed comments from Andy and Jonathan
>
> Changes for v3:
> - fixed Kconfig ordering
> - read INT_STATUS after reset, to ensure the device is ready
> - fixed a few xmas trees
> - added datasheet tags
>
> Changes for v4:
> - reworked read_raw -> fxls8962af_get_out, so we will skip the claim
> part.
> - Removed the drdy check, worstcase data will be 1,28s/0.781Hz old.
>
> drivers/iio/accel/Kconfig | 27 ++
> drivers/iio/accel/Makefile | 3 +
> drivers/iio/accel/fxls8962af-core.c | 563 ++++++++++++++++++++++++++++
> drivers/iio/accel/fxls8962af-i2c.c | 57 +++
> drivers/iio/accel/fxls8962af-spi.c | 57 +++
> drivers/iio/accel/fxls8962af.h | 22 ++
> 6 files changed, 729 insertions(+)
> create mode 100644 drivers/iio/accel/fxls8962af-core.c
> create mode 100644 drivers/iio/accel/fxls8962af-i2c.c
> create mode 100644 drivers/iio/accel/fxls8962af-spi.c
> create mode 100644 drivers/iio/accel/fxls8962af.h
>
> diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
> index 2e0c62c39155..7317d839ca1a 100644
> --- a/drivers/iio/accel/Kconfig
> +++ b/drivers/iio/accel/Kconfig
> @@ -208,6 +208,33 @@ config DMARD10
> Choosing M will build the driver as a module. If so, the module
> will be called dmard10.
>
...
> +}
> +
> +static int fxls8962af_power_off(struct fxls8962af_data *data)
> +{
> + struct device *dev = regmap_get_device(data->regmap);
> + int ret;
> +
> + pm_runtime_mark_last_busy(dev);
> + ret = pm_runtime_put_autosuspend(dev);
> +
could drop extra empty line here.
> + if (ret < 0) {
> + dev_err(dev, "failed to power off\n");
> + }
> +
> + return ret;
> +}
...
> +
> +static int fxls8962af_reset(struct fxls8962af_data *data)
> +{
> + struct device *dev = regmap_get_device(data->regmap);
> + unsigned int reg;
> + int ret;
> +
> + ret = regmap_update_bits(data->regmap, FXLS8962AF_SENS_CONFIG1,
> + FXLS8962AF_SENS_CONFIG1_RST,
> + FXLS8962AF_SENS_CONFIG1_RST);
> + if (ret < 0)
> + return ret;
> +
> + /* TBOOT1, TBOOT2, specifies we have to wait between 1 - 17.7ms */
> + ret = regmap_read_poll_timeout(data->regmap, FXLS8962AF_INT_STATUS, reg,
> + (reg & FXLS8962AF_INT_STATUS_SRC_BOOT), 1000, 18000);
> + if (ret)
> + dev_err(dev, "reset timeout, int_status = 0x%x\n", reg);
Should check for -ETIMEDOUT here rather than generic error? and handle
both cases.
> +
> + return ret;
> +}
> +
> +static void fxls8962af_regulator_disable(void *data_ptr)
> +{
> + struct fxls8962af_data *data = data_ptr;
> +
> + regulator_disable(data->vdd_reg);
> +}
> +
> +static void fxls8962af_pm_disable(void *dev_ptr)
> +{
> + struct device *dev = dev_ptr;
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +
> + pm_runtime_disable(dev);
> + pm_runtime_set_suspended(dev);
> + pm_runtime_put_noidle(dev);
> +
> + fxls8962af_standby(iio_priv(indio_dev));
> +}
> +
> +int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq)
> +{
> + struct fxls8962af_data *data;
> + struct iio_dev *indio_dev;
> + unsigned int reg;
> + int ret, i;
> +
> + indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + data = iio_priv(indio_dev);
> + dev_set_drvdata(dev, indio_dev);
> + data->regmap = regmap;
> +
> + ret = iio_read_mount_matrix(dev, "mount-matrix", &data->orientation);
> + if (ret)
> + return ret;
> +
> + data->vdd_reg = devm_regulator_get(dev, "vdd");
> + if (IS_ERR(data->vdd_reg))
> + return dev_err_probe(dev, PTR_ERR(data->vdd_reg),
> + "Failed to get vdd regulator\n");
> +
> + ret = regulator_enable(data->vdd_reg);
> + if (ret) {
> + dev_err(dev, "Failed to enable vdd regulator: %d\n", ret);
> + return ret;
> + }
> +
> + ret = devm_add_action_or_reset(dev, fxls8962af_regulator_disable, data);
> + if (ret)
> + return ret;
> +
> + ret = regmap_read(data->regmap, FXLS8962AF_WHO_AM_I, ®);
> + if (ret < 0)
> + return ret;
Could consider to use if (ret) consistently throughout this function?
> +
> + for (i = 0; i < ARRAY_SIZE(fxls_chip_info_table); i++) {
> + if (fxls_chip_info_table[i].chip_id == reg) {
> + data->chip_info = &fxls_chip_info_table[i];
> + break;
> + }
> + }
> + if (i == ARRAY_SIZE(fxls_chip_info_table)) {
> + dev_err(dev, "failed to match device in table\n");
> + return -ENXIO;
> + }
> +
> + indio_dev->channels = data->chip_info->channels;
> + indio_dev->num_channels = data->chip_info->num_channels;
> + indio_dev->name = data->chip_info->name;
> + indio_dev->info = &fxls8962af_info;
> + indio_dev->modes = INDIO_DIRECT_MODE;
> +
> + ret = fxls8962af_reset(data);
> + if (ret < 0)
> + return ret;
> +
> + ret = pm_runtime_set_active(dev);
> + if (ret < 0)
> + return ret;
> +
> + pm_runtime_enable(dev);
> + pm_runtime_set_autosuspend_delay(dev, FXLS8962AF_AUTO_SUSPEND_DELAY_MS);
> + pm_runtime_use_autosuspend(dev);
> +
> + ret = devm_add_action_or_reset(dev, fxls8962af_pm_disable, dev);
> + if (ret)
> + return ret;
> +
> + return devm_iio_device_register(dev, indio_dev);
> +}
> +EXPORT_SYMBOL_GPL(fxls8962af_core_probe);
> +
> +
next prev parent reply other threads:[~2021-04-30 9:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-29 12:28 [PATCH v4 1/6] iio: accel: add support for FXLS8962AF/FXLS8964AF accelerometers Sean Nyekjaer
2021-04-29 12:28 ` [PATCH v4 2/6] dt-bindings: iio: accel: fxls8962af: add bindings Sean Nyekjaer
2021-04-29 15:25 ` Rob Herring
2021-04-29 12:28 ` [PATCH v4 3/6] iio: accel: fxls8962af: add set/get of samplerate Sean Nyekjaer
2021-04-29 12:28 ` [PATCH v4 4/6] iio: accel: fxls8962af: add interrupt support Sean Nyekjaer
2021-04-30 9:02 ` Andy Shevchenko
2021-05-03 11:19 ` Sean Nyekjaer
2021-04-29 12:28 ` [PATCH v4 5/6] iio: accel: fxls8962af: add hw buffered sampling Sean Nyekjaer
2021-04-30 9:10 ` Andy Shevchenko
2021-04-29 12:28 ` [PATCH v4 6/6] iio: accel: fxls8962af: fix errata bug E3 - I2C burst reads Sean Nyekjaer
2021-04-30 9:14 ` Andy Shevchenko
2021-04-30 9:25 ` Tomas Melin [this message]
2021-05-02 17:46 ` [PATCH v4 1/6] iio: accel: add support for FXLS8962AF/FXLS8964AF accelerometers 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=ab6fffc8-2e40-47b4-24f2-6ec5b7803915@vaisala.com \
--to=tomas.melin@vaisala.com \
--cc=Nuno.Sa@analog.com \
--cc=andy.shevchenko@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=sean@geanix.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;
as well as URLs for NNTP newsgroup(s).