Devicetree
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Barnabás Czémán" <barnabas.czeman@mainlining.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Jonathan Albrieux <jonathan.albrieux@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org, linux@mainlining.org,
	Danila Tikhonov <danila@jiaxyga.com>
Subject: Re: [PATCH v2 3/3] iio: magnetometer: ak8975: Add AK09118 support
Date: Tue, 6 Aug 2024 17:26:06 +0100	[thread overview]
Message-ID: <20240806172606.70a07084@jic23-huawei> (raw)
In-Reply-To: <20240806-ak09918-v2-3-c300da66c198@mainlining.org>

On Tue, 06 Aug 2024 08:10:20 +0200
Barnabás Czémán <barnabas.czeman@mainlining.org> wrote:

> From: Danila Tikhonov <danila@jiaxyga.com>
> 
> Add additional AK09118 to the magnetometer driver which has the same
> register mapping and scaling as the AK09112 device.
> 
> Signed-off-by: Danila Tikhonov <danila@jiaxyga.com>
> Signed-off-by: Barnabás Czémán <barnabas.czeman@mainlining.org>

It definitely seems like a fallback compatible is suitable, but we
will still want the more precise match in the driver so that we can
avoid printing an info message to say we saw an unexpected ID.

Comments on that inline.

> ---
>  drivers/iio/magnetometer/Kconfig  |  2 +-
>  drivers/iio/magnetometer/ak8975.c | 34 ++++++++++++++++++++++++++++++++++
>  2 files changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig
> index cd2917d71904..8eb718f5e50f 100644
> --- a/drivers/iio/magnetometer/Kconfig
> +++ b/drivers/iio/magnetometer/Kconfig
> @@ -39,7 +39,7 @@ config AK8975
>  	select IIO_TRIGGERED_BUFFER
>  	help
>  	  Say yes here to build support for Asahi Kasei AK8975, AK8963,
> -	  AK09911, AK09912 or AK09916 3-Axis Magnetometer.
> +	  AK09911, AK09912, AK09916 or AK09918 3-Axis Magnetometer.
>  
>  	  To compile this driver as a module, choose M here: the module
>  	  will be called ak8975.
> diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
> index 925d76062b3e..9871fea67ae3 100644
> --- a/drivers/iio/magnetometer/ak8975.c
> +++ b/drivers/iio/magnetometer/ak8975.c
> @@ -78,6 +78,7 @@
>   */
>  #define AK09912_REG_WIA1		0x00
>  #define AK09912_REG_WIA2		0x01
> +#define AK09918_DEVICE_ID		0x0C
>  #define AK09916_DEVICE_ID		0x09
>  #define AK09912_DEVICE_ID		0x04
>  #define AK09911_DEVICE_ID		0x05
> @@ -209,6 +210,7 @@ enum asahi_compass_chipset {
>  	AK09911,
>  	AK09912,
>  	AK09916,
> +	AK09918,
>  };
>  
>  enum ak_ctrl_reg_addr {
> @@ -371,6 +373,31 @@ static const struct ak_def ak_def_array[] = {
>  			AK09912_REG_HXL,
>  			AK09912_REG_HYL,
>  			AK09912_REG_HZL},
> +	},
> +	[AK09918] = {
> +		.type = AK09918,
> +		.raw_to_gauss = ak09912_raw_to_gauss,
> +		.range = 32752,
> +		.ctrl_regs = {
> +			AK09912_REG_ST1,
> +			AK09912_REG_ST2,
> +			AK09912_REG_CNTL2,
> +			AK09912_REG_ASAX,
> +			AK09912_MAX_REGS},
> +		.ctrl_masks = {
> +			AK09912_REG_ST1_DRDY_MASK,
> +			AK09912_REG_ST2_HOFL_MASK,
> +			0,
> +			AK09912_REG_CNTL2_MODE_MASK},
> +		.ctrl_modes = {
> +			AK09912_REG_CNTL_MODE_POWER_DOWN,
> +			AK09912_REG_CNTL_MODE_ONCE,
> +			AK09912_REG_CNTL_MODE_SELF_TEST,
> +			AK09912_REG_CNTL_MODE_FUSE_ROM},
> +		.data_regs = {
> +			AK09912_REG_HXL,
> +			AK09912_REG_HYL,
> +			AK09912_REG_HZL},
>  	}
>  };
>  
> @@ -452,6 +479,7 @@ static int ak8975_who_i_am(struct i2c_client *client,
>  	/*
>  	 * Signature for each device:
>  	 * Device   |  WIA1      |  WIA2
> +	 * AK09918  |  DEVICE_ID_|  AK09918_DEVICE_ID
>  	 * AK09916  |  DEVICE_ID_|  AK09916_DEVICE_ID
>  	 * AK09912  |  DEVICE_ID |  AK09912_DEVICE_ID
>  	 * AK09911  |  DEVICE_ID |  AK09911_DEVICE_ID
> @@ -484,6 +512,10 @@ static int ak8975_who_i_am(struct i2c_client *client,
>  		if (wia_val[1] == AK09916_DEVICE_ID)
>  			return 0;
>  		break;
> +	case AK09918:
> +		if (wia_val[1] == AK09918_DEVICE_ID)
> +			return 0;
> +		break;
Whilst you are changing this code, please make it accept an unknown ID
with at most a dev_info() print. We used to get this wrong in IIO, but
this flexibility in matching Who Am I values is necessary to enable
fallback compatibles in DT.

Those allow you to use a newer DT with an older driver. It will
use the fallback ID to probe, so will get the ak09912 who am I value
and fail to probe currently.  We want it to succeed if they are
completely compatible other than this ID.

>  	default:
>  		dev_err(&client->dev, "Type %d unknown\n", type);
>  	}
> @@ -1066,6 +1098,7 @@ static const struct i2c_device_id ak8975_id[] = {
>  	{"ak09911", (kernel_ulong_t)&ak_def_array[AK09911] },
>  	{"ak09912", (kernel_ulong_t)&ak_def_array[AK09912] },
>  	{"ak09916", (kernel_ulong_t)&ak_def_array[AK09916] },
> +	{"ak09918", (kernel_ulong_t)&ak_def_array[AK09918] },
>  	{}
>  };
>  MODULE_DEVICE_TABLE(i2c, ak8975_id);
> @@ -1081,6 +1114,7 @@ static const struct of_device_id ak8975_of_match[] = {
>  	{ .compatible = "ak09912", .data = &ak_def_array[AK09912] },
>  	{ .compatible = "asahi-kasei,ak09916", .data = &ak_def_array[AK09916] },
>  	{ .compatible = "ak09916", .data = &ak_def_array[AK09916] },
> +	{ .compatible = "asahi-kasei,ak09918", .data = &ak_def_array[AK09918] },
>  	{}
>  };
>  MODULE_DEVICE_TABLE(of, ak8975_of_match);
> 


  reply	other threads:[~2024-08-06 16:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-06  6:10 [PATCH v2 0/3] Add support for AK09918 Barnabás Czémán
2024-08-06  6:10 ` [PATCH v2 1/3] iio: magnetometer: ak8975: Fix reading for ak099xx sensors Barnabás Czémán
2024-08-06 16:19   ` Jonathan Cameron
2024-08-06 17:54     ` Barnabás Czémán
2024-08-10 10:27       ` Jonathan Cameron
2024-08-07 15:15     ` barnabas.czeman
2024-08-06  6:10 ` [PATCH v2 2/3] dt-bindings: iio: imu: magnetometer: Add ak09118 Barnabás Czémán
2024-08-06 16:00   ` Conor Dooley
2024-08-06 16:01     ` Conor Dooley
2024-08-07  6:03   ` Krzysztof Kozlowski
2024-08-06  6:10 ` [PATCH v2 3/3] iio: magnetometer: ak8975: Add AK09118 support Barnabás Czémán
2024-08-06 16:26   ` Jonathan Cameron [this message]
2024-08-07  6:04   ` Krzysztof Kozlowski
2024-08-12 14:26     ` Barnabás Czémán

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=20240806172606.70a07084@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=barnabas.czeman@mainlining.org \
    --cc=conor+dt@kernel.org \
    --cc=danila@jiaxyga.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jonathan.albrieux@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@mainlining.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