From patchwork Wed Apr 2 19:14:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036405 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 785981E5B90; Wed, 2 Apr 2025 19:15:05 +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=1743621305; cv=none; b=QhslOAxrw/Konlerpy20nkJ/JTpayyE7gsGU0NVtsdy4hDCBy0GxvbVt05Q/mYvnOr3JyO8AptLGx3LBsaDXt+K/RYjycoDT8xYR1dDoN2Stu9haCJlt+tGIMmV6PbBZlucz066jLQx2VcwqcA4bAyZYEpkCLHRMyQ/vGHaetr4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743621305; c=relaxed/simple; bh=fkR0Vzd8mzNnT68cGKzanNGlviPHtKVJhQdzXpi6kJo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=flH7qrbAFt9SBEXExIxJ0lubBZsr841vWX8D4e0GgZSdxnO0aYjB+FZVph+I9OF5QTsY6FEbMVlb4GP3pUcZ3y4PCkvzMT36gjK5Penmu/gWf7jU4u0fRxn5cvr7Fnf1GBsurHdRDJxa8u7U5UgxhzyoTLP8x+AfPaDUcWV8VCA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ETQzIP2Q; 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="ETQzIP2Q" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0F9FCC4CEE5; Wed, 2 Apr 2025 19:15:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743621305; bh=fkR0Vzd8mzNnT68cGKzanNGlviPHtKVJhQdzXpi6kJo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ETQzIP2QsM6dEzJq9iHwRkCvaG92noETM76bpJhYqELqiamOSRA6mNG6IdDMiKQi7 FW2pw5iO20PVpT0p0cdFfujrQu/4szzxEK7fVBDZCZZeaYLqkKJ/CM+X5XD0enw8S2 m5tj8KUtZfttewW17egoGh52cX8f/hi8gZd4bPElisd/sWgbSttvTuRvHsiK1ICdWL QTvQbS/lYUImV4PvmkWvH/1oFC+7bWJKpR7tVO99j2KHtYrqFcC8kv83Y0mMGcf/Sp PsAQefmdJPVyfZ+ECgvn0H/Vr2Tl0qeJ7KoCijsT2ts6/XZyCiADrr3g9VVMo5iiP2 03UKUYvGk/Vag== 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 E4B04C36018; Wed, 2 Apr 2025 19:15:04 +0000 (UTC) Date: Wed, 02 Apr 2025 21:14:13 +0200 Subject: [PATCH v3 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-v3-1-cc3da273b5b2@ixit.cz> References: <20250402-al3010-iio-regmap-v3-0-cc3da273b5b2@ixit.cz> In-Reply-To: <20250402-al3010-iio-regmap-v3-0-cc3da273b5b2@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=1211; i=david@ixit.cz; h=from:subject:message-id; bh=gTAVbM5fFc5QokjDQ95bD2qhmu90RRaffipzE9qAgeM=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn7Yy2z6bI5zDrIbRTccUfbKEF9zMRSlNwd1PrR ubGSiB3LI2JAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2MtgAKCRBgAj/E00kg ciPbD/0ehgt16z5hkaK1f7naswyW1uVnfcDGxIBm/LlIWktjEKGcdo1yeG9/NEgiE+LBTIi5iC7 yb8cox7jEr9UQB1bR+NH+hzVLRKpQqaP9+0mZx3CIDybmTIXHe9Zg9mE8YSe//02dZ31zEubA19 fDLroie4+fXRCvVMDlNUzECerX2za1s4TO8mpWDDm9CEHEKTRFTwZUIQmdanD7NnW7i2xJ4kuHs 1PHschta+u8tjvmXkZf/YVXUea817/ekz5ztXaQC/uXTxPbRn4KJrBFqhiwBPd0cjmXi4sQ//ZV utVGiW9DVUEOZEu6ObXP+dCK/WGexoN78ae44W0ecyjKQ0SzkxswZlFIhfwMPE9gf88vPV0XfO5 qDVtwdlP5u24a8y5axZccSIaYJy6MF7le0CHMcGKqTwBM5+gxvlkoY7H0qD09R2Fe9J7QbEt3sR Mj6rTqCLzxOAAm7DEBoiHqEJtqVxxIjvUIbwjYBoM4SBgGd2s5JfkkrsFO83mkJABw+6ZQtbPHO SqSlcO9D9z/haXAPhs+a+8v+ECCnj+DHRJXwonjpzbuSNO3wcuvl1DyBr7q8r/XygpMD7ZPHLoD bJYv8F+qZ0QrkTEe2XcfkpRjd0IOJWaf0+4sKo3LmseziDMzIC9rJkOEi+Ty7aVTVSp8rHrCDtM cMhGS4fORo77qUw== 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..0fcf4253864843142f1a7c61c9a92dcfbdf72a60 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(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:14:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036403 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 3FDB21442F4; Wed, 2 Apr 2025 19:15:05 +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=1743621305; cv=none; b=tQ3eQ31XvnScXkC2yb2IyZ60qYJXsQ/bS1pof2/cYeLcC8p0SbhpyY4ddwY3lc1kUyaQVBbxZTVGo9MmKLrHqaE0OLOpz/DYuZrx8638dZjQoSdZU09+OpJgqreiEuzUKvOhTgBRo4vF41fuERF9W7VgBQGBQHwr7cwT/kxzW6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743621305; c=relaxed/simple; bh=E9c72WfQkYT4uA7LVMOrVPyecs4XR7gyDQxCccTo4vc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OhosoB/Ty6HPZxt8jjbtPPz300j4Ho6EhI/frSy8HBn2DayRS2ZAAwJWrxjSWBMYBqbGnqIJjuY1tmtn637jKZkTfkWHoxC6RnPDQdImRXRDQ+27N+UBPBl1Gyzc0v9Qx2HA20fob7gKnGr8j8AGgIafpE2zv5Tjv/8UhUMPFV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E7y9aN5O; 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="E7y9aN5O" Received: by smtp.kernel.org (Postfix) with ESMTPS id 161CCC4CEE8; Wed, 2 Apr 2025 19:15:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743621305; bh=E9c72WfQkYT4uA7LVMOrVPyecs4XR7gyDQxCccTo4vc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=E7y9aN5OAPKA0CTtEDsSa/BZx1m0y6UlCBhWCs/ptW6fmsjY9CQ0hX1mG8EkopSwZ w5DUXtqQH2sMDhrLFzhQQsYtGd4MmCK5uOSJ2HKbdUGD7kMGotGPVPpPgFIBdw4jKr bxVMRtqgNBg6TnjBCIxakMzlWApwREfhy8qC/BD86wio4drcxDA66u2f0yWD+CfN8s nQzP2Duyu7FulppALEVFHfUXkGIaTisqkeHsVXyNr0nFUkEKycJZ6BZAULAFGlVB2e 0nCdmL+uW8Rb3OFio9dBBEzS7SrPuJh7Zpom6sB/1Tyvlb6Bd/CRNXMYBi7b3M/pF8 NvXyphlNO6TVg== 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 0B79FC3601E; Wed, 2 Apr 2025 19:15:05 +0000 (UTC) Date: Wed, 02 Apr 2025 21:14:14 +0200 Subject: [PATCH v3 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-v3-2-cc3da273b5b2@ixit.cz> References: <20250402-al3010-iio-regmap-v3-0-cc3da273b5b2@ixit.cz> In-Reply-To: <20250402-al3010-iio-regmap-v3-0-cc3da273b5b2@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=1374; i=david@ixit.cz; h=from:subject:message-id; bh=qQvDrqw+rZNARjQEY1+9cVvczIiceT4fSIl/q8P2uWQ=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn7Yy31DPx1wXYhRoVsBn5uORAwDaRgaCShuFJV JL6J1pc50OJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2MtwAKCRBgAj/E00kg cvYcD/0dByWa9SsXZP2okc2RI8wXLHViKiH3fw94LHQj4u+vaxOxffQunlUO+WFhK4adgWHuKgO rKM80wX+TJPzqwatOGycNRU8OkToFIOIjKAwN+YXIGkYE+dz9X071MRKrp+k2HHN7KFyVUm7zfq PLsnv7gX5g4VtbEQ0CIZrP0KD48P0xxV5eyUBuijiasz3G+LS/G+L1QIpkdCzlarnd6r2+GZ+oj IQnRy5Kk0zOmX9euaNty73QuLGKXoHWX9E8NctDu77wHVzZCQzhWlNPsOWrvgvM8Zx2k4lpXvbP Udxbg3q10uByIiX/co+SwtaFEnnQbkNAJOB7waW2Wsy5cpkadMHGRrYFMmp54Kcu6DjmXZWL93N XPw2CeCytmMZjWF51q0QZRRb+1emZQm3OreZo+EeTaCk3u36f+Qao1+qWvJ52WH2QO/0o4j97F/ aYsEM1TWb1doyhj/NjC9QP7ClyoAfYELDlFYtGk60tVnVVqUqi5HeDoRVhIIMdweaAqWk4r7JKE usgj0VfEzLoENT8ajWBWdYTBrO0F3bMkjzz/XbgIaFHfDBqhyJAyNOOgMVFfu1t3V1IsIT1wZep R4W84Qak9Fx7alNLvb+Hq9pg3O7Ltu+083faecfCU9dLFJabamMNMHwOn1BlllZUfKTaSiICZ7+ Aop13hKPWeMvfqQ== 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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/light/al3000a.c b/drivers/iio/light/al3000a.c index e2fbb1270040f43d9f0a97838861818a8eaef813..e6208bfeb3be9040364463ef6d59a15d31e8700c 100644 --- a/drivers/iio/light/al3000a.c +++ b/drivers/iio/light/al3000a.c @@ -91,6 +91,10 @@ static int al3000a_init(struct al3000a_data *data) if (ret) return ret; + ret = devm_add_action_or_reset(&data->client->dev, al3000a_set_pwr_off, data); + if (ret) + return dev_err_probe(&data->client->dev, ret, "failed to add action\n"); + ret = regmap_write(data->regmap, AL3000A_REG_SYSTEM, AL3000A_CONFIG_RESET); if (ret) return ret; @@ -157,10 +161,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:14:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036408 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 B85701EE028; Wed, 2 Apr 2025 19:15:05 +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=1743621306; cv=none; b=Xt866Vs34EjcMiUkugRGc64ANNJScADloPpyRaohOJJUpx1fRVMcfnP8zHqDwUcUGfI3gxWXmwJA0imESM4EgyYUCWjB3WiE+m9m4C1Z3K5f/FKHrwT89KscE8pHlKUnji3qB9WuGGFrWFJdcvj7thSPxwYIat2F5GgQFOgOBXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743621306; c=relaxed/simple; bh=t8SlwYvfr0dVPDmeuPmUptlt1LXH2OgT7yF+9hGe7LY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Yzbc5/32h7LIAiOwHBVzPYNvP5JRDxdfJmeQGq0m+VyEdaTTmAw5047E0HvqrHdBMAmgolNYx7MtZEP90AkfG5NQ7L8/9w6f1dwwPLUaknj6stXihVyUHalpUbGXn2x4pW+Dpn7K0otyxcUEdBy9V8VVHRqG3IksegHlE7Nyz54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dc78sARN; 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="dc78sARN" Received: by smtp.kernel.org (Postfix) with ESMTPS id 2B2A9C4CEEB; Wed, 2 Apr 2025 19:15:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743621305; bh=t8SlwYvfr0dVPDmeuPmUptlt1LXH2OgT7yF+9hGe7LY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=dc78sARNgxchz/KgHK9dXtQWdCPhhIeHRmGmv5a/McmuVhRgbveu2A4T0YQUVKmJz FFz3/SW2XdggyUgiEETH4aeEHB/o0fcKaW7VD1k0KWjcguRATsAteYLNpqL8d6W/xD 6rHgXsr61/zQ3xcYpBJNUB5aXg59AZB9xfz2vY9jN2yrZDi62nrkdbhnmvrR47nSNF pb0fSiufIb/WFs8bkEDBVAxtCvDEkF8fG1JLaHPtmIQviy8OzQvuKg37luQkCxECOf 5T+fM3V4oHYNbQNPkoLYD4Bx8wk4VRsVcmL2ponuPCYoDkHvi9O6LCXblxgi9ARJO3 eUc4BudRqxcpQ== 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 20420C3601B; Wed, 2 Apr 2025 19:15:05 +0000 (UTC) Date: Wed, 02 Apr 2025 21:14:15 +0200 Subject: [PATCH v3 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-v3-3-cc3da273b5b2@ixit.cz> References: <20250402-al3010-iio-regmap-v3-0-cc3da273b5b2@ixit.cz> In-Reply-To: <20250402-al3010-iio-regmap-v3-0-cc3da273b5b2@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=1336; i=david@ixit.cz; h=from:subject:message-id; bh=xUR9gZOnjOoo0snJLgIn15f7Ro6lut1DvCDtNBnZliU=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn7Yy3HOIVp0gNPuYuFIC9TWknQMBqKiZtTfBDQ NHggVCvdbOJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2MtwAKCRBgAj/E00kg ci+oEACT4SQ9qhj6AogU5XSeGSWVeoJmSF1/gDjIJFsYEk4x+IMWOilEld9etR8R9AVLgIIUz2N M9XEf73ktQ/UQNqq1Y6qRuRvWCOWW7QLYMFR6g0ufFcxfMRwQTpHfEQrTJfWfAvR5iDxuwqW7aD AhqQOR0tskfNAd4UTdWkKWqILRrcJW1Md9422fRpwNlFasiCAKMhaoGltqJULcFclEAw4y0eVtK 6w+LB1dR4R8YOU1kQmMJ6a6BzjpYezVSK6dOIBUw6L0UhO2ZDRWvXXPIntRIHq62Gg5XfCt0cXd Y4LIdBmPwonGzkVzGkBXeybA1dd7rDtXvdqv+eB3NRt0Um6+swHgVKDA2/BXkwwt/88/5e8afj7 ph4GQH84p1GCEeudA5uGU64zN29pbQ8T+UpesfiT3XT2FV5siAuNedItlWrxu6bVJZBiVx/eGAH JlfIVjOvS3Qc77l+RODFHHDMySEZuQc8gnqN5isvQpjivajDa49PcikSQqZnHbAq5hhTsdRfGpb zJuJAeAIlyPpDH9c7R06S9WVyu9EpEcC7ceiWSQXrBXiaOmatqCvuAIb5NBXjIU+Bsvs24nJw5j YHDpQE6BMy8L2TIMAfn+VlR993h+krjuEwYaXVeN2FTjJN9uLTZ9vLqKPPRz3OMeGA8XOJlQqX+ 53gPEkok5JDFmDw== 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..005a7664568667b5cf9419baba6764f7b4e8fc39 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(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:14:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036404 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 6D30C1E5B82; Wed, 2 Apr 2025 19:15:05 +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=1743621305; cv=none; b=UTU+PW9hzRwQ8dB/ReOdmC5akeQz5gNstq7j3X/JAEfKHFSfVzTil2WG/H9dmlEq7RtYcLrSBEHQJFYiAFvqx1ZW2XTNxNPqiSE7PVZl76JALbStgsg4JMIxOVaxp4F1MMoeKViW4Yct1HiRypTmAgwsSVKZrwl3w5V/UvizFdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743621305; c=relaxed/simple; bh=bLvZgpoRz8jPTh6lztF4LgifJrv5YjqT/zfMYLdKTtQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RubK9Z5zKyB6wHIHaAspCJyLoLkVzla6QfCcGdx5DdUY20foeT4eA7Y0szsrjZD6Wr6J4sXhjH6le4sHEotbgZ9NFlFljEtLxcV3IU7PpDZs9MWang1Mxfg/NOICblCSwBvhkr5DhQcFMmkjFBTjn2LkheDkPAjm5Ra0UaI5TMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sGoMlOT3; 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="sGoMlOT3" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3BEF3C4CEEF; Wed, 2 Apr 2025 19:15:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743621305; bh=bLvZgpoRz8jPTh6lztF4LgifJrv5YjqT/zfMYLdKTtQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=sGoMlOT3vJS/TpvtfN9gVMLFn+sUX2ShdsJYsVg6Dmfwvk5SeDzxaafguJ86GuOYa PQ6KixY8CWTZZN2M+9L5P4C999M+22/EGQAsdZg3JdltyRm8KVaQQodTmUmpL/kJ5f Z+W3DwMaqS2Zja8YndiJ3yNKjwD22eTdRfK0RtKNbVIATUj5POnG/W4qP+u2Vz5BGk m0oBTW2gJwQCM4JYZaTKbVqkSj25rUodC2t/+aQNQcPJOGzjtuuKeqWEeWzyKnFxvQ s71gash6ghZmQzuWL/TtJPdteH4uxAQuRRYx7hFHiez0lmqpp2vSibgmP0JrA6wzvy acGsZdq703VaQ== 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 330AFC36018; Wed, 2 Apr 2025 19:15:05 +0000 (UTC) Date: Wed, 02 Apr 2025 21:14:16 +0200 Subject: [PATCH v3 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-v3-4-cc3da273b5b2@ixit.cz> References: <20250402-al3010-iio-regmap-v3-0-cc3da273b5b2@ixit.cz> In-Reply-To: <20250402-al3010-iio-regmap-v3-0-cc3da273b5b2@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=5266; i=david@ixit.cz; h=from:subject:message-id; bh=4vlK8//koSebmXkgSEu7I6tvaU7BCe4QTWz6vNOOPy4=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn7Yy3dSiY3P5FEwr6FbRuqLC2xrgbJeThC+Aj0 5TxyVY4uTKJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2MtwAKCRBgAj/E00kg cpcmD/4gg5LEUZZjOsXWowRTOCXw6XaR+zbllg5MjXNsezuh27prCaaUs7I57Ey7ZDkAhgz+SNz b1aEFuOzT9GY0InUWymY460jXCw+FpWsZp2YV1Co59V6/9o9Vt1YO9B6S+YYPsaJyEM9Ep352zs CBYORfKjdILSG/hYQl2FHjE2a9B7S2Cgnj4EL8coOlxLipMdcOruN59OwdXCnm6N6JDVeE1L69n 5FGnm4MkWuMWZl1Y1YEXxRCY+ayVhEuzIJKfmtkC5HfkdZNa0EzeDyaV+lJbKskaKhbu9pgajgu pq40UWcjWKryw065sXmeLzXlXJs7ZiUG6Iyei38lv5Nc5x3pUaGpaRvSPndgejPlMUUpX9wD0+O IGeNYnZv0ESk5VzX5/o0U6tF+PBK4WXs7ui4xl5Gdi/bqEpAm73Pz5Pcdam3RlLHZLcOGjP75S1 2PimfxbXqIb+pnf4aLFeFs7cySLFKxBwc3rOOrIIDCG32A+bkR+9F3Q+hsyo66pKBTky2bo/Sb2 o30K6GWfj/Eb13u96Mw28vDW7wRnZhbR+FPUNqjtL4XdPaPCG1ziWrh1GDxHvQ7eSvtoEzvfhOi IX04Cfl11QXK/TH7JeMCn3swZt1zFXVKLBivBkX78wm0Z48xqmrYdMMhKJhlfbn66pO4HR6R069 42VvoDiPnJ5sVew== 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 | 72 +++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/drivers/iio/light/al3010.c b/drivers/iio/light/al3010.c index 0fcf4253864843142f1a7c61c9a92dcfbdf72a60..03ea3c7c03fbdb4e818a6524a1c6f2209320753b 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,38 @@ 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) { 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); if (ret) - return dev_err_probe(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(&data->client->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 +113,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 +122,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 +157,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 +184,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 +212,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:14:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036407 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 A4A5C1E9907; Wed, 2 Apr 2025 19:15:05 +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=1743621305; cv=none; b=eWAko5hzwwQ9+kgt1vfmwel47Qkj6qi5BngQg5Ks4zPGZmGMpLHktK7T2ys0N8wnULDtNHYk12+OCqrqcJjnH1Q/T/PcG/6BZRBjPJeYXnpMbw1Rjc1WDFPnCLZG2kXAwCWYvb/xPpOmHC5ozfd08SRuuhSaa0xyVorlcOUCkn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743621305; c=relaxed/simple; bh=/6ORwPGEylk2ensJ45ZIl+JuJVNYG1Rvk/NerUkupug=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V5UohpC9Ci6YuYPzuKjcRVlAXioRVfmAt1yEhta5ewxEPK3Dmi9EeLIF7GiJSc7pL+78asKGPGhX9oJjpJ15aZ4X+dtENMtflO10vUfmERK1hx1L83sK+f/2l0ORFzx3AJgfV/YHrLe6Z+tp0kitYUGQ5rGrn+p5wByaOBKkR+A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PzhYOeS4; 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="PzhYOeS4" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7B141C4CEEA; Wed, 2 Apr 2025 19:15:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743621305; bh=/6ORwPGEylk2ensJ45ZIl+JuJVNYG1Rvk/NerUkupug=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=PzhYOeS4NRLsh4sJf+eypzdtQPJJxbI3KdhTBTmR0KJgQqMhHXj4PoMYSR7I4c0vk rhcXGW5M9WQMt4hTgHjDM0zB+poLLZno9n1tY9qrdHZsU7LF9N/KpLLL9iC40V7Pmv oQjcbov0CjyaZodOAGwSmXbZDUlmboTPKShiCU4/7LT0C0skkoFXLlPENABvDgEfN9 zkJFGn/Z7NUwq5Mj/f+QuEkXayIX2Kn5frzgI65KI0CPM95JsqmKQ/aaLQ1G/iwjTE +kVRE0Rg6FYgWOOowDzU+c7QyStLSTBbuTzHrWh+zvPMpnjiUSO8lR2EodG9r4TaKp FbskvvKeG0ZWQ== 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 72CB4C3601B; Wed, 2 Apr 2025 19:15:05 +0000 (UTC) Date: Wed, 02 Apr 2025 21:14:17 +0200 Subject: [PATCH v3 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-v3-5-cc3da273b5b2@ixit.cz> References: <20250402-al3010-iio-regmap-v3-0-cc3da273b5b2@ixit.cz> In-Reply-To: <20250402-al3010-iio-regmap-v3-0-cc3da273b5b2@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=5785; i=david@ixit.cz; h=from:subject:message-id; bh=VF2IB659WVA5EWuUppV3rVlQHRbT5K4V8Zm1qxQVpcY=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn7Yy3UYYbdVwzWjvefWbwlC9fPFuWVa7X+c7J7 glWpj6MxlSJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2MtwAKCRBgAj/E00kg cnieEADOUjVWO+EZ7SnPPLT/MviCrwZLrkrhnBolAMv/Mc9PWIh5Frxn77DKupA0yQlvNw4wSx0 rqV3rk3g70E0v/hr3Xchouc9htwHFLMqwLY4POatTRIH83HvX8BvTACMT2xxHhCGcdxEdz57Uby uJ5GJxfOPn59l6wfgsG/gc7JXH0HUYUoWFAq61IGyD5/XZ16J3XW1eeJ7vad5b8fvWta644tSlz TKB4n+cF6yQA5mV9lfoSZqs/3mfjon7M5Opt/HKvkzuH8QLg7s7RGHCCufwU2C348OZGTgg5Oa8 RyA4WuygFPrBYWY+38Pk64b+Q932ZOgKG5GNkjmxOtKfGcHtf5/U3S3331xlf/0DqFg1SS95voE f7BGR3I5R81U0U2l00q5rI+CPmaC7EnpwwWGQEOaq4na+ZYK5GfuFYErwkkzrm4+OOR6Fo590vw dipW06/DWvZqKN+uSeBbjvRkbsAS8aFz231pplz7KpEutM1ocyzX7Wnd+izdHtzS6Jy5J0no3zq 5MiYZKLyo23Jd4UwIzcOJUmBkZgOGomYkZLk1A/9AJqiX3pYV00OhVgtWkSJHJV4HyEVuT/BhQI Mrfgocgel+YmxN+iM0Inss30L4K/Ewifwdd3B/kp9e50mhvOszCY3ztpuLSP9i1qjx043OzmfFr ZiINJ5K29vUxqSA== 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 | 82 +++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/drivers/iio/light/al3320a.c b/drivers/iio/light/al3320a.c index 005a7664568667b5cf9419baba6764f7b4e8fc39..05b6ec217ee8103e3527948aa2da1af75c2a495e 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,25 +87,28 @@ 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) { 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, @@ -107,23 +117,18 @@ static int al3320a_init(struct al3320a_data *data) if (ret) return dev_err_probe(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; - - 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 +136,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 +145,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 +180,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 +207,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 +238,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,