* [PATCH 0/3] Add support for AK09918
@ 2024-08-05 20:31 Barnabás Czémán
2024-08-05 20:31 ` [PATCH 1/3] iio: magnetometer: ak8975: Fix reading for ak099xx sensors Barnabás Czémán
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Barnabás Czémán @ 2024-08-05 20:31 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Albrieux
Cc: linux-iio, linux-kernel, devicetree, linux,
Barnabás Czémán, Danila Tikhonov
Add support for AK09918 which is register and scaling compatible with
AK09912.
It was tested in Xiaomi Redmi 5 Plus (vince).
magnetometer@c {
compatible = "asahi-kasei,ak09918";
reg = <0x0c>;
vdd-supply = <&pm8953_l6>;
mount-matrix = "1", "0", "0",
"0", "1", "0",
"0", "0", "1";
};
Add a fix for data reading according to datasheet [1] (9.4.3.2.)
ST2 register should be read out after read measurment data as third step.
ST2 read out is required and get correct value during measurment data
read.
[1] https://www.akm.com/content/dam/documents/products/electronic-compass/ak09918c/ak09918c-en-datasheet.pdf
Signed-off-by: Barnabás Czémán <barnabas.czeman@mainlining.org>
---
Barnabás Czémán (1):
iio: magnetometer: ak8975: Fix reading for ak099xx sensors
Danila Tikhonov (2):
dt-bindings: iio: imu: magnetometer: Add ak09118
iio: magnetometer: ak8975: Add AK09118 support
.../iio/magnetometer/asahi-kasei,ak8975.yaml | 2 +
drivers/iio/magnetometer/Kconfig | 2 +-
drivers/iio/magnetometer/ak8975.c | 66 ++++++++++++++++------
3 files changed, 53 insertions(+), 17 deletions(-)
---
base-commit: d6dbc9f56c3a70e915625b6f1887882c23dc5c91
change-id: 20240805-ak09918-4a6cfef91c32
Best regards,
--
Barnabás Czémán <barnabas.czeman@mainlining.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] iio: magnetometer: ak8975: Fix reading for ak099xx sensors
2024-08-05 20:31 [PATCH 0/3] Add support for AK09918 Barnabás Czémán
@ 2024-08-05 20:31 ` Barnabás Czémán
2024-08-05 20:31 ` [PATCH 2/3] dt-bindings: iio: imu: magnetometer: Add ak09118 Barnabás Czémán
2024-08-05 20:31 ` [PATCH 3/3] iio: magnetometer: ak8975: Add AK09118 support Barnabás Czémán
2 siblings, 0 replies; 6+ messages in thread
From: Barnabás Czémán @ 2024-08-05 20:31 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Albrieux
Cc: linux-iio, linux-kernel, devicetree, linux,
Barnabás Czémán
ST2 register read should be placed after read measurment data,
because it will get correct values after it.
Signed-off-by: Barnabás Czémán <barnabas.czeman@mainlining.org>
---
drivers/iio/magnetometer/ak8975.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index dd466c5fa621..925d76062b3e 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -692,22 +692,7 @@ static int ak8975_start_read_axis(struct ak8975_data *data,
if (ret < 0)
return ret;
- /* This will be executed only for non-interrupt based waiting case */
- if (ret & data->def->ctrl_masks[ST1_DRDY]) {
- ret = i2c_smbus_read_byte_data(client,
- data->def->ctrl_regs[ST2]);
- if (ret < 0) {
- dev_err(&client->dev, "Error in reading ST2\n");
- return ret;
- }
- if (ret & (data->def->ctrl_masks[ST2_DERR] |
- data->def->ctrl_masks[ST2_HOFL])) {
- dev_err(&client->dev, "ST2 status error 0x%x\n", ret);
- return -EINVAL;
- }
- }
-
- return 0;
+ return !(ret & data->def->ctrl_masks[ST1_DRDY]);
}
/* Retrieve raw flux value for one of the x, y, or z axis. */
@@ -731,6 +716,20 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
ret = i2c_smbus_read_i2c_block_data_or_emulated(
client, def->data_regs[index],
sizeof(rval), (u8*)&rval);
+ ret = i2c_smbus_read_byte_data(client,
+ data->def->ctrl_regs[ST2]);
+ if (ret < 0) {
+ dev_err(&client->dev, "Error in reading ST2\n");
+ goto exit;
+ }
+
+ if (ret & (data->def->ctrl_masks[ST2_DERR] |
+ data->def->ctrl_masks[ST2_HOFL])) {
+ dev_err(&client->dev, "ST2 status error 0x%x\n", ret);
+ ret = -EINVAL;
+ goto exit;
+ }
+
if (ret < 0)
goto exit;
--
2.46.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] dt-bindings: iio: imu: magnetometer: Add ak09118
2024-08-05 20:31 [PATCH 0/3] Add support for AK09918 Barnabás Czémán
2024-08-05 20:31 ` [PATCH 1/3] iio: magnetometer: ak8975: Fix reading for ak099xx sensors Barnabás Czémán
@ 2024-08-05 20:31 ` Barnabás Czémán
2024-08-06 5:21 ` Krzysztof Kozlowski
2024-08-05 20:31 ` [PATCH 3/3] iio: magnetometer: ak8975: Add AK09118 support Barnabás Czémán
2 siblings, 1 reply; 6+ messages in thread
From: Barnabás Czémán @ 2024-08-05 20:31 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Albrieux
Cc: linux-iio, linux-kernel, devicetree, linux,
Barnabás Czémán, Danila Tikhonov
From: Danila Tikhonov <danila@jiaxyga.com>
Document asahi-kasei,ak09918 compatible.
Signed-off-by: Danila Tikhonov <danila@jiaxyga.com>
Signed-off-by: Barnabás Czémán <barnabas.czeman@mainlining.org>
---
.../devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Documentation/devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml b/Documentation/devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml
index 9790f75fc669..67c60abbfcf0 100644
--- a/Documentation/devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml
+++ b/Documentation/devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml
@@ -18,12 +18,14 @@ properties:
- asahi-kasei,ak09911
- asahi-kasei,ak09912
- asahi-kasei,ak09916
+ - asahi-kasei,ak09918
- enum:
- ak8975
- ak8963
- ak09911
- ak09912
- ak09916
+ - ak09918
deprecated: true
reg:
--
2.46.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] iio: magnetometer: ak8975: Add AK09118 support
2024-08-05 20:31 [PATCH 0/3] Add support for AK09918 Barnabás Czémán
2024-08-05 20:31 ` [PATCH 1/3] iio: magnetometer: ak8975: Fix reading for ak099xx sensors Barnabás Czémán
2024-08-05 20:31 ` [PATCH 2/3] dt-bindings: iio: imu: magnetometer: Add ak09118 Barnabás Czémán
@ 2024-08-05 20:31 ` Barnabás Czémán
2024-08-06 5:22 ` Krzysztof Kozlowski
2 siblings, 1 reply; 6+ messages in thread
From: Barnabás Czémán @ 2024-08-05 20:31 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Albrieux
Cc: linux-iio, linux-kernel, devicetree, linux,
Barnabás Czémán, Danila Tikhonov
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>
---
drivers/iio/magnetometer/Kconfig | 2 +-
drivers/iio/magnetometer/ak8975.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 36 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..de1ba7f48b4b 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;
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,8 @@ 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] },
+ { .compatible = "ak09918", .data = &ak_def_array[AK09918] },
{}
};
MODULE_DEVICE_TABLE(of, ak8975_of_match);
--
2.46.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] dt-bindings: iio: imu: magnetometer: Add ak09118
2024-08-05 20:31 ` [PATCH 2/3] dt-bindings: iio: imu: magnetometer: Add ak09118 Barnabás Czémán
@ 2024-08-06 5:21 ` Krzysztof Kozlowski
0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-06 5:21 UTC (permalink / raw)
To: Barnabás Czémán, Jonathan Cameron,
Lars-Peter Clausen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Albrieux
Cc: linux-iio, linux-kernel, devicetree, linux, Danila Tikhonov
On 05/08/2024 22:31, Barnabás Czémán wrote:
> From: Danila Tikhonov <danila@jiaxyga.com>
>
> Document asahi-kasei,ak09918 compatible.
>
> Signed-off-by: Danila Tikhonov <danila@jiaxyga.com>
> Signed-off-by: Barnabás Czémán <barnabas.czeman@mainlining.org>
> ---
> .../devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml b/Documentation/devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml
> index 9790f75fc669..67c60abbfcf0 100644
> --- a/Documentation/devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml
> +++ b/Documentation/devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml
> @@ -18,12 +18,14 @@ properties:
> - asahi-kasei,ak09911
> - asahi-kasei,ak09912
> - asahi-kasei,ak09916
> + - asahi-kasei,ak09918
> - enum:
> - ak8975
> - ak8963
> - ak09911
> - ak09912
> - ak09916
> + - ak09918
No, you cannot grow deprecated list.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] iio: magnetometer: ak8975: Add AK09118 support
2024-08-05 20:31 ` [PATCH 3/3] iio: magnetometer: ak8975: Add AK09118 support Barnabás Czémán
@ 2024-08-06 5:22 ` Krzysztof Kozlowski
0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-06 5:22 UTC (permalink / raw)
To: Barnabás Czémán, Jonathan Cameron,
Lars-Peter Clausen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Jonathan Albrieux
Cc: linux-iio, linux-kernel, devicetree, linux, Danila Tikhonov
On 05/08/2024 22:31, Barnabás Czémán 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>
...
> };
> MODULE_DEVICE_TABLE(i2c, ak8975_id);
> @@ -1081,6 +1114,8 @@ 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] },
> + { .compatible = "ak09918", .data = &ak_def_array[AK09918] },
NAK. That's not a valid compatible.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-08-06 5:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-05 20:31 [PATCH 0/3] Add support for AK09918 Barnabás Czémán
2024-08-05 20:31 ` [PATCH 1/3] iio: magnetometer: ak8975: Fix reading for ak099xx sensors Barnabás Czémán
2024-08-05 20:31 ` [PATCH 2/3] dt-bindings: iio: imu: magnetometer: Add ak09118 Barnabás Czémán
2024-08-06 5:21 ` Krzysztof Kozlowski
2024-08-05 20:31 ` [PATCH 3/3] iio: magnetometer: ak8975: Add AK09118 support Barnabás Czémán
2024-08-06 5:22 ` Krzysztof Kozlowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox