From patchwork Wed Apr 2 19:33:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036416 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 BE7F718E03A; Wed, 2 Apr 2025 19:33:32 +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=1743622412; cv=none; b=Ld3lKS2WXBpMgkpqH+e3fXbqOqiMA4pYxX6Eqc/ThkJ/7Ves2nZ1s4gO3ET7E9x3n7NOjKGXKKcujlep5S6v4dmjYm2y9h4XgJqA7DHYwV8KLtI6gi9TxQKF7bnutf9NEs3xehuLXk9QZn70qUmpkd6n2vTP2RLdbYziyKl0VYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743622412; c=relaxed/simple; bh=VsE3WyyxL4Exi7V542Px7+JjGuyH9uxuRIQpC16XC04=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JwRXZcb2jMqHECfbCaMMcc+pJVB6Pg3wVcTqV8sqJ/XDHdza5GM04a3npk4JtOQ6jt5oZO0nuS1I1DsGqwvLOq2AI/GjUKUWEmU/TgzEcv08ARTgaNOYp4TvTmqBAvODx9Tmt+Su9v2tHzy8Kl/kg01TH8V+3b4w2fltzEkUW9k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YUepaOhy; 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="YUepaOhy" Received: by smtp.kernel.org (Postfix) with ESMTPS id 32585C4CEE8; Wed, 2 Apr 2025 19:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743622412; bh=VsE3WyyxL4Exi7V542Px7+JjGuyH9uxuRIQpC16XC04=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=YUepaOhyDFJgQj+GN1fqP0qmAPyQi9SrgQUA0KNq/DzSVGsp7kZ0y1z0mZ+g1dNkH hxsWWjEiKqABu3nrZs6/LEsULX8IDav+ObeG81vHk0JVFolZ49hmyiJmJACNV8W4o0 MFmw6+OKw6ELcnuJ1eDSVK2fO4raI9tZCnK/GrismVb7oa0u2GBayEAsGi+Pn1aWjB qvmTxCA+lalOYlAlzVaZ0ZGEB5GSJBwbLQHuIBLoCADq66dzQZLjJ3UC7CnKHXt4AU +avQ36qIgcr/K+5sUAQX3tV+LIZr9krT4ma9ZX996uIAnqx1eXbjDfwS8l8q8IS4yK 5a8wepwhT9vPg== 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 1932BC3601B; Wed, 2 Apr 2025 19:33:32 +0000 (UTC) Date: Wed, 02 Apr 2025 21:33:24 +0200 Subject: [PATCH v4 1/5] iio: light: al3010: Improve al3010_init error handling with dev_err_probe() Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250402-al3010-iio-regmap-v4-1-d189bea87261@ixit.cz> References: <20250402-al3010-iio-regmap-v4-0-d189bea87261@ixit.cz> In-Reply-To: <20250402-al3010-iio-regmap-v4-0-d189bea87261@ixit.cz> To: Jonathan Cameron , Lars-Peter Clausen Cc: Svyatoslav Ryhel , Robert Eckelmann , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Heidelberg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1226; i=david@ixit.cz; h=from:subject:message-id; bh=N9LbC8OZWRVf5APMfHXIqkJb2k+lvKlkciNMNe3ltSs=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn7ZEJh1yMmYwBfvrQLmelKSsmcsjaMNsSDa+5P 0kf0VvqhTSJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2RCQAKCRBgAj/E00kg chxtD/0WlctxGyXcnUrf4p7CHbPuMELKfAxvnBa37etxVgIiupkvBozuv2OZFLb0k54yoHqicRK lXg/ymE0+bYEQLAuPXRY1rcsqp6UTB06K7+UCFGAvaCztqNq+IvX+UPvMipKao4Zi7mpFKEAac+ RE53tvVjVL0hx6PjNb0iQR3hO+J5VRto5QPiH7TonoDY+XR36lHNKDXG6ni8SFCbliEDAAs7xAY eN28gGAhzj62mJi+guuQDGiJyHSQo+cmp99q9MUJhVtnayZHsxBcGbezIb6Kf0uKVeEZFay56PU lk916DZyPgvLzr6CdJglPDV1ZLga4G3XLSQpnalKmBafK+mumdiXcUR8RN9guWDx56n8eZrdERY pgmVkLUgofnWbzEv+eZ/7TS7DkBw4Gepo49H1UdAHSk4+UzrLAHneJZ6+4RWRHaIrjs7jQ6vQTz h8xxitKwxNK4Vt+qeOMsb9N2DS1dlKMx4SDxLcpW8ug1J8KQmsdeIlYrQ2Gb4WILEGSsAeZo6mD 92QKBRtTMd+oLkW5NW1wRIYWXarIj9HWCivO9tikhs4ouqpxjEY0YBOS31qtZNQl1DkVcYFuYNx AEkDOY1e2c2v/Jyi6TTWy2f2iPta82pn8NDVJ+qX+DECsOLJQ5Jwuwvx6MThroE9pNyBUT0k996 r81JE+n9uMZY6Jw== X-Developer-Key: i=david@ixit.cz; a=openpgp; fpr=D77A09CFEEDC2BBD53A7047460023FC4D3492072 X-Endpoint-Received: by B4 Relay for david@ixit.cz/default with auth_id=355 X-Original-From: David Heidelberg Reply-To: david@ixit.cz From: David Heidelberg From: David Heidelberg Minor code simplifications and improved error reporting. Signed-off-by: David Heidelberg --- drivers/iio/light/al3010.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/iio/light/al3010.c b/drivers/iio/light/al3010.c index 8c004a9239aef246a8c6f6c3f4acd6b760ee8249..34a29a51c5f9e8aa143d3ba195b79a19793e4f88 100644 --- a/drivers/iio/light/al3010.c +++ b/drivers/iio/light/al3010.c @@ -92,8 +92,8 @@ static int al3010_init(struct al3010_data *data) ret = devm_add_action_or_reset(&data->client->dev, al3010_set_pwr_off, data); - if (ret < 0) - return ret; + if (ret) + return dev_err_probe(&data->client->dev, ret, "failed to add action\n"); ret = i2c_smbus_write_byte_data(data->client, AL3010_REG_CONFIG, FIELD_PREP(AL3010_GAIN_MASK, @@ -190,10 +190,8 @@ static int al3010_probe(struct i2c_client *client) indio_dev->modes = INDIO_DIRECT_MODE; ret = al3010_init(data); - if (ret < 0) { - dev_err(dev, "al3010 chip init failed\n"); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, "failed to init ALS\n"); return devm_iio_device_register(dev, indio_dev); } From patchwork Wed Apr 2 19:33:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036415 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 BE8551DE2A5; Wed, 2 Apr 2025 19:33:32 +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=1743622412; cv=none; b=ljkG5AIgDgF3Ss/lQpO4WwwwuA5lcj7BiA9UOVJa3gAXTasQJL4knEkr4HLlJE8+y2NPHuTzkfEDBJvSmfMg2V3gL1V4we+MDH8vyOJuHZCIyjXl/nAMh/hufgZVAGEwiGMWDgGhwFIjUgX3XL8Lo2F4BSDkUPslGdwlNvt3AWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743622412; c=relaxed/simple; bh=O2TGhCtbwyCv/uYpcbYa8vSxgrjrVO0TZfOd0YOOx3M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CFaUlgvyRW8fEXCHHKEizTIPTgJ9YdZnDDiQpci/+CMbG+mxn2fef+ddhWnE5hga4OltnRCDTFydw06w7aF3w6FDjiOPYY+TBrddIEvsbOTEF2OcQs6VPsuZECRNEEVW7jalb+OEyc+6SJ4MLz0J7mcKQPRYoAXG8GKWDjGqvZU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ylh3FAwH; 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="Ylh3FAwH" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3B7FDC4CEEA; Wed, 2 Apr 2025 19:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743622412; bh=O2TGhCtbwyCv/uYpcbYa8vSxgrjrVO0TZfOd0YOOx3M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Ylh3FAwHKqfvQqWS0sJ8IBlVVpFClyqENkowpZHP70CHvuaBM/fK04OiaYHo2tuU7 lJmxZq57ksDFFMBsJhv/NhLdXBCHovf4mbUm93gCx2tN3sAl6aPk6DYeChc4lE001k yMQs71M0u+LefhQja54UTEgM+w4VlaXT+UN7NLU4RbmWkl+nmle1SerBgF2bUV3WIF TzFKv/aLB32sE+wHR05Nkbx2Qa2a4w6a5PMCBPdn9cT2DhRztF/uC/hPXJPrHV++sK df7+DyIcCm4NFbFjraXytpCYnRYITJIOcbJgOQwvLoNhrnsv8w4FHj1ZN6i69vevDg pMLEIl9gxjhAw== 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 2D52BC3601F; Wed, 2 Apr 2025 19:33:32 +0000 (UTC) Date: Wed, 02 Apr 2025 21:33:25 +0200 Subject: [PATCH v4 2/5] iio: light: al3000a: Fix an error handling path in al3000a_probe() Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250402-al3010-iio-regmap-v4-2-d189bea87261@ixit.cz> References: <20250402-al3010-iio-regmap-v4-0-d189bea87261@ixit.cz> In-Reply-To: <20250402-al3010-iio-regmap-v4-0-d189bea87261@ixit.cz> To: Jonathan Cameron , Lars-Peter Clausen Cc: Svyatoslav Ryhel , Robert Eckelmann , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Heidelberg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1507; i=david@ixit.cz; h=from:subject:message-id; bh=66tuh0qra+186i8PqZ9MH09vmloKVLdmfLyT9O7NZJA=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn7ZEKK38jVBmHNU7CFYig14RDpWa0ZY1lj8pTo eVvHE5NkY2JAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2RCgAKCRBgAj/E00kg cpyqD/0cFgarWExeX/tExe5FTLgYJPq0Xq/kck8yd71Vru/LfC7yA9BE4BFt3NlSei5tUJQxpmj O1WY8H3w5psDaJWwr2sfyEknwDwb66cXaQiX2cG7dQ9TOFeOuSbjEGTuJGlfs5ezPnQBSdyYeKp R4wdUo7vJ7fQx9AWhSiuw5IbhCsoSW81QzkFrCsJYw7DA961cT81OYXdGZcVqP1aiZ9c5fL5J+1 0ETI6JxPm7Vn0AxfiiRxpKaWEtQiR9O4OSIE4o/i95svsqMKMEb9ydJUEUssq0tovzzyTfeyPsU aiosITW0pjausm2HFfR51+Mp0yzjY4kOat6jWXBxtE4akF5dce5gtaBlxVbdNnQHxB5/C0CvY/m LBniBGgCT9TGk5mwVB41NyRWGv+n4KTuJs57qVNrM1WU1BECDlM3CKOT+6bm/azv5CmW1uKtz6l bEO1XPNUo8OEYFnWFALsHmMWEIQl1KW9YIyPx72tQYfq01r3sPnzF+P7j6iud1Z8YgNb3lg1LIe 7D7lHzKIe/wFWEFnQyC9MRvc1q3DnKZDzpiziZaMW/iRJ/2WIUfyYQkbsNJoCbqPh2Vo5FnbMJ2 Krxg39SDlLW5EHMLo9wVab5OqosY98PV4D5jfgv+DyQ3do/lMfpLgxdDdOvjVl8VX462e4xLy5g lkUx24OLatH7t0w== X-Developer-Key: i=david@ixit.cz; a=openpgp; fpr=D77A09CFEEDC2BBD53A7047460023FC4D3492072 X-Endpoint-Received: by B4 Relay for david@ixit.cz/default with auth_id=355 X-Original-From: David Heidelberg Reply-To: david@ixit.cz From: David Heidelberg From: David Heidelberg If regmap_write() fails in al3000a_init(), al3000a_set_pwr_off is not called. In order to avoid such a situation, move the devm_add_action_or_reset() which calls al3000a_set_pwr_off right after a successful al3000a_set_pwr_on. Signed-off-by: David Heidelberg --- drivers/iio/light/al3000a.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/iio/light/al3000a.c b/drivers/iio/light/al3000a.c index e2fbb1270040f43d9f0a97838861818a8eaef813..6d5115b2a06c5acce18d831b9c41d3d5121fba12 100644 --- a/drivers/iio/light/al3000a.c +++ b/drivers/iio/light/al3000a.c @@ -85,12 +85,17 @@ static void al3000a_set_pwr_off(void *_data) static int al3000a_init(struct al3000a_data *data) { + struct device *dev = regmap_get_device(data->regmap); int ret; ret = al3000a_set_pwr_on(data); if (ret) return ret; + ret = devm_add_action_or_reset(dev, al3000a_set_pwr_off, data); + if (ret) + return dev_err_probe(dev, ret, "failed to add action\n"); + ret = regmap_write(data->regmap, AL3000A_REG_SYSTEM, AL3000A_CONFIG_RESET); if (ret) return ret; @@ -157,10 +162,6 @@ static int al3000a_probe(struct i2c_client *client) if (ret) return dev_err_probe(dev, ret, "failed to init ALS\n"); - ret = devm_add_action_or_reset(dev, al3000a_set_pwr_off, data); - if (ret) - return dev_err_probe(dev, ret, "failed to add action\n"); - return devm_iio_device_register(dev, indio_dev); } From patchwork Wed Apr 2 19:33:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036413 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 BE765537FF; Wed, 2 Apr 2025 19:33:32 +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=1743622412; cv=none; b=CjwhN428J/yXvYnWb3lhlmMZ5P2zdJoO+/MGicTuBGSCpH0dYEhFFjqxTv94w+kYIyqWMYoDMagrDstKmltuC4NexuuxfXZw61XTThLevv6NLE+5sd4bzQzgy1a6z4NFj9ExCkGTBteNeImv85Woxd/NCMGzkS/qNIEd/e/XmkU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743622412; c=relaxed/simple; bh=y8pgi5JtduylthuSaY0K3q7nUbMsc3wf6FBuvAUREpk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=foBkz7px02xiWmlazXAbagQtB6vUZ9USerbMypVvnNDExe7Dd3go4gLtTMFxiVsIL6AzU3cViOT/LK1SBFXA9IZrE98GKYkqikX06+AL7kE8RGDbnLyg0K16Ll5e/zAOH8lzGFBCPW4z9+lK3VPM4KtbjFZmj0GJhJh2pmCOlqU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tb7TQ8eR; 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="tb7TQ8eR" Received: by smtp.kernel.org (Postfix) with ESMTPS id 4EDFDC4CEEB; Wed, 2 Apr 2025 19:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743622412; bh=y8pgi5JtduylthuSaY0K3q7nUbMsc3wf6FBuvAUREpk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=tb7TQ8eRPy9sdmFdTjdw28t8oX7M8LBrdmH1ZBHmKoBSMB6sA3oPZ2hZLGR7GavJh AWjW/4a8WvGTk9zzvDg30gJjO/TPIu33zDi13rUqRlcvLg5hKHQzaYsKjS76asVN/x RAwNTy7GhNLp2y1aMZMdaOxZdS8NxyAEyN8a1ZVuN9clIUMca2o8UCsH3+5shohqVX +37DfsAGEtXdUf9F3srgMO7NuV+SDZWQZJtD0XFpLiHvpfmTJviPCEpyoiHZUY0cf1 rQBb22lvnFd29G9Wa+11ia7FvIiTn9M8CBbfZPTPTZGr6AjWsVV+hz4qyesQvD4Hm9 PO/m06JFToKfQ== 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 415A4C3601E; Wed, 2 Apr 2025 19:33:32 +0000 (UTC) Date: Wed, 02 Apr 2025 21:33:26 +0200 Subject: [PATCH v4 3/5] iio: light: al3320a: Fix an error handling path in al3320a_probe() Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250402-al3010-iio-regmap-v4-3-d189bea87261@ixit.cz> References: <20250402-al3010-iio-regmap-v4-0-d189bea87261@ixit.cz> In-Reply-To: <20250402-al3010-iio-regmap-v4-0-d189bea87261@ixit.cz> To: Jonathan Cameron , Lars-Peter Clausen Cc: Svyatoslav Ryhel , Robert Eckelmann , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Heidelberg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1351; i=david@ixit.cz; h=from:subject:message-id; bh=mTCyccBifllmHJInqLXe+hdaL4JlCXkaIIsicpjyZMI=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn7ZEKD01cnC8iLLj/aKn9pjzrLDbyH8bXtPAtv DYzhSepiJmJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2RCgAKCRBgAj/E00kg cn40D/4rxElhV51cdYCOw82WrQd5fsVyC4nEuiCh6arve9ful8lyPDhnPhg6MetJKlLfbs0WajM 3CLobiP4r+k/hpdQDGdWp5tEaWKjS2V9jIwaUcH+YPRTDthrELoonuiuz3jQs9DUEE6IdYlED3m K0mZYyZE9McWqU4dflZnSL94SdQ0PUyCqdA6gO0OMg0/9NHcW6UF8dawdpUQg4WEEw618Xux2b/ FLm2bRHHJd3Ex8gpmxe/bX/vxo3KNRG7YZpEeXX4Y6YNlyRQ7mT6bjAiN1BrmfEs9DQa07+WKa+ 1tnVXBGrgNDWheBD3V0L1u5GOfJxN6nXZEC8c5uRFsMGNEr+BSDRZYv/CPmE4tNjyXRIew1XR2J MnLWn0rM6XaqEjF64qz5LNaHCkHXJdUdMJZaNnIfRf64u1Acz4s4U4UQjkJEBLad++BYEsMmXat n1Br9SUN7Djazuzk0HIb3ToFHxl/OxxmGA5GT/wRSXJ3/wCAhCS3emABlcJc3XCnxYo0D2KNA7N g1f1sJO/NTko0v/N0W4atSQj93rGZmz7HTe6wRHBsxcT/ofVhVaDoFXSI07ApYztjxblVXd9eiU 5rYS+IaxRWEis0D1cTP0k/XZq6jxe6Au8KpS4+E7IXbF2INLTCgsuXBB04thIDA876bJkmxgybW ivarTCdU7lFr+Bg== X-Developer-Key: i=david@ixit.cz; a=openpgp; fpr=D77A09CFEEDC2BBD53A7047460023FC4D3492072 X-Endpoint-Received: by B4 Relay for david@ixit.cz/default with auth_id=355 X-Original-From: David Heidelberg Reply-To: david@ixit.cz From: David Heidelberg From: David Heidelberg If regmap_write() fails in al3320a_init(), al3320a_set_pwr_off is not called. In order to avoid such a situation, move the devm_add_action_or_reset() which calls al3320a_set_pwr_off right after a successful al3320a_set_pwr_on. Signed-off-by: David Heidelberg --- drivers/iio/light/al3320a.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/iio/light/al3320a.c b/drivers/iio/light/al3320a.c index 1b2b0359ed5dad5e00d2fe584f8f3495c13c997e..1fa693d54ae2a6e5ead3a9c7ac7018afeba9b760 100644 --- a/drivers/iio/light/al3320a.c +++ b/drivers/iio/light/al3320a.c @@ -101,6 +101,12 @@ static int al3320a_init(struct al3320a_data *data) if (ret < 0) return ret; + ret = devm_add_action_or_reset(&data->client->dev, + al3320a_set_pwr_off, + data); + if (ret) + return dev_err_probe(&data->client->dev, ret, "failed to add action\n"); + ret = i2c_smbus_write_byte_data(data->client, AL3320A_REG_CONFIG_RANGE, FIELD_PREP(AL3320A_GAIN_MASK, AL3320A_RANGE_3)); @@ -211,10 +217,6 @@ static int al3320a_probe(struct i2c_client *client) return ret; } - ret = devm_add_action_or_reset(dev, al3320a_set_pwr_off, data); - if (ret < 0) - return ret; - return devm_iio_device_register(dev, indio_dev); } From patchwork Wed Apr 2 19:33:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036414 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 BE7AC13635E; Wed, 2 Apr 2025 19:33:32 +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=1743622412; cv=none; b=B9PHSihQ/lWWj8N3/wCYgfj9xFF+4f0ODwBFRDpaWofwDEDriNoTk2meeh6/7Tag8Zcvx61snsohFfdIJwGL/sZkB2vbiE+XT1pAJr+pkG36EXtU4zEKFGStDuigFydLmitDpoBt2B+wUTj3jVhq+TrDJpK7lBphRv595o+rGew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743622412; c=relaxed/simple; bh=GD1mfBzXCt0cgDgeoYjhc5hkgaAZktPHxYCmSLS1h0I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mn704I0eHLs7BoqLrI93h1xDktWqv2ZXF+w+lQNIR4fVBkk61RWpWfNQMBI1H9L/3Z8vurUpcs/6CmYR1J/qVYI42jdOfQllsB9W9Q4CWVUj9OfISDI3bqfKyiPeXcVWPCkKTlOzLOHa6COvizZQv0DaQtTw/uN3YObPpts4wWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=THbQJsqw; 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="THbQJsqw" Received: by smtp.kernel.org (Postfix) with ESMTPS id 62E40C4CEEF; Wed, 2 Apr 2025 19:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743622412; bh=GD1mfBzXCt0cgDgeoYjhc5hkgaAZktPHxYCmSLS1h0I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=THbQJsqwfZ9Kv42AwxphMriqBl1tdE0lAu2kQqbDmGqBtSC9Usj/MEg+UH1sEXAH1 UJo0ddBEDui3qqo7pZk9FVeKhWP2zcUth1dXaHXLOw3ZWUd4yC/Tv07fdOT38zsszg gpHoTpSNOPbbi5KoYo6qexxjlXC7x6oog0EsZ2tHHEAi+YvEn7EC+cVnMQiwCzCYLC QPgZowp8On3YROj6opJu6oKxrz3zSalVf6soII7x2pGWFklTlFfmzjH2WRkUjA7PhF Xa/8jWFBftKEYTEzg7uIRBq15Cu8dAmM08v9+31PfEoOGxILdtCyaVIaKMFl5H96dQ BfAjAfjaR7QfA== 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 5859AC3601B; Wed, 2 Apr 2025 19:33:32 +0000 (UTC) Date: Wed, 02 Apr 2025 21:33:27 +0200 Subject: [PATCH v4 4/5] iio: light: al3010: Implement regmap support Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250402-al3010-iio-regmap-v4-4-d189bea87261@ixit.cz> References: <20250402-al3010-iio-regmap-v4-0-d189bea87261@ixit.cz> In-Reply-To: <20250402-al3010-iio-regmap-v4-0-d189bea87261@ixit.cz> To: Jonathan Cameron , Lars-Peter Clausen Cc: Svyatoslav Ryhel , Robert Eckelmann , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Heidelberg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5389; i=david@ixit.cz; h=from:subject:message-id; bh=xLXsAL6IdnDjFhJIlqoCoKr7hx9rtDUHioMAjUgCuVg=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn7ZEK1PisZ3DA8tTFzQ7YNrhqQdK4MjHjULRwe Nd4nNUg4LOJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2RCgAKCRBgAj/E00kg cqUqEACzIR7MO8Hq9NtE5+/vnPb8Yq4bEg53p26e09ClAISxRv/O/TekJYo8Xa+8SUvW3uhQPWC ARkPCjQStdSdZ0EoygNSwLEt8kKIkV0c21IDdArIlnLkEzuAvMSV7CbeE0y3K8sHbu1FqSA+Co2 WS3yPWmAz34UMiupn8Srp+KuGvo8gS6mirsrV5tg3lspAlC+Ov1qDBIpNOb6aHpERo7z7a1Wd2r tZYLk1hwzn1p1dg6GruRePXnK7NJi8RDaUrhlpIUozmDeWR9hR4IlHoFU1ESB/pU5jfGcMf5puN bRahgTn3Ohr4jUvaVzadL4P1FW9vEZ+UCA2C2r9Hgkn8juRh5c0nk02PCyEuPlpJvtQr6DaGBf8 YZej64VCxA8NxMmjkTPB+W8ExYL7RRzIE8oqjCZ3oXQpfvvHH5iE2ObGv+lrDYc69q3l5J05Mq7 QvrxjOraNSUyDEwl8lMeHrPFzwduBi6AEdMiG9wpczCCtpyMyb9Y5Qoqf6KgZnqCIfV72CMs4Hd qFHe7dNBWI6G5FRio3Yqt2lVlmxwuDZY1bhz4IQa8C/bRJrpr+z4UkexnAeGrN6c2kBhg569KO+ 2dp8hbIkrZJEZH0u/AyJNopc/gbYyrc1/pU0hCcDeBljB6WciEdbA2PCAAvnipEFEpmT2pRQt/O OBqJI5wwhZW5PHw== X-Developer-Key: i=david@ixit.cz; a=openpgp; fpr=D77A09CFEEDC2BBD53A7047460023FC4D3492072 X-Endpoint-Received: by B4 Relay for david@ixit.cz/default with auth_id=355 X-Original-From: David Heidelberg Reply-To: david@ixit.cz From: David Heidelberg From: David Heidelberg Modernize and clean up the driver using the regmap framework. With the regmap implementation, the compiler produces a significantly smaller module. Size before: 72 kB Size after: 58 kB Signed-off-by: David Heidelberg --- drivers/iio/light/al3010.c | 77 +++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/drivers/iio/light/al3010.c b/drivers/iio/light/al3010.c index 34a29a51c5f9e8aa143d3ba195b79a19793e4f88..d4c9a6e5c415269332dda67622b17b46fb157218 100644 --- a/drivers/iio/light/al3010.c +++ b/drivers/iio/light/al3010.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -44,8 +45,14 @@ static const int al3010_scales[][2] = { {0, 1187200}, {0, 296800}, {0, 74200}, {0, 18600} }; +static const struct regmap_config al3010_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = AL3010_REG_CONFIG, +}; + struct al3010_data { - struct i2c_client *client; + struct regmap *regmap; }; static const struct iio_chan_spec al3010_channels[] = { @@ -67,41 +74,37 @@ static const struct attribute_group al3010_attribute_group = { .attrs = al3010_attributes, }; -static int al3010_set_pwr_on(struct i2c_client *client) +static int al3010_set_pwr_on(struct al3010_data *data) { - return i2c_smbus_write_byte_data(client, AL3010_REG_SYSTEM, - AL3010_CONFIG_ENABLE); + return regmap_write(data->regmap, AL3010_REG_SYSTEM, AL3010_CONFIG_ENABLE); } static void al3010_set_pwr_off(void *_data) { struct al3010_data *data = _data; + struct device *dev = regmap_get_device(data->regmap); + int ret; - i2c_smbus_write_byte_data(data->client, AL3010_REG_SYSTEM, - AL3010_CONFIG_DISABLE); + ret = regmap_write(data->regmap, AL3010_REG_SYSTEM, AL3010_CONFIG_DISABLE); + if (ret) + dev_err(dev, "failed to write system register\n"); } static int al3010_init(struct al3010_data *data) { + struct device *dev = regmap_get_device(data->regmap); int ret; - ret = al3010_set_pwr_on(data->client); - if (ret < 0) + ret = al3010_set_pwr_on(data); + if (ret) return ret; - ret = devm_add_action_or_reset(&data->client->dev, - al3010_set_pwr_off, - data); + ret = devm_add_action_or_reset(dev, al3010_set_pwr_off, data); if (ret) - return dev_err_probe(&data->client->dev, ret, "failed to add action\n"); - - ret = i2c_smbus_write_byte_data(data->client, AL3010_REG_CONFIG, - FIELD_PREP(AL3010_GAIN_MASK, - AL3XXX_RANGE_3)); - if (ret < 0) - return ret; + return dev_err_probe(dev, ret, "failed to add action\n"); - return 0; + return regmap_write(data->regmap, AL3010_REG_CONFIG, + FIELD_PREP(AL3010_GAIN_MASK, AL3XXX_RANGE_3)); } static int al3010_read_raw(struct iio_dev *indio_dev, @@ -109,7 +112,7 @@ static int al3010_read_raw(struct iio_dev *indio_dev, int *val2, long mask) { struct al3010_data *data = iio_priv(indio_dev); - int ret; + int ret, gain, raw; switch (mask) { case IIO_CHAN_INFO_RAW: @@ -118,21 +121,21 @@ static int al3010_read_raw(struct iio_dev *indio_dev, * - low byte of output is stored at AL3010_REG_DATA_LOW * - high byte of output is stored at AL3010_REG_DATA_LOW + 1 */ - ret = i2c_smbus_read_word_data(data->client, - AL3010_REG_DATA_LOW); - if (ret < 0) + ret = regmap_read(data->regmap, AL3010_REG_DATA_LOW, &raw); + if (ret) return ret; - *val = ret; + + *val = raw; + return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: - ret = i2c_smbus_read_byte_data(data->client, - AL3010_REG_CONFIG); - if (ret < 0) + ret = regmap_read(data->regmap, AL3010_REG_CONFIG, &gain); + if (ret) return ret; - ret = FIELD_GET(AL3010_GAIN_MASK, ret); - *val = al3010_scales[ret][0]; - *val2 = al3010_scales[ret][1]; + gain = FIELD_GET(AL3010_GAIN_MASK, gain); + *val = al3010_scales[gain][0]; + *val2 = al3010_scales[gain][1]; return IIO_VAL_INT_PLUS_MICRO; } @@ -153,9 +156,8 @@ static int al3010_write_raw(struct iio_dev *indio_dev, val2 != al3010_scales[i][1]) continue; - return i2c_smbus_write_byte_data(data->client, - AL3010_REG_CONFIG, - FIELD_PREP(AL3010_GAIN_MASK, i)); + return regmap_write(data->regmap, AL3010_REG_CONFIG, + FIELD_PREP(AL3010_GAIN_MASK, i)); } break; } @@ -181,7 +183,10 @@ static int al3010_probe(struct i2c_client *client) data = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); - data->client = client; + data->regmap = devm_regmap_init_i2c(client, &al3010_regmap_config); + if (IS_ERR(data->regmap)) + return dev_err_probe(dev, PTR_ERR(data->regmap), + "cannot allocate regmap\n"); indio_dev->info = &al3010_info; indio_dev->name = "al3010"; @@ -206,7 +211,9 @@ static int al3010_suspend(struct device *dev) static int al3010_resume(struct device *dev) { - return al3010_set_pwr_on(to_i2c_client(dev)); + struct al3010_data *data = iio_priv(dev_get_drvdata(dev)); + + return al3010_set_pwr_on(data); } static DEFINE_SIMPLE_DEV_PM_OPS(al3010_pm_ops, al3010_suspend, al3010_resume); From patchwork Wed Apr 2 19:33:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036417 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 CEDA81E2847; Wed, 2 Apr 2025 19:33:32 +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=1743622412; cv=none; b=Sqgp4VNszVgmYOsZoGZV5/0kDd2wtnIYToa1AvqT25dUAVij6U2E0Atqdnm29e9uYfROcDtls1A4PXQkNxycw2kntuBtpowkTYD7W8GmqUYznbHinmcVKg0pCq9pnR0a6cLhmSxk9cfSRRjpG8F1wyWsFSQuG4DHHvEfLYuk2Uw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743622412; c=relaxed/simple; bh=ZQ5rXtxFpcftxO9BKYVGOH3WBUnbDNUjD+xKM7Odu9w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AmAcQwEI9yxgp8qbCHo23MMeoc/Qlu3AUTmGfvz4FgwJEGg6ECOKdIu/NGh8qA3yLxSh742ykw7oGFCklpZeu2RzGrfLyfmrWENJxIGWOPFaeFUb2dNArFRDNS58umbVq4rd+0rYWwAztJdsM1zeDGrJ5VVWh194f1qNUaU6fuM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZXBpFQUV; 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="ZXBpFQUV" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7855CC4CEF1; Wed, 2 Apr 2025 19:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743622412; bh=ZQ5rXtxFpcftxO9BKYVGOH3WBUnbDNUjD+xKM7Odu9w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ZXBpFQUVMUXo7CyFR/i0RG2m7m0ejcT2qSmszm9oasu0NDb7hISayzIQyLwI9e3dC RgeZviifmPoxkFaTTDBXvWtnCMRix6sOjZCbcccWPggD7UumWgbSXBbhXnVST5i3NW zcC0eXkvhQD68FtpvygCH6/k9xr25RJdQp6z4hpCuyN4NMqYIvtxl1V7zhRa2EPfxp Yaym+dXzJUdSRoNLSfIHioYqj8rkNv3gXh5qSOT/4EdB5woypshpfLRDVn/pRr//pI rcU1oZ4sIIRiQse/uqWe4OnGbAwrOj9MkTuZgmuAFhK1K8Yhu5EyirLfZ4n6wvcZUX S6hlarWi7fskg== 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 6DCDCC36018; Wed, 2 Apr 2025 19:33:32 +0000 (UTC) Date: Wed, 02 Apr 2025 21:33:28 +0200 Subject: [PATCH v4 5/5] iio: light: al3320a: Implement regmap support Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250402-al3010-iio-regmap-v4-5-d189bea87261@ixit.cz> References: <20250402-al3010-iio-regmap-v4-0-d189bea87261@ixit.cz> In-Reply-To: <20250402-al3010-iio-regmap-v4-0-d189bea87261@ixit.cz> To: Jonathan Cameron , Lars-Peter Clausen Cc: Svyatoslav Ryhel , Robert Eckelmann , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Heidelberg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5966; i=david@ixit.cz; h=from:subject:message-id; bh=KF7wfd386VFn0Qab9eMCBOMC7w8cF3bp15+z7GtVxKg=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn7ZEKANUDM7It0EXHF5Zdp51cw6YGYAR+pS7gk diU+mWsUt2JAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2RCgAKCRBgAj/E00kg choBEACyrkpl681CZgf8ZKOvVH6HO5wDcd0B4Hu9xdZHhuETVbVMknY0sYRNDwvdf4gSxjOcCW1 siWO9ydJeNafHoi3uZZulQc84FnIx1/tC3YLBX9aVPAW9zsJPJM9e04HhW+LJWgOIZidhuzyWIJ SlFM4QfEJ82VDsZP58PvcYS2jhldS54Pb0mnUz4Db52zFKkncLclkByBye217sjPlPmwAqoJpcK uBaQFfzVW57nn4gB0dpHK5cTlcJtV6yVdbGp30yI84Tiht7wNvLbmUrQnmEeSumxw0vt4oHOSnC AvXIorG0/uUM9BnlpWOB9PRtTTlinjihN9iDCPg9ZzOwaFmDmQPWxZcz7EPl/UjhFVA5YdrCIY3 uHpf7BZdtuVRbIBlurAOK1UmNo/gNODeFyR5Ls9rRXsuJ4KTeeyX9+OLonMujyJ/SlUEPkNtXO/ pgWAGMCqKKa1jPQ9WTTU+g2N1CVeOMD7JsUMXnV9meQpqbYXtsazOseIYq/NQKgMsqwtkVJh3Ex EWx0kKIA1j4AxevvdsWXYyxI3ljTXix1Ke2M9GP7hTPWiRwkKEE2pJUKyxeM9czaLbotnIqhsQa /fv02G9Rdg9yb2s6J54xYGZ3F5oHYMtLSlT0Ke/2qRs9XctnnhtywP9d/XpZ9xqAJ6sRSLFAanz 0qCT5mok3aauaNw== X-Developer-Key: i=david@ixit.cz; a=openpgp; fpr=D77A09CFEEDC2BBD53A7047460023FC4D3492072 X-Endpoint-Received: by B4 Relay for david@ixit.cz/default with auth_id=355 X-Original-From: David Heidelberg Reply-To: david@ixit.cz From: David Heidelberg From: David Heidelberg Modernize and clean up the driver using the regmap framework. With the regmap implementation, the compiler produces a significantly smaller module. Size before: 72 kB Size after: 58 kB Signed-off-by: David Heidelberg --- drivers/iio/light/al3320a.c | 89 +++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/drivers/iio/light/al3320a.c b/drivers/iio/light/al3320a.c index 1fa693d54ae2a6e5ead3a9c7ac7018afeba9b760..988a3dd3a8449f10c657eb75fd744b2a9db2965e 100644 --- a/drivers/iio/light/al3320a.c +++ b/drivers/iio/light/al3320a.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -57,8 +58,14 @@ static const int al3320a_scales[][2] = { {0, 512000}, {0, 128000}, {0, 32000}, {0, 10000} }; +static const struct regmap_config al3320a_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = AL3320A_REG_HIGH_THRESH_HIGH, +}; + struct al3320a_data { - struct i2c_client *client; + struct regmap *regmap; }; static const struct iio_chan_spec al3320a_channels[] = { @@ -80,50 +87,47 @@ static const struct attribute_group al3320a_attribute_group = { .attrs = al3320a_attributes, }; -static int al3320a_set_pwr_on(struct i2c_client *client) +static int al3320a_set_pwr_on(struct al3320a_data *data) { - return i2c_smbus_write_byte_data(client, AL3320A_REG_CONFIG, AL3320A_CONFIG_ENABLE); + return regmap_write(data->regmap, AL3320A_REG_CONFIG, AL3320A_CONFIG_ENABLE); } static void al3320a_set_pwr_off(void *_data) { struct al3320a_data *data = _data; + struct device *dev = regmap_get_device(data->regmap); + int ret; - i2c_smbus_write_byte_data(data->client, AL3320A_REG_CONFIG, AL3320A_CONFIG_DISABLE); + ret = regmap_write(data->regmap, AL3320A_REG_CONFIG, AL3320A_CONFIG_DISABLE); + if (ret) + dev_err(dev, "failed to write system register\n"); } static int al3320a_init(struct al3320a_data *data) { + struct device *dev = regmap_get_device(data->regmap); int ret; - ret = al3320a_set_pwr_on(data->client); - - if (ret < 0) + ret = al3320a_set_pwr_on(data); + if (ret) return ret; - ret = devm_add_action_or_reset(&data->client->dev, - al3320a_set_pwr_off, - data); + ret = devm_add_action_or_reset(dev, al3320a_set_pwr_off, data); if (ret) - return dev_err_probe(&data->client->dev, ret, "failed to add action\n"); - - ret = i2c_smbus_write_byte_data(data->client, AL3320A_REG_CONFIG_RANGE, - FIELD_PREP(AL3320A_GAIN_MASK, - AL3320A_RANGE_3)); - if (ret < 0) - return ret; + return dev_err_probe(dev, ret, "failed to add action\n"); - ret = i2c_smbus_write_byte_data(data->client, AL3320A_REG_MEAN_TIME, - AL3320A_DEFAULT_MEAN_TIME); - if (ret < 0) + ret = regmap_write(data->regmap, AL3320A_REG_CONFIG_RANGE, + FIELD_PREP(AL3320A_GAIN_MASK, AL3320A_RANGE_3)); + if (ret) return ret; - ret = i2c_smbus_write_byte_data(data->client, AL3320A_REG_WAIT, - AL3320A_DEFAULT_WAIT_TIME); - if (ret < 0) + ret = regmap_write(data->regmap, AL3320A_REG_MEAN_TIME, + AL3320A_DEFAULT_MEAN_TIME); + if (ret) return ret; - return 0; + return regmap_write(data->regmap, AL3320A_REG_WAIT, + AL3320A_DEFAULT_WAIT_TIME); } static int al3320a_read_raw(struct iio_dev *indio_dev, @@ -131,7 +135,7 @@ static int al3320a_read_raw(struct iio_dev *indio_dev, int *val2, long mask) { struct al3320a_data *data = iio_priv(indio_dev); - int ret; + int ret, gain, raw; switch (mask) { case IIO_CHAN_INFO_RAW: @@ -140,21 +144,21 @@ static int al3320a_read_raw(struct iio_dev *indio_dev, * - low byte of output is stored at AL3320A_REG_DATA_LOW * - high byte of output is stored at AL3320A_REG_DATA_LOW + 1 */ - ret = i2c_smbus_read_word_data(data->client, - AL3320A_REG_DATA_LOW); - if (ret < 0) + ret = regmap_read(data->regmap, AL3320A_REG_DATA_LOW, &raw); + if (ret) return ret; - *val = ret; + + *val = raw; + return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: - ret = i2c_smbus_read_byte_data(data->client, - AL3320A_REG_CONFIG_RANGE); - if (ret < 0) + ret = regmap_read(data->regmap, AL3320A_REG_CONFIG_RANGE, &gain); + if (ret) return ret; - ret = FIELD_GET(AL3320A_GAIN_MASK, ret); - *val = al3320a_scales[ret][0]; - *val2 = al3320a_scales[ret][1]; + gain = FIELD_GET(AL3320A_GAIN_MASK, gain); + *val = al3320a_scales[gain][0]; + *val2 = al3320a_scales[gain][1]; return IIO_VAL_INT_PLUS_MICRO; } @@ -175,9 +179,8 @@ static int al3320a_write_raw(struct iio_dev *indio_dev, val2 != al3320a_scales[i][1]) continue; - return i2c_smbus_write_byte_data(data->client, - AL3320A_REG_CONFIG_RANGE, - FIELD_PREP(AL3320A_GAIN_MASK, i)); + return regmap_write(data->regmap, AL3320A_REG_CONFIG_RANGE, + FIELD_PREP(AL3320A_GAIN_MASK, i)); } break; } @@ -203,7 +206,11 @@ static int al3320a_probe(struct i2c_client *client) data = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); - data->client = client; + + data->regmap = devm_regmap_init_i2c(client, &al3320a_regmap_config); + if (IS_ERR(data->regmap)) + return dev_err_probe(dev, PTR_ERR(data->regmap), + "cannot allocate regmap\n"); indio_dev->info = &al3320a_info; indio_dev->name = "al3320a"; @@ -230,7 +237,9 @@ static int al3320a_suspend(struct device *dev) static int al3320a_resume(struct device *dev) { - return al3320a_set_pwr_on(to_i2c_client(dev)); + struct al3320a_data *data = iio_priv(dev_get_drvdata(dev)); + + return al3320a_set_pwr_on(data); } static DEFINE_SIMPLE_DEV_PM_OPS(al3320a_pm_ops, al3320a_suspend,