linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Alexandru Ardelean <alexandru.ardelean@analog.com>
Cc: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<nuno.sa@analog.com>
Subject: Re: [PATCH v2 7/9] iio: imu: adis: add support product ID check in adis_initial_startup
Date: Fri, 14 Feb 2020 14:41:21 +0000	[thread overview]
Message-ID: <20200214144121.2c4864a6@archlinux> (raw)
In-Reply-To: <20200210132606.9315-7-alexandru.ardelean@analog.com>

On Mon, 10 Feb 2020 15:26:04 +0200
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> Each driver/chip that wants to validate it's product id, can now
> specify a 'prod_id_reg' and an expected 'prod_id' value.
> The 'prod_id' value is intentionally left 0 (uninitialized). There aren't
> (yet) any product IDs with value 0; this enforces that both 'prod_id_reg'
> and 'prod_id' are specified.
> 
> At the very least, this routine validates that the SPI connection to the
> ADIS chip[s] works well.
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Applied.  Thanks,

Jonathan

> ---
>  drivers/iio/imu/adis.c       | 23 ++++++++++++++++++++++-
>  include/linux/iio/imu/adis.h |  5 +++++
>  2 files changed, 27 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/imu/adis.c b/drivers/iio/imu/adis.c
> index 0bd6e32cf577..a8afd01de4f3 100644
> --- a/drivers/iio/imu/adis.c
> +++ b/drivers/iio/imu/adis.c
> @@ -373,6 +373,10 @@ static int adis_self_test(struct adis *adis)
>   * via GPIOLIB. If no pin is configured a SW reset will be performed.
>   * The RST pin for the ADIS devices should be configured as ACTIVE_LOW.
>   *
> + * After the self-test operation is performed, the function will also check
> + * that the product ID is as expected. This assumes that drivers providing
> + * 'prod_id_reg' will also provide the 'prod_id'.
> + *
>   * Returns 0 if the device is operational, a negative error code otherwise.
>   *
>   * This function should be called early on in the device initialization sequence
> @@ -382,6 +386,7 @@ int __adis_initial_startup(struct adis *adis)
>  {
>  	const struct adis_timeout *timeouts = adis->data->timeouts;
>  	struct gpio_desc *gpio;
> +	uint16_t prod_id;
>  	int ret;
>  
>  	/* check if the device has rst pin low */
> @@ -401,7 +406,23 @@ int __adis_initial_startup(struct adis *adis)
>  			return ret;
>  	}
>  
> -	return adis_self_test(adis);
> +	ret = adis_self_test(adis);
> +	if (ret)
> +		return ret;
> +
> +	if (!adis->data->prod_id_reg)
> +		return 0;
> +
> +	ret = adis_read_reg_16(adis, adis->data->prod_id_reg, &prod_id);
> +	if (ret)
> +		return ret;
> +
> +	if (prod_id != adis->data->prod_id)
> +		dev_warn(&adis->spi->dev,
> +			 "Device ID(%u) and product ID(%u) do not match.",
> +			 adis->data->prod_id, prod_id);
> +
> +	return 0;
>  }
>  EXPORT_SYMBOL_GPL(__adis_initial_startup);
>  
> diff --git a/include/linux/iio/imu/adis.h b/include/linux/iio/imu/adis.h
> index b7feca4e5f26..ac7cfd073804 100644
> --- a/include/linux/iio/imu/adis.h
> +++ b/include/linux/iio/imu/adis.h
> @@ -41,6 +41,8 @@ struct adis_timeout {
>   * @glob_cmd_reg: Register address of the GLOB_CMD register
>   * @msc_ctrl_reg: Register address of the MSC_CTRL register
>   * @diag_stat_reg: Register address of the DIAG_STAT register
> + * @prod_id_reg: Register address of the PROD_ID register
> + * @prod_id: Product ID code that should be expected when reading @prod_id_reg
>   * @self_test_reg: Register address to request self test command
>   * @status_error_msgs: Array of error messgaes
>   * @status_error_mask:
> @@ -54,6 +56,9 @@ struct adis_data {
>  	unsigned int glob_cmd_reg;
>  	unsigned int msc_ctrl_reg;
>  	unsigned int diag_stat_reg;
> +	unsigned int prod_id_reg;
> +
> +	unsigned int prod_id;
>  
>  	unsigned int self_test_mask;
>  	unsigned int self_test_reg;


  reply	other threads:[~2020-02-14 14:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-10 13:25 [PATCH v2 1/9] iio: imu: adis16480: initialize adis_data statically Alexandru Ardelean
2020-02-10 13:25 ` [PATCH v2 2/9] iio: imu: adis16400: " Alexandru Ardelean
2020-02-14 14:29   ` Jonathan Cameron
2020-02-10 13:26 ` [PATCH v2 3/9] iio: gyro: adis16136: " Alexandru Ardelean
2020-02-14 14:30   ` Jonathan Cameron
2020-02-10 13:26 ` [PATCH v2 4/9] iio: imu: adis: add unlocked __adis_initial_startup() Alexandru Ardelean
2020-02-14 14:31   ` Jonathan Cameron
2020-02-10 13:26 ` [PATCH v2 5/9] iio: imu: adis: Add self_test_reg variable Alexandru Ardelean
2020-02-14 14:33   ` Jonathan Cameron
2020-02-10 13:26 ` [PATCH v2 6/9] iio: imu: adis: Refactor adis_initial_startup Alexandru Ardelean
2020-02-14 14:39   ` Jonathan Cameron
2020-02-10 13:26 ` [PATCH v2 7/9] iio: imu: adis: add support product ID check in adis_initial_startup Alexandru Ardelean
2020-02-14 14:41   ` Jonathan Cameron [this message]
2020-02-10 13:26 ` [PATCH v2 8/9] iio: adis16480: Make use of __adis_initial_startup Alexandru Ardelean
2020-02-14 14:44   ` Jonathan Cameron
2020-02-10 13:26 ` [PATCH v2 9/9] iio: adis16460: " Alexandru Ardelean
2020-02-14 14:45   ` Jonathan Cameron
2020-02-14 14:28 ` [PATCH v2 1/9] iio: imu: adis16480: initialize adis_data statically 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=20200214144121.2c4864a6@archlinux \
    --to=jic23@kernel.org \
    --cc=alexandru.ardelean@analog.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.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).