From nobody Sat Jun 13 12:27:40 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D28033D4135; Thu, 7 May 2026 14:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164569; cv=none; b=FdDdCcjQYiD8ByqnFzK6n0vZKVtP4g3g2Ad3KqpIVT8TH3I52CsBTs1ApGX5fs1bMeV5vi9fjQ64OHG0+EnMnA+S/ogELvG9Y9TCTP7FDprIv8WBztQTmYhHDs8JVusp7GdyNnWdmLb+bfOugrIUNIMWlDk4Uns6GpAxOoFQoFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164569; c=relaxed/simple; bh=ZF583aBtYGAJpHHeB0vOg6PUeXY1blXcxWsonJHvWrk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bjTnSwrw+yQrN2sTGM0lnh9aLV/x9ga9JsvMkSjZV5B83OXTrSck2NF0X+G05ojlybi0uuRnFWM7wsqny+4U+b+Ygm07gAWNjL158wcpnCgY3AnrECeMdCUX1590ZrBkAh8zFWdpd42NDcY8Su4rJW6liWJbuV1VbW8CUTLAt6Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JlnwmEG+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JlnwmEG+" Received: by smtp.kernel.org (Postfix) with ESMTPS id 89853C2BCB8; Thu, 7 May 2026 14:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778164569; bh=ZF583aBtYGAJpHHeB0vOg6PUeXY1blXcxWsonJHvWrk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=JlnwmEG+YHBX1KfVPsg95EJulrhlgUfhJVuUsRm5w2qrvrMWZA6b5ylFXBjnuE9xp P+r0q4f7aVW/usGyB+U7D8PmWkKWMRpNuopIrBwavce+S2ADl8VP/4CHCt2Los7Bdd 5tj1HNFae/AWRDxDpvKV8q4iW7p3BOvM89NhbFHPXUnlz9X0PV5YFP1mpCO1c3MbRe CSXM513Hdq2uee3OBQ1TLDX2269WW+NMTW7Yeat9GgsG1W9O0a20BpGURwuOHYsKAt l9WPyG0No52ctRCCtEN2BDt6P7pHUBwyCz5pbeTmdXtSBIqe5Zu/KhhPT/wOdCKLDq LqW5ZHvnbo5lQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78B29CD343F; Thu, 7 May 2026 14:36:09 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 07 May 2026 16:35:50 +0200 Subject: [PATCH 1/8] iio: magnetometer: ak8975: modernize polling loops with iopoll() macros Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-magnetometer-fixes-post-pickup-v1-1-37827ca68fb3@gmail.com> References: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> In-Reply-To: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Andy Shevchenko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164567; l=2895; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=WCXc9xJK2iqHW3SXYjHYZyCyWgILLVxm1tWrHc5KDy8=; b=KT/yu5fjjyrNeElOWHTLkNmsc4iTt0YnQZ35Z9FeG8UL5kKSjI+fWKz94tpQjSNsdNtqySU/d bTC1Oa4fWF8D9LnQypLodvIkGx9QN3Me6Vx3PCYJ9//BJoSqezfafL4 X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Joshua Crofts The driver currently uses while loops and msleep() for polling during conversion waits. Replace the custom polling loops with readx_poll_timeout() and read_poll_timeout() macros from . This reduces boilerplate, standardizes timeout handling and improves overall code readability, keeping the original timing and error behaviour. Add for USEC_PER_MSEC macro instead of using magic numbers. Assisted-by: Gemini:3.1-Pro Reviewed-by: Andy Shevchenko Signed-off-by: Joshua Crofts Reviewed-by: Nuno S=C3=A1 --- drivers/iio/magnetometer/ak8975.c | 43 ++++++++++++++++-------------------= ---- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/a= k8975.c index 6be72e1cc0a8321e767da5e65d54c0fe88712304..b990c123e2808c2078abcfaf6b2= ef86c09393e6b 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include =20 @@ -649,16 +650,14 @@ static int wait_conversion_complete_gpio(struct ak897= 5_data *data, { struct i2c_client *client =3D data->client; int ret; + int val; =20 /* Wait for the conversion to complete. */ - while (timeout_ms) { - msleep(poll_ms); - if (gpiod_get_value(data->eoc_gpiod)) - break; - timeout_ms -=3D poll_ms; - } - if (!timeout_ms) - return -ETIMEDOUT; + ret =3D readx_poll_timeout(gpiod_get_value, data->eoc_gpiod, val, val != =3D 0, + poll_ms * USEC_PER_MSEC, + timeout_ms * USEC_PER_MSEC); + if (ret) + return ret; =20 ret =3D i2c_smbus_read_byte_data(client, data->def->ctrl_regs[ST1]); if (ret < 0) @@ -672,27 +671,21 @@ static int wait_conversion_complete_polled(struct ak8= 975_data *data, unsigned int timeout_ms) { struct i2c_client *client =3D data->client; - u8 read_status; int ret; + int val; =20 /* Wait for the conversion to complete. */ - while (timeout_ms) { - msleep(poll_ms); - ret =3D i2c_smbus_read_byte_data(client, - data->def->ctrl_regs[ST1]); - if (ret < 0) { - dev_err(&client->dev, "Error in reading ST1\n"); - return ret; - } - read_status =3D ret; - if (read_status) - break; - timeout_ms -=3D poll_ms; - } - if (!timeout_ms) - return -ETIMEDOUT; + ret =3D read_poll_timeout(i2c_smbus_read_byte_data, val, val !=3D 0, + poll_ms * USEC_PER_MSEC, + timeout_ms * USEC_PER_MSEC, + true, + client, data->def->ctrl_regs[ST1]); + if (ret) + return ret; + if (val < 0) + dev_err(&client->dev, "Error in reading ST1\n"); =20 - return read_status; + return val; } =20 /* Returns 0 if the end of conversion interrupt occurred or -ETIMEDOUT oth= erwise */ --=20 2.47.3 From nobody Sat Jun 13 12:27:40 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D26B13161AD; Thu, 7 May 2026 14:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164569; cv=none; b=PJivxLtuGzx9AXFJadyLaOt3pSciG19ms1pSUVjbzxcXE5ztbCNNmFv/cSQHeDKdb4/scaJIZShlTLa5s3Q76MmyXBTUcvOnCkLCjpkBX/6FVdD6hhDGf+OvqrbH++2f/qwCvqVfxv0mtPE76/SzS09YsSsJM8QHltoopmMsmbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164569; c=relaxed/simple; bh=S8zcjYqcOkQGiBJsJ14OTpfEjFyAY9C0atC0kOOLrM0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KymrVuVDJTXhRvB+KSGWUhbdvt+ZwFtpM71MKBeIj2Vz/wPsc5fSmNblKZUjhR1ZapHrfc2h0LfiiC+0gEiwWbQUaEKKqYKBl2qyW9STtY+dwilmujCRti4Fipx/7vm4PDPuSfb1GHnoOV1TJAzaa2OVwccDVzYqZZMyM06A/og= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=COOHizHZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="COOHizHZ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 999A1C2BCC4; Thu, 7 May 2026 14:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778164569; bh=S8zcjYqcOkQGiBJsJ14OTpfEjFyAY9C0atC0kOOLrM0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=COOHizHZ95C4AZcKaPv9A6I7qTbYxhtdqWJ0m4ILpvxXlVpPOl6TEYgfuiCkEzigZ HU50cCP4I8xJKqXJv/Bud6ki72wRcUPvgXx7G3aeaKxq5XNNr+sUmV1mysCaKhgekF BJ+CpmaTXEUPO0IEv+rEl0HE+t6EsaHjIh/uU4zWxO1TquynlFbJsurYNkrOR7GnnE SBS6H2acoFTDkTITC89ZteI5haGmR1HkMEV0jybD++BRCwpeo34cRlt+jZi4SpDjeE 0Rb21BtEGvCNEf/VkzXEM62DjMxKyPft7zBRGufBqEtgGT9fN6EcF/ho51pTJOMnUE WH0bEcTHeoyrw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89958CD3442; Thu, 7 May 2026 14:36:09 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 07 May 2026 16:35:51 +0200 Subject: [PATCH 2/8] iio: magnetometer: ak8975: check if gpiod read was successful Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-magnetometer-fixes-post-pickup-v1-2-37827ca68fb3@gmail.com> References: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> In-Reply-To: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164567; l=936; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=rgh2T/BraT11/1sDogsM03wH+GIDtJpudp0bLFkpppg=; b=kw14rqVLrLwHvzqYtMWqjVGldMXWJUomqSjyqG61K4vLS/7Ka67Bzq6yOzxmV41FVGQreapZV 4eV+neL0kYTBvgWhS4KY2yovbAT6BZ6w8CKaGkG41bAO9Ilred5zCCp X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Joshua Crofts Add a check that ensures that valid data has been read from GPIOD. If not, log an error and return the negative read value. Suggested-by: Jonathan Cameron Signed-off-by: Joshua Crofts Reviewed-by: Nuno S=C3=A1 --- drivers/iio/magnetometer/ak8975.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/a= k8975.c index b990c123e2808c2078abcfaf6b2ef86c09393e6b..63b6e8465f5f3873841550a1cd0= 3ce86b95d1d67 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -658,6 +658,10 @@ static int wait_conversion_complete_gpio(struct ak8975= _data *data, timeout_ms * USEC_PER_MSEC); if (ret) return ret; + if (val < 0) { + dev_err(&client->dev, "Error in reading GPIOD\n"); + return val; + } =20 ret =3D i2c_smbus_read_byte_data(client, data->def->ctrl_regs[ST1]); if (ret < 0) --=20 2.47.3 From nobody Sat Jun 13 12:27:40 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D40DF3E928B; Thu, 7 May 2026 14:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164569; cv=none; b=MYgtX6+4tFbjIW4ADrQ93Ji6xjsnSfaRbLb2Yi19X6SAvMS/PqeZBCUjRf2+xjW/PWVjiE2KLrT7a0i4Pg5jAVIGiOQGFjrGoFQLz1vtLTfKNdhSezD7THBBHed8u1jb30ilRd7qZl3D6PzIcIiB9KHKlKrj44/EEMc0A3Jxfrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164569; c=relaxed/simple; bh=bmRBrhdLyXSmDd8jabmz6shomjMBxA5X+VSR1EwvcyA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ujyxFbSG9lQPwKoOraOUWRNN1X/7Vc6O3zZYtvNHocVOdRhYQokUNMdIPpeNLApH8ByKU064soKKhWltOvxC9Bb6MZXr48jIZi74Wrhwr3hfRTwy8cuIfGDQ2CY5cTXFiX6l54TKUXCYlsBtFJdYVnNnLDJIY8Cl3F2kRqsL4ck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B8SCq0el; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="B8SCq0el" Received: by smtp.kernel.org (Postfix) with ESMTPS id A5949C2BCC9; Thu, 7 May 2026 14:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778164569; bh=bmRBrhdLyXSmDd8jabmz6shomjMBxA5X+VSR1EwvcyA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=B8SCq0elhBh1jagRrIELn+BPH1cySXObsDAne17ZroQmd+5YbesBQvlAlvDs7fFsH bNrLDcj9glkCcXpJ5in0D8HAGv+syLNUfTu5fOcEfyW8W5vtlR/evV9NpHB/lijSum +M5XUJ3DXw05ZkUUaAvmp5zlwVwprJJyvrW6kVgVfNnWozMny6+qzzLT3RaTmOuVTs hyB47Os0GP9nYI1Aty1h4d1oKKU40CbQEgX8QYH+Ecpr+L8jMq/Wk4+Ga1giMkHJfK vzCHvFnalVkOTUsPqOcxVipoaai0mfW7BbM5KIojpDSZtm8FOO39qtcILnUpC1nNNP u4R71hfBeCwxg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99AA7CD343B; Thu, 7 May 2026 14:36:09 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 07 May 2026 16:35:52 +0200 Subject: [PATCH 3/8] iio: magnetometer: ak8975: switch to using managed resources Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-magnetometer-fixes-post-pickup-v1-3-37827ca68fb3@gmail.com> References: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> In-Reply-To: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Andy Shevchenko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164567; l=4925; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=ZQ3q5iOgGVbjwOP5QsGeqqFLxDINScZT1+7U5nwxEX0=; b=/DL6EVg6+/cioIGybKNYjqjnez+CcczW9BsRx6E1GwP5Javu7teESOidyNyvih2fgP4AasrS0 ug6yAoqKs9IAUfZEOH8Gsr4ElqRqvFwaG6D9yJphkiOoQCGzyeESkWN X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Andy Shevchenko Switch the driver to use managed resources (devm_*) which simplifier error handling and allows removing ak8975_remove() method from the driver. Note, on error path we now also set mode to POWER_DOWN state which is fine. Even if the device is in that mode, there is no problem to set that mode again, it should be no-op. Additionally, remove any pm_runtime_get/put*() function calls that dummy cycled the counter to autosuspend the device. Signed-off-by: Andy Shevchenko Co-developed-by: Joshua Crofts Signed-off-by: Joshua Crofts --- drivers/iio/magnetometer/ak8975.c | 74 ++++++++++++++++++++++-------------= ---- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/a= k8975.c index 63b6e8465f5f3873841550a1cd03ce86b95d1d67..1d8f448d5179fe9b33af989cc2f= 456ac91bc2f17 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -898,9 +898,24 @@ static irqreturn_t ak8975_handle_trigger(int irq, void= *p) return IRQ_HANDLED; } =20 +static void devm_ak8975_power_off(void *data) +{ + struct ak8975_data *ak =3D data; + struct device *dev =3D &ak->client->dev; + + /* Only power down if currently active */ + if (pm_runtime_status_suspended(dev)) + return; + + /* Soft-stop the chip before hard-stopping the regulators */ + ak8975_set_mode(data, POWER_DOWN); + ak8975_power_off(data); +} + static int ak8975_probe(struct i2c_client *client) { const struct i2c_device_id *id =3D i2c_client_get_device_id(client); + struct device *dev =3D &client->dev; struct ak8975_data *data; struct iio_dev *indio_dev; struct gpio_desc *eoc_gpiod; @@ -968,10 +983,21 @@ static int ak8975_probe(struct i2c_client *client) if (ret) return ret; =20 + /* + * Set device as active early so pm_runtime_status_suspended() works + * correctly if probe fails before pm_runtime is enabled. Do not attempt + * to move this line lower. + */ + pm_runtime_set_active(dev); + + ret =3D devm_add_action_or_reset(dev, devm_ak8975_power_off, data); + if (ret) + return ret; + ret =3D ak8975_who_i_am(client, data->def->type); if (ret) { dev_err(&client->dev, "Unexpected device\n"); - goto power_off; + return ret; } dev_dbg(&client->dev, "Asahi compass chip %s\n", name); =20 @@ -979,10 +1005,13 @@ static int ak8975_probe(struct i2c_client *client) ret =3D ak8975_setup(client); if (ret) { dev_err(&client->dev, "%s initialization fails\n", name); - goto power_off; + return ret; } =20 - mutex_init(&data->lock); + ret =3D devm_mutex_init(dev, &data->lock); + if (ret) + return ret; + indio_dev->channels =3D ak8975_channels; indio_dev->num_channels =3D ARRAY_SIZE(ak8975_channels); indio_dev->info =3D &ak8975_info; @@ -990,52 +1019,32 @@ static int ak8975_probe(struct i2c_client *client) indio_dev->modes =3D INDIO_DIRECT_MODE; indio_dev->name =3D name; =20 - ret =3D iio_triggered_buffer_setup(indio_dev, NULL, ak8975_handle_trigger, - NULL); + ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, + ak8975_handle_trigger, NULL); if (ret) { dev_err(&client->dev, "triggered buffer setup failed\n"); - goto power_off; + return ret; } =20 - ret =3D iio_device_register(indio_dev); + ret =3D devm_iio_device_register(dev, indio_dev); if (ret) { dev_err(&client->dev, "device register failed\n"); - goto cleanup_buffer; + return ret; } =20 /* Enable runtime PM */ - pm_runtime_get_noresume(&client->dev); - pm_runtime_set_active(&client->dev); - pm_runtime_enable(&client->dev); + ret =3D devm_pm_runtime_enable(dev); + if (ret) + return ret; + /* * The device comes online in 500us, so add two orders of magnitude * of delay before autosuspending: 50 ms. */ pm_runtime_set_autosuspend_delay(&client->dev, 50); pm_runtime_use_autosuspend(&client->dev); - pm_runtime_put(&client->dev); =20 return 0; - -cleanup_buffer: - iio_triggered_buffer_cleanup(indio_dev); -power_off: - ak8975_power_off(data); - return ret; -} - -static void ak8975_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev =3D i2c_get_clientdata(client); - struct ak8975_data *data =3D iio_priv(indio_dev); - - pm_runtime_get_sync(&client->dev); - pm_runtime_put_noidle(&client->dev); - pm_runtime_disable(&client->dev); - iio_device_unregister(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); - ak8975_set_mode(data, POWER_DOWN); - ak8975_power_off(data); } =20 static int ak8975_runtime_suspend(struct device *dev) @@ -1129,7 +1138,6 @@ static struct i2c_driver ak8975_driver =3D { .acpi_match_table =3D ak_acpi_match, }, .probe =3D ak8975_probe, - .remove =3D ak8975_remove, .id_table =3D ak8975_id, }; module_i2c_driver(ak8975_driver); --=20 2.47.3 From nobody Sat Jun 13 12:27:40 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DABBC28313D; Thu, 7 May 2026 14:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164569; cv=none; b=L9YBGcSRcdPtKHRRk4wBmxC2YNMU2q68XBkbHqLTODwv3fY1NPMqck6TYyexoyTwjOM8ZLY09ZnbBWPfqcu/obkq5KZKY/5od1K40g9SMJOD9ctPCCLMJUa5+CNr5lXzgSsVDC7iiMt39NvZ8Hh9S8g53XFhRIVlitLo+f7b8Cs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164569; c=relaxed/simple; bh=279KTUhgYtLiCj0FjFVAREjqNaNxek4+Xr1rBsCcc1E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UkLfZhwdxIMkrpUboiDbWBOn2P6eC+vHP3ZWj6XWCdue4LLnbhUHrW1yQX20sH2BTtaLtJh8YNcjvgQrn2lFMBY7Dq4CTzgdZQg7PwIkJBw8B8WV/zYP0NLrtSeLC/2REoMinB7jUbvpbb06jPBq9/5GUXJPUjOETFJAC3Kk/ng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ovhCvQHT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ovhCvQHT" Received: by smtp.kernel.org (Postfix) with ESMTPS id B3DF2C2BCF6; Thu, 7 May 2026 14:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778164569; bh=279KTUhgYtLiCj0FjFVAREjqNaNxek4+Xr1rBsCcc1E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ovhCvQHTqLKdH1qUSEoWnZalI+P1X0lROi1byfDlMQDf26S1g3NFxTpzfk4keclhV 6WxBV4hbbcBSp9r6dP+XthKXvNW2mUMZrn3/h1ZBFMr+Ti1hnvsb74wH2Wtz31n/Es khEeI+gZWf/0In0SsX2LTh51JVlQ2VvltzQb2wA57uaRsNkFmevWkW0nhfcOc5j8Nj X/fK7IA+APS2Ue0ndiIxTe3zW0lyQOcpx5A4Qlb/qcHh5tgeUX2rF/mvSzDvvCcLqt puOxSFEdNwttHT42aeU1oMFtZGymDWz1JIkyKFVoa5YCke+eDmZE7m0JVmWH6EYyIF LFrbsxBm0I0Ng== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC2ADCD3444; Thu, 7 May 2026 14:36:09 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 07 May 2026 16:35:53 +0200 Subject: [PATCH 4/8] iio: magnetometer: ak8975: consistently use 'data' parameter Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-magnetometer-fixes-post-pickup-v1-4-37827ca68fb3@gmail.com> References: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> In-Reply-To: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Andy Shevchenko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164567; l=3366; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=aBXD1UqgNsG/B0TM6+2/HkyCvJBTEDR+pG1fondDO7Q=; b=7I1UR1HjOTylM2/T4A2ng3AWxqNThhbNwHMvWaRpVC9412OG5O3CH33YiXTFWuPx5ATLrC8eI wfWthoukwVdAX6Soq7PbssMICCte6ZwlLpPa/CNfjShR6hpCb0cvx/9 X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Andy Shevchenko Some of the functions use 'client', some use 'data', and some use both. Refactor the driver to consistently use 'data' in all cases. Signed-off-by: Andy Shevchenko Signed-off-by: Joshua Crofts Reviewed-by: Nuno S=C3=A1 --- drivers/iio/magnetometer/ak8975.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/a= k8975.c index 1d8f448d5179fe9b33af989cc2f456ac91bc2f17..e575d252076acc3639cfbb718a7= 6811636fe56d2 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -474,9 +474,10 @@ static void ak8975_power_off(const struct ak8975_data = *data) * Return 0 if the i2c device is the one we expect. * return a negative error number otherwise */ -static int ak8975_who_i_am(struct i2c_client *client, +static int ak8975_who_i_am(const struct ak8975_data *data, enum asahi_compass_chipset type) { + struct i2c_client *client =3D data->client; u8 wia_val[2]; int ret; =20 @@ -598,10 +599,9 @@ static int ak8975_setup_irq(struct ak8975_data *data) * Perform some start-of-day setup, including reading the asa calibration * values and caching them. */ -static int ak8975_setup(struct i2c_client *client) +static int ak8975_setup(struct ak8975_data *data) { - struct iio_dev *indio_dev =3D i2c_get_clientdata(client); - struct ak8975_data *data =3D iio_priv(indio_dev); + struct i2c_client *client =3D data->client; int ret; =20 /* Write the fused rom access mode. */ @@ -706,12 +706,13 @@ static int wait_conversion_complete_interrupt(struct = ak8975_data *data, return ret > 0 ? 0 : -ETIMEDOUT; } =20 -static int ak8975_start_read_axis(struct ak8975_data *data, - const struct i2c_client *client) +static int ak8975_start_read_axis(struct ak8975_data *data) { - /* Set up the device for taking a sample. */ - int ret =3D ak8975_set_mode(data, MODE_ONCE); + struct i2c_client *client =3D data->client; + int ret; =20 + /* Set up the device for taking a sample. */ + ret =3D ak8975_set_mode(data, MODE_ONCE); if (ret < 0) { dev_err(&client->dev, "Error in setting operating mode\n"); return ret; @@ -744,7 +745,7 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, = int index, int *val) =20 mutex_lock(&data->lock); =20 - ret =3D ak8975_start_read_axis(data, client); + ret =3D ak8975_start_read_axis(data); if (ret) goto exit; =20 @@ -856,7 +857,7 @@ static void ak8975_fill_buffer(struct iio_dev *indio_de= v) =20 mutex_lock(&data->lock); =20 - ret =3D ak8975_start_read_axis(data, client); + ret =3D ak8975_start_read_axis(data); if (ret) goto unlock; =20 @@ -994,7 +995,7 @@ static int ak8975_probe(struct i2c_client *client) if (ret) return ret; =20 - ret =3D ak8975_who_i_am(client, data->def->type); + ret =3D ak8975_who_i_am(data, data->def->type); if (ret) { dev_err(&client->dev, "Unexpected device\n"); return ret; @@ -1002,7 +1003,7 @@ static int ak8975_probe(struct i2c_client *client) dev_dbg(&client->dev, "Asahi compass chip %s\n", name); =20 /* Perform some basic start-of-day setup of the device. */ - ret =3D ak8975_setup(client); + ret =3D ak8975_setup(data); if (ret) { dev_err(&client->dev, "%s initialization fails\n", name); return ret; --=20 2.47.3 From nobody Sat Jun 13 12:27:40 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10D9A402B8B; Thu, 7 May 2026 14:36:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164570; cv=none; b=t1Eptjab0lrRj05shqnWy3xYlUD0YvYQUjY68JLbSPI4UTX/C2MyTOQi95bEITg0FDr3P7SwNkfwHLVMivqvGEfwbs0lzvgkCvyYJt15sA9w/9ZUL5u6Xn0qqQ+BtX0RI8S6icNBJINannI/QeSfeNfLsQOr1dXHJ9gSlT6x4uc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164570; c=relaxed/simple; bh=BAgldrNgFqY/UdPfT4z464ow+eRyyMd2E/es+wb04tU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V+Xd5OzI1L/r3RG2gz9CpdR31ZCX6NHq3wjCOVfu57mC7XdlA+323U9naEDSQ10ueonUtfI4YfozKUDyX+vArZeQfb/h5evAwIk2rjHiMn6lT3oGH6RVAcdyvEoF0fMsIAYHGlmOOjbGDo69YPmGll3/pgH2L3US5YGALM2VwTg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nkYWBmfM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nkYWBmfM" Received: by smtp.kernel.org (Postfix) with ESMTPS id C3EF3C2BCFF; Thu, 7 May 2026 14:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778164569; bh=BAgldrNgFqY/UdPfT4z464ow+eRyyMd2E/es+wb04tU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=nkYWBmfM0P/7RuNeiqFrE+YbKpUNfwHQJT0VtsQdBw2568hT5e1JGjx2otfE08hpb vgI9VMNk1B87dn5KHX5suiOvHBKl4xF0JcxHMVZjmZHMbE8azxFq8z18s+E/uccOST /B/fzCPw6Bcenvuy/mu9fbRH/kPPxn53j3Q55czQ27MdMiqi6Gwh261Kr8k/ROCesK AC/X818CR5p4H0Dkrx9JjmcIru0nyLh9KzJFN++fRzD0XcVD9QyXQmPioy/7azYu3E tpR0C/iTXh659R75qhMx1VJzPqW7W5/M6PzO2kw7XA1xaZroucw0bMmu5ZO27YBR1y WhVNhaaX6aFEA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD5AFCD343B; Thu, 7 May 2026 14:36:09 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 07 May 2026 16:35:54 +0200 Subject: [PATCH 5/8] iio: magnetometer: ak8975: unify messages with help of dev_err_probe() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-magnetometer-fixes-post-pickup-v1-5-37827ca68fb3@gmail.com> References: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> In-Reply-To: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Andy Shevchenko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164567; l=2364; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=DwBNoYdjw+pyVB4LkpMEXnJ7TcOCwJnLd6lf/i0u+OA=; b=nAmRauS1RnRKE50OlR+YmyWxpM3nnI/LzHGTVVvMOUcJma4zqPNEWddZGdrVPDxLj09ES8yGn PtUdwzHSm1mAe1/K5b31LeFnKA1Kc3npKZu6nNTqJbvdXxxhKTovF3/ X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Andy Shevchenko Unify error messages that might appear during probe phase by switching to use dev_err_probe(). Signed-off-by: Andy Shevchenko Signed-off-by: Joshua Crofts Reviewed-by: Nuno S=C3=A1 --- drivers/iio/magnetometer/ak8975.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/a= k8975.c index e575d252076acc3639cfbb718a76811636fe56d2..394f930b862e82fd41c02d81bc6= fdb3cfc8b729f 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -495,10 +495,8 @@ static int ak8975_who_i_am(const struct ak8975_data *d= ata, AK09912_REG_WIA1, sizeof(wia_val), wia_val); - if (ret < 0) { - dev_err(&client->dev, "Error reading WIA\n"); - return ret; - } + if (ret < 0) + return dev_err_probe(&client->dev, ret, "Error reading WIA\n"); =20 if (wia_val[0] !=3D AK8975_DEVICE_ID) return -ENODEV; @@ -996,18 +994,14 @@ static int ak8975_probe(struct i2c_client *client) return ret; =20 ret =3D ak8975_who_i_am(data, data->def->type); - if (ret) { - dev_err(&client->dev, "Unexpected device\n"); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, "Unexpected device\n"); dev_dbg(&client->dev, "Asahi compass chip %s\n", name); =20 /* Perform some basic start-of-day setup of the device. */ ret =3D ak8975_setup(data); - if (ret) { - dev_err(&client->dev, "%s initialization fails\n", name); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, "%s initialization fails\n", name); =20 ret =3D devm_mutex_init(dev, &data->lock); if (ret) @@ -1022,16 +1016,12 @@ static int ak8975_probe(struct i2c_client *client) =20 ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, ak8975_handle_trigger, NULL); - if (ret) { - dev_err(&client->dev, "triggered buffer setup failed\n"); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, "triggered buffer setup failed\n"); =20 ret =3D devm_iio_device_register(dev, indio_dev); - if (ret) { - dev_err(&client->dev, "device register failed\n"); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, "device register failed\n"); =20 /* Enable runtime PM */ ret =3D devm_pm_runtime_enable(dev); --=20 2.47.3 From nobody Sat Jun 13 12:27:40 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 183DB402BA4; Thu, 7 May 2026 14:36:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164570; cv=none; b=YT6LfZRlznCyGVAvgDn7TRE2F6aEwQlMjNbUk7Nnzp93hP5gidm/rClQXxdI8gbt3KaoL6Tgn/Qn6qR/pRuBiXqGX/O3pR0Seah3YqxpDOOFY4OizQNmZc2pua4vXlB0F/+lrtF9qxFcYe+Rn6tUC2vZ//tSPcAMrkEwBK1jV40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164570; c=relaxed/simple; bh=5sywxvSW6c7wmNm9dtBEKxaHHa0nW9q/ohzcmqXmxZk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Uu7UZpNwDi+nM94l+r9Bsojyenv6qFa0ONG2yTKtgRBoD6+F2zLh22Y2woz014cQFOtZxz8PpLiP5RWAD6s4zwrPxiV/wlAY3x7zJp1i6evG4kjoIR6aQtHOBCCOTy0X83MxfsvBjFV9LdicJPypDugyIA7rn1UDFPLI3FW514M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KlO2qdL2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KlO2qdL2" Received: by smtp.kernel.org (Postfix) with ESMTPS id EBEB5C2BCFC; Thu, 7 May 2026 14:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778164570; bh=5sywxvSW6c7wmNm9dtBEKxaHHa0nW9q/ohzcmqXmxZk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=KlO2qdL2xfsQjmqxRZipLDacikTIfQEj90Il5iHxo6XBZvXX9iWEaaNBnhgoO3IqL d6wM0Ch9gbMAHbMdmHxGldKY+UFo0ztFPOmyiDSjGQGd/oiDsaAxry38wE9/vGjelE 1fp5p40T6DN2/EZjixFd4LhwqPlG9JQyXkJHwIzsngmhHuOlXX0TqsT8BX9VhvfbQo WNnFWPAn3U3WD02y+3/6ozWx57RrP7VQo+fwNu+07L8Z4g8Af4mk8MwUZglWnDUBlR tt5C2aUJm23lLVG1MM1vPiGqrLaCls8FOSyU90wqQFzbJEmcBPqX8H1FnEYOwkntTZ PjRZERUckk6Ig== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1003CD3439; Thu, 7 May 2026 14:36:09 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 07 May 2026 16:35:55 +0200 Subject: [PATCH 6/8] iio: magnetometer: ak8975: use temporary variable for struct device Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-magnetometer-fixes-post-pickup-v1-6-37827ca68fb3@gmail.com> References: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> In-Reply-To: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Andy Shevchenko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164567; l=8247; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=ko3JPxFTdhLs//ra9EADR2+ynHyGp5idcwI3tsudOYk=; b=zUbfpYlZsvhUpoN+k2Ieab1Qyvn1U0UV0S3bJXANc3f8dsztTMjkHovKFh8mPY3xEslPWciSv DjW4+IkKJB/Csx7eO74s0/TWUIXCRknurCvh3L+5ZbEVATGyC+xvNzM X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Andy Shevchenko Use temporary variable for struct device to make code neater. Signed-off-by: Andy Shevchenko Signed-off-by: Joshua Crofts Reviewed-by: Nuno S=C3=A1 --- drivers/iio/magnetometer/ak8975.c | 63 +++++++++++++++++++----------------= ---- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/a= k8975.c index 394f930b862e82fd41c02d81bc6fdb3cfc8b729f..fde37cdcdd053bde1630c2f73ab= 717f9d008e2fa 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -433,18 +433,17 @@ struct ak8975_data { /* Enable attached power regulator if any. */ static int ak8975_power_on(const struct ak8975_data *data) { + struct device *dev =3D &data->client->dev; int ret; =20 ret =3D regulator_enable(data->vdd); if (ret) { - dev_warn(&data->client->dev, - "Failed to enable specified Vdd supply\n"); + dev_warn(dev, "Failed to enable specified Vdd supply\n"); return ret; } ret =3D regulator_enable(data->vid); if (ret) { - dev_warn(&data->client->dev, - "Failed to enable specified Vid supply\n"); + dev_warn(dev, "Failed to enable specified Vid supply\n"); regulator_disable(data->vdd); return ret; } @@ -572,6 +571,7 @@ static irqreturn_t ak8975_irq_handler(int irq, void *da= ta) static int ak8975_setup_irq(struct ak8975_data *data) { struct i2c_client *client =3D data->client; + struct device *dev =3D &client->dev; int irq; int ret; =20 @@ -582,9 +582,8 @@ static int ak8975_setup_irq(struct ak8975_data *data) else irq =3D gpiod_to_irq(data->eoc_gpiod); =20 - ret =3D devm_request_irq(&client->dev, irq, ak8975_irq_handler, - IRQF_TRIGGER_RISING, - dev_name(&client->dev), data); + ret =3D devm_request_irq(dev, irq, ak8975_irq_handler, IRQF_TRIGGER_RISIN= G, + dev_name(dev), data); if (ret) return ret; =20 @@ -600,12 +599,13 @@ static int ak8975_setup_irq(struct ak8975_data *data) static int ak8975_setup(struct ak8975_data *data) { struct i2c_client *client =3D data->client; + struct device *dev =3D &client->dev; int ret; =20 /* Write the fused rom access mode. */ ret =3D ak8975_set_mode(data, FUSE_ROM); if (ret < 0) { - dev_err(&client->dev, "Error in setting fuse access mode\n"); + dev_err(dev, "Error in setting fuse access mode\n"); return ret; } =20 @@ -615,22 +615,21 @@ static int ak8975_setup(struct ak8975_data *data) sizeof(data->asa), data->asa); if (ret < 0) { - dev_err(&client->dev, "Not able to read asa data\n"); + dev_err(dev, "Not able to read asa data\n"); return ret; } =20 /* After reading fuse ROM data set power-down mode */ ret =3D ak8975_set_mode(data, POWER_DOWN); if (ret < 0) { - dev_err(&client->dev, "Error in setting power-down mode\n"); + dev_err(dev, "Error in setting power-down mode\n"); return ret; } =20 if (data->eoc_gpiod || client->irq > 0) { ret =3D ak8975_setup_irq(data); if (ret < 0) { - dev_err(&client->dev, - "Error setting data ready interrupt\n"); + dev_err(dev, "Error setting data ready interrupt\n"); return ret; } } @@ -736,10 +735,11 @@ static int ak8975_read_axis(struct iio_dev *indio_dev= , int index, int *val) struct ak8975_data *data =3D iio_priv(indio_dev); const struct i2c_client *client =3D data->client; const struct ak_def *def =3D data->def; + struct device *dev =3D &data->client->dev; __le16 rval; int ret; =20 - pm_runtime_get_sync(&data->client->dev); + pm_runtime_get_sync(dev); =20 mutex_lock(&data->lock); =20 @@ -757,20 +757,20 @@ static int ak8975_read_axis(struct iio_dev *indio_dev= , int index, int *val) /* Read out ST2 for release lock on measurement data. */ ret =3D i2c_smbus_read_byte_data(client, data->def->ctrl_regs[ST2]); if (ret < 0) { - dev_err(&client->dev, "Error in reading ST2\n"); + dev_err(dev, "Error in reading ST2\n"); goto exit; } =20 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); + dev_err(dev, "ST2 status error 0x%x\n", ret); ret =3D -EINVAL; goto exit; } =20 mutex_unlock(&data->lock); =20 - pm_runtime_put_autosuspend(&data->client->dev); + pm_runtime_put_autosuspend(dev); =20 /* Swap bytes and convert to valid range. */ *val =3D clamp_t(s16, le16_to_cpu(rval), -def->range, def->range); @@ -779,8 +779,8 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, = int index, int *val) =20 exit: mutex_unlock(&data->lock); - pm_runtime_put_autosuspend(&data->client->dev); - dev_err(&client->dev, "Error in reading axis\n"); + pm_runtime_put_autosuspend(dev); + dev_err(dev, "Error in reading axis\n"); return ret; } =20 @@ -927,7 +927,7 @@ static int ak8975_probe(struct i2c_client *client) * We may not have a GPIO based IRQ to scan, that is fine, we will * poll if so. */ - eoc_gpiod =3D devm_gpiod_get_optional(&client->dev, NULL, GPIOD_IN); + eoc_gpiod =3D devm_gpiod_get_optional(dev, NULL, GPIOD_IN); if (IS_ERR(eoc_gpiod)) return PTR_ERR(eoc_gpiod); gpiod_set_consumer_name(eoc_gpiod, "ak_8975"); @@ -937,13 +937,12 @@ static int ak8975_probe(struct i2c_client *client) * deassert reset on ak8975_power_on() and assert reset on * ak8975_power_off(). */ - reset_gpiod =3D devm_gpiod_get_optional(&client->dev, - "reset", GPIOD_OUT_HIGH); + reset_gpiod =3D devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(reset_gpiod)) return PTR_ERR(reset_gpiod); =20 /* Register with IIO */ - indio_dev =3D devm_iio_device_alloc(&client->dev, sizeof(*data)); + indio_dev =3D devm_iio_device_alloc(dev, sizeof(*data)); if (indio_dev =3D=3D NULL) return -ENOMEM; =20 @@ -955,7 +954,7 @@ static int ak8975_probe(struct i2c_client *client) data->reset_gpiod =3D reset_gpiod; data->eoc_irq =3D 0; =20 - ret =3D iio_read_mount_matrix(&client->dev, &data->orientation); + ret =3D iio_read_mount_matrix(dev, &data->orientation); if (ret) return ret; =20 @@ -965,16 +964,16 @@ static int ak8975_probe(struct i2c_client *client) return -ENODEV; =20 /* If enumerated via firmware node, fix the ABI */ - if (dev_fwnode(&client->dev)) - name =3D dev_name(&client->dev); + if (dev_fwnode(dev)) + name =3D dev_name(dev); else name =3D id->name; =20 /* Fetch the regulators */ - data->vdd =3D devm_regulator_get(&client->dev, "vdd"); + data->vdd =3D devm_regulator_get(dev, "vdd"); if (IS_ERR(data->vdd)) return PTR_ERR(data->vdd); - data->vid =3D devm_regulator_get(&client->dev, "vid"); + data->vid =3D devm_regulator_get(dev, "vid"); if (IS_ERR(data->vid)) return PTR_ERR(data->vid); =20 @@ -996,7 +995,7 @@ static int ak8975_probe(struct i2c_client *client) ret =3D ak8975_who_i_am(data, data->def->type); if (ret) return dev_err_probe(dev, ret, "Unexpected device\n"); - dev_dbg(&client->dev, "Asahi compass chip %s\n", name); + dev_dbg(dev, "Asahi compass chip %s\n", name); =20 /* Perform some basic start-of-day setup of the device. */ ret =3D ak8975_setup(data); @@ -1032,8 +1031,8 @@ static int ak8975_probe(struct i2c_client *client) * The device comes online in 500us, so add two orders of magnitude * of delay before autosuspending: 50 ms. */ - pm_runtime_set_autosuspend_delay(&client->dev, 50); - pm_runtime_use_autosuspend(&client->dev); + pm_runtime_set_autosuspend_delay(dev, 50); + pm_runtime_use_autosuspend(dev); =20 return 0; } @@ -1048,7 +1047,7 @@ static int ak8975_runtime_suspend(struct device *dev) /* Set the device in power down if it wasn't already */ ret =3D ak8975_set_mode(data, POWER_DOWN); if (ret < 0) { - dev_err(&client->dev, "Error in setting power-down mode\n"); + dev_err(dev, "Error in setting power-down mode\n"); return ret; } /* Next cut the regulators */ @@ -1072,7 +1071,7 @@ static int ak8975_runtime_resume(struct device *dev) */ ret =3D ak8975_set_mode(data, POWER_DOWN); if (ret < 0) { - dev_err(&client->dev, "Error in setting power-down mode\n"); + dev_err(dev, "Error in setting power-down mode\n"); return ret; } =20 --=20 2.47.3 From nobody Sat Jun 13 12:27:40 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18317402B9B; Thu, 7 May 2026 14:36:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164570; cv=none; b=i9qihjz3Y7hqlXT5jiZ3zoSR9Fo4TC4M7zmui+3VHO72EtamscNWU0kLZPL9v1NTCS6mwW+gkqUznBZHHDlnPHRJp64Qmh4fgc1qQkfts26Bg6MnxIpYLykwLOIWpGUr4e4eB6mF9z0E17iOluUgqYGJ77VOcEEnX3jxe9HVVng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164570; c=relaxed/simple; bh=Dd/KxItWicMwbCV2zwSOzcxMY1WSyk6AKUH/IWkhgmI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZyLNVbrSMs5wEOs+EMR4gD1769oa2VcV61RIiIw62FAQVlCCmUNReyjyM7ip+3Z8ouc239RTxY4jG1HSGK7CB9RZqP5NeVC5OdNDN1GcFuleiAkuMEspTV5t+islJnxT0IOsaryjCbsi8l82n6jp/BWgsDilIYKc66hzqYSvJ1A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Rzjslhkk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Rzjslhkk" Received: by smtp.kernel.org (Postfix) with ESMTPS id EB9EBC2BCFB; Thu, 7 May 2026 14:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778164570; bh=Dd/KxItWicMwbCV2zwSOzcxMY1WSyk6AKUH/IWkhgmI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=RzjslhkkLMk2O0ZHSHMIbjbZV+j888Bg/GmWEbB9UBhAMVkyhdzGqgGmSEaIgJahD ZocPsCzQq8cgNTw/fgH0mAkVBKEiUB3Y6Gx+84E7PVQQCS6urzV8+bXYUzCKZZ9Yw5 zkaWSP85l/s5CI650m2seU14IZR/Zupbm2tK/voMttjqg7lcFC0WBlrY9zU+fBWRA/ KXesSrcVGsXRqXV+h5q53SPSrUzNn94iRWer8r0t13XQfF7Yh1+KrDKE7ptBiJTwfl JuR8gD0UXFN4+DGXvA4PTp7i86D/vxPmBwxKPDX8qCohQoPqn6Vsj1YYcPSivmal9R MtOsK6tXcHagg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3EFFCD3442; Thu, 7 May 2026 14:36:09 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 07 May 2026 16:35:56 +0200 Subject: [PATCH 7/8] iio: magnetometer: ak8975: add scan mask index enum Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-magnetometer-fixes-post-pickup-v1-7-37827ca68fb3@gmail.com> References: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> In-Reply-To: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164567; l=1542; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=45ZXc1YiNJiCl0IL+yOuRiuQft1seVNg1PtV4bx1wjw=; b=8if4tekMMBmxdS45/1kZMsaz9PNGpZ4IwbBFvguwm8eckjlgxKrn0F1iFIQkuWJYsWZ06o7BP eIZ1VOF/jhgDoo7zUAfIZve4uG274J4PRMDbYEX83yoOLUUY+L+bxR+ X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Joshua Crofts Add an enum to explicitly define scan mask indexes for the X, Y, Z and timestamp channels. Also, update the struct iio_chan_spec to use said enum for the .scan_index parameter. This prevents magic numbers from obscuring the hardware channel mapping and improves code style. No functional change. Suggested-by: Jonathan Cameron Signed-off-by: Joshua Crofts Reviewed-by: Nuno S=C3=A1 --- drivers/iio/magnetometer/ak8975.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/a= k8975.c index fde37cdcdd053bde1630c2f73ab717f9d008e2fa..d11f025e146d098508f35ef31c1= ccad544612535 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -238,6 +238,13 @@ enum ak_ctrl_mode { MODE_END, }; =20 +enum ak_scan_index { + AK8975_SCAN_X, + AK8975_SCAN_Y, + AK8975_SCAN_Z, + AK8975_SCAN_TS, +}; + struct ak_def { enum asahi_compass_chipset type; long (*raw_to_gauss)(u16 data); @@ -835,8 +842,10 @@ static const struct iio_chan_spec_ext_info ak8975_ext_= info[] =3D { } =20 static const struct iio_chan_spec ak8975_channels[] =3D { - AK8975_CHANNEL(X, 0), AK8975_CHANNEL(Y, 1), AK8975_CHANNEL(Z, 2), - IIO_CHAN_SOFT_TIMESTAMP(3), + AK8975_CHANNEL(X, AK8975_SCAN_X), + AK8975_CHANNEL(Y, AK8975_SCAN_Y), + AK8975_CHANNEL(Z, AK8975_SCAN_Z), + IIO_CHAN_SOFT_TIMESTAMP(AK8975_SCAN_TS), }; =20 static const unsigned long ak8975_scan_masks[] =3D { 0x7, 0 }; --=20 2.47.3 From nobody Sat Jun 13 12:27:40 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DADB40627F; Thu, 7 May 2026 14:36:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164570; cv=none; b=OPS2jJ9PiXEYakLpPghJZADGAyX9y85J0XtyUFMaezUCD4XHLbJAa0C7HLMCZZZuHEwOwKHsu2Iegu7bMDMMbTo56lqXE1WP17siP6VoXxWXRNOV3u7in3RsIrlK+aXA85MqYXnr64CdoZHRTVNHxeGSMFUoieZHd0pv1l2t3VQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778164570; c=relaxed/simple; bh=Unp1dH41/zoQZrljdPrJE9WyZVlWutvMQmiybWJnPfE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Tre1VKJgLu7r0dJ3Cw2CdzGALtlO8kKCpQdHSR0lIei0yKKZhJ/C6ZAJu9oJie+ld96ujhUK2so/cgsXsD2STGsj4lFvJxLB0JBNuz5EVcmw12ILU6u+a93Va2oAsyJJt9/m6J6Uk7IbmaBgkgxoD1RQ5Dzk0K4dsV8TJ5ENJNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X5c25uBr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X5c25uBr" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0AD58C2BCB2; Thu, 7 May 2026 14:36:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778164570; bh=Unp1dH41/zoQZrljdPrJE9WyZVlWutvMQmiybWJnPfE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=X5c25uBrMw453ICHHIBA6X87JQ5mCOhbZA+m3eVxhZs3ZSVyDHUTe5AlnCZmxnMyy 3757pl7bv4+maKaFLyzNdpFDOG1z9soqlAog4Vei3ZBFD43y8iSkB1Z8Wqt/YJHoQY KwjYVmETSthpr1+MsRUO3680WRR4XCo7aGdAfCX5YD7+n+mNdqXOdytrBXsiHXf9BM FkOxhczCI1Gt+41RqZuJ1w7zZua170KTbW3v/m3LijT9S8nloD2QGTJcDs8VRsCYoO HrU0LVQKQyAuBWCGk/uYz+lbrRuDg0FyCNZr2wm0ZHaG2A9OimByXAkuaY4SDrxGNk YOTycK7Nd+b0w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02427CD343F; Thu, 7 May 2026 14:36:10 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Thu, 07 May 2026 16:35:57 +0200 Subject: [PATCH 8/8] iio: magnetometer: ak8975: make use of the macros from bits.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-magnetometer-fixes-post-pickup-v1-8-37827ca68fb3@gmail.com> References: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> In-Reply-To: <20260507-magnetometer-fixes-post-pickup-v1-0-37827ca68fb3@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Andy Shevchenko X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778164567; l=3026; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=uSqUkNKA96dxORbdKRT87CB6VtK79Lmf39ap3WDBEeU=; b=qD/2bhyCsROnAtQrqwOMwyy58y58ehGB9jrvSyCqxQJFaUn9qL/7hCq16zSM7x/keSTvk6ozU YGMgB2t93TEDn41b7elkUpHH9QHFMv/g1Zl4pOT8xlMJhQTkX+GWFyF X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Andy Shevchenko Make use of BIT() and GENMASK() where it makes sense. Signed-off-by: Andy Shevchenko Co-developed-by: Joshua Crofts Signed-off-by: Joshua Crofts Reviewed-by: Nuno S=C3=A1 --- drivers/iio/magnetometer/ak8975.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/a= k8975.c index d11f025e146d098508f35ef31c1ccad544612535..d8d9f706f96bae3be19e8db17b9= 473e6e0eef4fc 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -45,8 +45,7 @@ #define AK8975_REG_INFO 0x01 =20 #define AK8975_REG_ST1 0x02 -#define AK8975_REG_ST1_DRDY_SHIFT 0 -#define AK8975_REG_ST1_DRDY_MASK (1 << AK8975_REG_ST1_DRDY_SHIFT) +#define AK8975_REG_ST1_DRDY_MASK BIT(0) =20 #define AK8975_REG_HXL 0x03 #define AK8975_REG_HXH 0x04 @@ -55,15 +54,12 @@ #define AK8975_REG_HZL 0x07 #define AK8975_REG_HZH 0x08 #define AK8975_REG_ST2 0x09 -#define AK8975_REG_ST2_DERR_SHIFT 2 -#define AK8975_REG_ST2_DERR_MASK (1 << AK8975_REG_ST2_DERR_SHIFT) +#define AK8975_REG_ST2_DERR_MASK BIT(2) =20 -#define AK8975_REG_ST2_HOFL_SHIFT 3 -#define AK8975_REG_ST2_HOFL_MASK (1 << AK8975_REG_ST2_HOFL_SHIFT) +#define AK8975_REG_ST2_HOFL_MASK BIT(3) =20 #define AK8975_REG_CNTL 0x0A -#define AK8975_REG_CNTL_MODE_SHIFT 0 -#define AK8975_REG_CNTL_MODE_MASK (0xF << AK8975_REG_CNTL_MODE_SHIFT) +#define AK8975_REG_CNTL_MODE_MASK GENMASK(3, 0) #define AK8975_REG_CNTL_MODE_POWER_DOWN 0x00 #define AK8975_REG_CNTL_MODE_ONCE 0x01 #define AK8975_REG_CNTL_MODE_SELF_TEST 0x08 @@ -95,8 +91,7 @@ =20 #define AK09912_REG_ST1 0x10 =20 -#define AK09912_REG_ST1_DRDY_SHIFT 0 -#define AK09912_REG_ST1_DRDY_MASK (1 << AK09912_REG_ST1_DRDY_SHIFT) +#define AK09912_REG_ST1_DRDY_MASK BIT(0) =20 #define AK09912_REG_HXL 0x11 #define AK09912_REG_HXH 0x12 @@ -107,8 +102,7 @@ #define AK09912_REG_TMPS 0x17 =20 #define AK09912_REG_ST2 0x18 -#define AK09912_REG_ST2_HOFL_SHIFT 3 -#define AK09912_REG_ST2_HOFL_MASK (1 << AK09912_REG_ST2_HOFL_SHIFT) +#define AK09912_REG_ST2_HOFL_MASK BIT(3) =20 #define AK09912_REG_CNTL1 0x30 =20 @@ -117,8 +111,7 @@ #define AK09912_REG_CNTL_MODE_ONCE 0x01 #define AK09912_REG_CNTL_MODE_SELF_TEST 0x10 #define AK09912_REG_CNTL_MODE_FUSE_ROM 0x1F -#define AK09912_REG_CNTL2_MODE_SHIFT 0 -#define AK09912_REG_CNTL2_MODE_MASK (0x1F << AK09912_REG_CNTL2_MODE_SHIFT) +#define AK09912_REG_CNTL2_MODE_MASK GENMASK(4, 0) =20 #define AK09912_REG_CNTL3 0x32 =20 @@ -848,7 +841,10 @@ static const struct iio_chan_spec ak8975_channels[] = =3D { IIO_CHAN_SOFT_TIMESTAMP(AK8975_SCAN_TS), }; =20 -static const unsigned long ak8975_scan_masks[] =3D { 0x7, 0 }; +static const unsigned long ak8975_scan_masks[] =3D { + BIT(AK8975_SCAN_X) | BIT(AK8975_SCAN_Y) | BIT(AK8975_SCAN_Z), + 0 +}; =20 static const struct iio_info ak8975_info =3D { .read_raw =3D &ak8975_read_raw, --=20 2.47.3