Add support for AK09918
Subsystems (2)
v4 cover Add support for AK09918
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", "asahi-kasei,ak09912"; 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 have to be read out after read measurment data as third step because ST2 will realasing the lock on the measurment data. Without it the next reading will fail.
---
Changes in v4:
- Fix commit title.
- Add Fixes tag.
- Add more comments inline.
- Rebase on latest next.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Relax failure on unknown device id
for support more register compatible variants.
- Change to fallback compatible.
- Make ST2 to be always read after measuremnt read.
- Reword fix commit with more explanation.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Remove unnecessary ak09918 compatbile.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Barnabás Czémán (2):
iio: magnetometer: ak8975: Relax failure on unknown id
iio: magnetometer: ak8975: Fix reading for ak099xx sensors
Danila Tikhonov (2):
dt-bindings: iio: magnetometer: Add ak09118
iio: magnetometer: ak8975: Add AK09118 support
.../iio/magnetometer/asahi-kasei,ak8975.yaml | 4 ++ drivers/iio/magnetometer/Kconfig | 2 +- drivers/iio/magnetometer/ak8975.c | 78 ++++++++++++++++------ 3 files changed, 64 insertions(+), 20 deletions(-)
---
base-commit: 367b5c3d53e57d51a5878816804652963da90950
change-id: 20240805-ak09918-4a6cfef91c32
Best regards,
Signature · 1 line
Barnabás Czémán <[email protected]>
PATCH v4 1/4 iio: magnetometer: ak8975: Relax failure on unknown id
Relax failure when driver gets an unknown device id for allow probe for register compatible devices.
--- drivers/iio/magnetometer/ak8975.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/iio/magnetometer/ak8975.c +6 -3
@@ -484,10 +484,13 @@ static int ak8975_who_i_am(struct i2c_client *client,if (wia_val[1 ] ==AK09916_DEVICE_ID )return 0 ;break ; -default : -dev_err (&client->dev,"Type %d unknown\n" , type); } -return -ENODEV ; + +dev_info (&client->dev,"Device ID %x is unknown.\n" , wia_val[1 ]); +/* Let driver to probe on unknown id for support more register +* compatible variants. +*/ +return 0 ; }/*
Signature · 1 line
2.46.0
Jonathan Cameron
maintainerRe: [PATCH v4 1/4] iio: magnetometer: ak8975: Relax failure on unknown id
Quoted 13 lines · On Mon, 19 Aug 2024 00:29:39 +0200 Barnabás Czémán…
Relax failure when driver gets an unknown device id for allow probe for register compatible devices.
Signed-off-by Barnabás Czémán <[email protected]>--- drivers/iio/magnetometer/ak8975.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/iio/magnetometer/ak8975.c +0
-0
drivers/iio/magnetometer/ak8975.c static int ak8975_who_i_am(struct i2c_client *client, · line 490
Quoted 10 lines
drivers/iio/magnetometer/ak8975.c +3
-3@@ -484,10 +484,13 @@ static int ak8975_who_i_am(struct i2c_client *client,if (wia_val[1 ] ==AK09916_DEVICE_ID )return 0 ;break ; -default : -dev_err (&client->dev,"Type %d unknown\n" , type); } -return -ENODEV ; + +dev_info (&client->dev,"Device ID %x is unknown.\n" , wia_val[1 ]); +/* Let driver to probe on unknown id for support more register
Comment style wrong, I'll fix it up.
With that tweak applied to the togreg branch of iio.git
Thanks,
Jonathan
Quoted 7 lines
drivers/iio/magnetometer/ak8975.c +3
-0+* compatible variants. +*/ +return 0 ; }/*
Re: [PATCH v4 1/4] iio: magnetometer: ak8975: Relax failure on unknown id
Quoted 2 lines · Jonathan Cameron
On Mon, 19 Aug 2024 00:29:39 +0200
Barnabás Czémán <[email protected]> wrote:
...
Quoted 5 lines
drivers/iio/magnetometer/ak8975.c static int ak8975_who_i_am(struct i2c_client *client, · line 490
Quoted 1 line
drivers/iio/magnetometer/ak8975.c +1
-0+/* Let driver to probe on unknown id for support more register Comment style wrong, I'll fix it up.
With that tweak applied to the togreg branch of iio.git
Quoted 7 lines
Thanks,
Jonathan
drivers/iio/magnetometer/ak8975.c static int ak8975_who_i_am(struct i2c_client *client, · line 492
Quoted 2 lines
drivers/iio/magnetometer/ak8975.c +2
-0+* compatible variants. +*/
There is another one also wrong.
+ [AK09918] = {
+ /* ak09918 is register compatible with ak09912 this is for avoid
+ * unknown id messages.
+ */
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v4 1/4] iio: magnetometer: ak8975: Relax failure on unknown id
Quoted 23 lines · On Fri, 23 Aug 2024 22:11:15 +0300 Andy Shevchenko…
Quoted 2 lines · Jonathan Cameron
On Mon, 19 Aug 2024 00:29:39 +0200
Barnabás Czémán <[email protected]> wrote:...
Quoted 5 lines
drivers/iio/magnetometer/ak8975.c static int ak8975_who_i_am(struct i2c_client *client, · line 490
Quoted 1 line
drivers/iio/magnetometer/ak8975.c +1
-0+/* Let driver to probe on unknown id for support more register Comment style wrong, I'll fix it up.
With that tweak applied to the togreg branch of iio.git
Quoted 7 lines
Thanks,
Jonathan
drivers/iio/magnetometer/ak8975.c static int ak8975_who_i_am(struct i2c_client *client, · line 492
Quoted 2 lines
drivers/iio/magnetometer/ak8975.c +2
-0+* compatible variants. +*/ There is another one also wrong.
Review
Quoted 4 lines
(quoted diff) +4
-0+ [AK09918] = { + /* ak09918 is register compatible with ak09912 this is for avoid + * unknown id messages. + */
I think unrelated to this series, but nice to cleanup.
Patches welcome :) Or it I get bored, I might do a scrub of the full subsystem to get everything in the same style and not provide incorrect choices to cut and paste.
Jonathan
Re: [PATCH v4 1/4] iio: magnetometer: ak8975: Relax failure on unknown id
Quoted 5 lines · Jonathan Cameron
Quoted 3 lines · On Fri, 23 Aug 2024 22:11:15 +0300 Andy Shevchenko…
Quoted 2 lines · Jonathan Cameron
On Mon, 19 Aug 2024 00:29:39 +0200
Barnabás Czémán <[email protected]> wrote:
...
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
drivers/iio/magnetometer/ak8975.c static int ak8975_who_i_am(struct i2c_client *client, · line 490
Quoted 1 line
drivers/iio/magnetometer/ak8975.c +1
-0+/* Let driver to probe on unknown id for support more register Comment style wrong, I'll fix it up.
With that tweak applied to the togreg branch of iio.git
drivers/iio/magnetometer/ak8975.c static int ak8975_who_i_am(struct i2c_client *client, · line 492
Quoted 2 lines
drivers/iio/magnetometer/ak8975.c +2
-0+* compatible variants. +*/ There is another one also wrong.
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ [AK09918] = { + /* ak09918 is register compatible with ak09912 this is for avoid + * unknown id messages. + */I think unrelated to this series, but nice to cleanup. Patches welcome :)
Sure, but I leave this to newbies to have a material to exercise on.
Quoted 2 lines
Or it I get bored, I might do a scrub of the full subsystem to get everything in the same style and not provide incorrect choices to cut and paste.
:-)
I believe we still have more interesting cases, than white space cleanups.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v4 2/4 iio: magnetometer: ak8975: Fix reading for ak099xx sensors
In reply to Barnabás CzémánMove ST2 reading with overflow handling after measurement data reading.
ST2 register read have to be read after read measurment data, because it means end of the reading and realease the lock on the data. Remove ST2 read skip on interrupt based waiting because ST2 required to be read out at and of the axis read.
--- drivers/iio/magnetometer/ak8975.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
drivers/iio/magnetometer/ak8975.c +16 -16
@@ -695,22 +695,8 @@ 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 with zero if the data is ready. */ +return !data->def->ctrl_regs[ST1_DRDY ]; }/* Retrieve raw flux value for one of the x, y, or z axis. */
@@ -737,6 +723,20 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)if (ret <0 ) goto exit; +/* Read out ST2 for release lock on measurment data. */ + 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; + } +mutex_unlock (&data->lock);pm_runtime_mark_last_busy (&data->client->dev);
Signature · 1 line
2.46.0
PATCH v4 3/4 dt-bindings: iio: magnetometer: Add ak09118
In reply to Barnabás CzémánFrom: Danila Tikhonov <[email protected]>
Document asahi-kasei,ak09918 compatible as a fallback compatible, ak09918 is register compatible with ak09912.
--- .../devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/iio/magnetometer/asahi-kasei,ak8975.yaml +4 -0
@@ -18,6 +18,10 @@ properties: - asahi-kasei,ak09911 - asahi-kasei,ak09912 - asahi-kasei,ak09916 + - items: + # ak09918 is register compatible with ak09912. + - const: asahi-kasei,ak09918 + - const: asahi-kasei,ak09912 - enum: - ak8975 - ak8963
Signature · 1 line
2.46.0
Re: [PATCH v4 3/4] dt-bindings: iio: magnetometer: Add ak09118
Quoted 7 lines · Barnabás Czémán
From: Danila Tikhonov <[email protected]>
Document asahi-kasei,ak09918 compatible as a fallback compatible, ak09918 is register compatible with ak09912.
Signed-off-by Danila Tikhonov <[email protected]>Signed-off-by Barnabás Czémán <[email protected]>
PATCH v4 4/4 iio: magnetometer: ak8975: Add AK09118 support
In reply to Barnabás CzémánFrom: Danila Tikhonov <[email protected]>
Add additional AK09118 to the magnetometer driver which has the same register mapping and scaling as the AK09112 device.
--- drivers/iio/magnetometer/Kconfig | 2 +- drivers/iio/magnetometer/ak8975.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-)
drivers/iio/magnetometer/Kconfig +1 -1
@@ -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.
drivers/iio/magnetometer/ak8975.c +37 -0
@@ -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,34 @@ static const struct ak_def ak_def_array[] = { AK09912_REG_HXL,AK09912_REG_HYL , AK09912_REG_HZL}, + }, + [AK09918 ] = { +/* ak09918 is register compatible with ak09912 this is for avoid +* unknown id messages. +*/ + .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 +482,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 +515,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 ; }dev_info (&client->dev,"Device ID %x is unknown.\n" , wia_val[1 ]);
@@ -1070,6 +1105,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);
@@ -1084,6 +1120,7 @@ static const struct of_device_id ak8975_of_match[] = { { .compatible = "asahi-kasei,ak09912", .data = &ak_def_array[AK09912] }, { .compatible = "ak09912", .data = &ak_def_array[AK09912] }, { .compatible = "asahi-kasei,ak09916", .data = &ak_def_array[AK09916] }, + { .compatible = "asahi-kasei,ak09918", .data = &ak_def_array[AK09918] }, {} };MODULE_DEVICE_TABLE (of, ak8975_of_match);
Signature · 1 line
2.46.0
Jonathan Cameron
maintainerRe: [PATCH v4 4/4] iio: magnetometer: ak8975: Add AK09118 support
Quoted 8 lines · On Mon, 19 Aug 2024 00:29:42 +0200 Barnabás Czémán…
From: Danila Tikhonov <[email protected]>
Add additional AK09118 to the magnetometer driver which has the same register mapping and scaling as the AK09112 device.
Signed-off-by Danila Tikhonov <[email protected]>Signed-off-by Barnabás Czémán <[email protected]>
Applied rest of series to the testing branch of iio.git. I'll rebase that after the pull I have outstanding is in Greg's tree and then it will become togreg and get picked up by linux-next etc.
Thanks,
Jonathan