From patchwork Tue Dec 5 17:06:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13480479 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 42BA46928B for ; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fWCauffX" Received: by smtp.kernel.org (Postfix) with ESMTPS id D6B03C433C8; Tue, 5 Dec 2023 17:06:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701796005; bh=sjUP64TzXG9MuFbyLhkat8sU5mUfln6N25I4AI6lZW0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=fWCauffXAr1RSJQrWGF6ToyLzYPNsA35GhEGLDUxj2GR7J9x1frONNv6Rp71T4Aag EEcRggcOnZDMReTdShPqVmuP9CYODD1XvOow9DD3n1mcdmC2gvFrpmh5Nd4wjdht6x /8N/7eNaNbAyIAJtiwuBhUunqYTPbxeeHGPLyNQnPW/Vxa3nuJ6xu7oYoKn66OOY8l 31VkB5eCrvUBBG1yXqm6/uSyqAh0+6yBXkfHXIEOLN/sQXjVwdI+h3JKKdIUuiRfb6 HQU3ojW+UJfZrVD437+0bUbUKGT6oGG0mhc12XP3bOTF8guzKxkXlKx5HPjInnxDlA XLnmSq3240H5Q== 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 BBC7EC10DCE; Tue, 5 Dec 2023 17:06:45 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 05 Dec 2023 18:06:41 +0100 Subject: [PATCH 1/8] iio: adc: ad9467: fix reset gpio handling Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231205-iio-backend-prep-v1-1-7c9bc18d612b@analog.com> References: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> In-Reply-To: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> To: linux-iio@vger.kernel.org Cc: Michael Hennerich , Jonathan Cameron , Lars-Peter Clausen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1701796004; l=2385; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=jSRdyxiCoJT95OyuOsgiz/xzqOuZXfUDVd39nEe6GjE=; b=ViXcMuziGM9kkRx+zo9zzYxxHcv50HWzMMyeuuuNIjTMWFTsN84xbPWzgXPFBHN2VtjwGpT0j C1dExWSO4JXDq/HRf7tH8vhFiwIj70c4SGMyyHXCE58QF418LF4/IPu X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: From: Nuno Sa The reset gpio was being requested with GPIOD_OUT_LOW which means, not asserted. Then it was being asserted but never de-asserted which means the devices was left in reset. Fix it by de-asserting the gpio. While at it, moved the handling to it's own function and dropped 'reset_gpio' from the 'struct ad9467_state' as we only need it during probe. On top of that, refactored things so that we now request the gpio asserted (i.e in reset) and then de-assert it. Also note that we now use gpiod_set_value_cansleep() instead of gpiod_direction_output() as we already request the pin as output. Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC") Signed-off-by: Nuno Sa Reviewed-by: David Lechner --- drivers/iio/adc/ad9467.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index 39eccc28debe..5ecf486bf5d1 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -121,7 +121,6 @@ struct ad9467_state { unsigned int output_mode; struct gpio_desc *pwrdown_gpio; - struct gpio_desc *reset_gpio; }; static int ad9467_spi_read(struct spi_device *spi, unsigned int reg) @@ -378,6 +377,23 @@ static int ad9467_preenable_setup(struct adi_axi_adc_conv *conv) return ad9467_outputmode_set(st->spi, st->output_mode); } +static int ad9467_reset(struct device *dev) +{ + struct gpio_desc *gpio; + + gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(gpio)) + return PTR_ERR(gpio); + if (!gpio) + return 0; + + fsleep(1); + gpiod_set_value_cansleep(gpio, 0); + fsleep(10 * USEC_PER_MSEC); + + return 0; +} + static int ad9467_probe(struct spi_device *spi) { const struct ad9467_chip_info *info; @@ -408,18 +424,9 @@ static int ad9467_probe(struct spi_device *spi) if (IS_ERR(st->pwrdown_gpio)) return PTR_ERR(st->pwrdown_gpio); - st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", - GPIOD_OUT_LOW); - if (IS_ERR(st->reset_gpio)) - return PTR_ERR(st->reset_gpio); - - if (st->reset_gpio) { - udelay(1); - ret = gpiod_direction_output(st->reset_gpio, 1); - if (ret) - return ret; - mdelay(10); - } + ret = ad9467_reset(&spi->dev); + if (ret) + return ret; conv->chip_info = &info->axi_adc_info; From patchwork Tue Dec 5 17:06:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13480483 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 42B1B69288 for ; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RJEFcU1K" Received: by smtp.kernel.org (Postfix) with ESMTPS id DF553C433C9; Tue, 5 Dec 2023 17:06:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701796005; bh=kScHFZZto0r+oZaxi1gWjEB/h2Q2xGCAhset1wXcg9w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=RJEFcU1KXLgMmZDPUfEreDnXOzzXwDzdON4W9EXHTkwPk1+Svs99989+080/U2Mh5 hN7/YTylkoib5H5QoVtZg30RM/AkdtSjoIOHbS51WSJaHq9wPMceD9TSL0clMXFIrc vwBbTqBDerBCWM4qyqWnor0LKfdyoV6S6ba2jhTb6SSenELm1aATvoiik6PZhsOEvt 3vtsVQldD6CXib7PF8JP1HYhEUvJB6ra5Fbgsv6YJKJviIs7k8XxEl0/As0m61bWfL w5hRZxl35JPIhcS/7y43VeRbBE6HQNl32CZr3b2gcG3g/Hle5c0cWpJXoEaJrT4nda 1wkA3Atlx1EQw== 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 C5EDDC46CA0; Tue, 5 Dec 2023 17:06:45 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 05 Dec 2023 18:06:42 +0100 Subject: [PATCH 2/8] iio: adc: ad9467: don't ignore error codes Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231205-iio-backend-prep-v1-2-7c9bc18d612b@analog.com> References: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> In-Reply-To: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> To: linux-iio@vger.kernel.org Cc: Michael Hennerich , Jonathan Cameron , Lars-Peter Clausen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1701796004; l=2369; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=Yp88xt+p4CeVtKT4sRsURqn6TKhQ4aZcgz2tzeg6i/s=; b=aPjXwGNyNzaF6mAwYtziiGvIbC+zEmbfuA2K/pwV3e9T0nnGKVnXQcUHfCbLpbj187IRy2p3t bvrOuPWC8EjCEgZTXkd4nifiQZmZL7P8NG+xJrs3OlicQBP9GX5JcwL X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: From: Nuno Sa Make sure functions that return errors are not ignored. Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC") Signed-off-by: Nuno Sa Reviewed-by: David Lechner --- drivers/iio/adc/ad9467.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index 5ecf486bf5d1..0f2dce730a0a 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -162,9 +162,10 @@ static int ad9467_reg_access(struct adi_axi_adc_conv *conv, unsigned int reg, if (readval == NULL) { ret = ad9467_spi_write(spi, reg, writeval); - ad9467_spi_write(spi, AN877_ADC_REG_TRANSFER, - AN877_ADC_TRANSFER_SYNC); - return ret; + if (ret) + return ret; + return ad9467_spi_write(spi, AN877_ADC_REG_TRANSFER, + AN877_ADC_TRANSFER_SYNC); } ret = ad9467_spi_read(spi, reg); @@ -272,10 +273,13 @@ static int ad9467_get_scale(struct adi_axi_adc_conv *conv, int *val, int *val2) const struct ad9467_chip_info *info1 = to_ad9467_chip_info(info); struct ad9467_state *st = adi_axi_adc_conv_priv(conv); unsigned int i, vref_val; + int ret; - vref_val = ad9467_spi_read(st->spi, AN877_ADC_REG_VREF); + ret = ad9467_spi_read(st->spi, AN877_ADC_REG_VREF); + if (ret < 0) + return ret; - vref_val &= info1->vref_mask; + vref_val = ret & info1->vref_mask; for (i = 0; i < info->num_scales; i++) { if (vref_val == info->scale_table[i][1]) @@ -296,6 +300,7 @@ static int ad9467_set_scale(struct adi_axi_adc_conv *conv, int val, int val2) struct ad9467_state *st = adi_axi_adc_conv_priv(conv); unsigned int scale_val[2]; unsigned int i; + int ret; if (val != 0) return -EINVAL; @@ -305,11 +310,13 @@ static int ad9467_set_scale(struct adi_axi_adc_conv *conv, int val, int val2) if (scale_val[0] != val || scale_val[1] != val2) continue; - ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, - info->scale_table[i][1]); - ad9467_spi_write(st->spi, AN877_ADC_REG_TRANSFER, - AN877_ADC_TRANSFER_SYNC); - return 0; + ret = ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, + info->scale_table[i][1]); + if (ret < 0) + return ret; + + return ad9467_spi_write(st->spi, AN877_ADC_REG_TRANSFER, + AN877_ADC_TRANSFER_SYNC); } return -EINVAL; From patchwork Tue Dec 5 17:06:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13480481 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 4F01869295 for ; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JJluzrx3" Received: by smtp.kernel.org (Postfix) with ESMTPS id E8800C433CB; Tue, 5 Dec 2023 17:06:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701796006; bh=DaHrib+sTZO8JDKwkqWnkVTCyGR/kWgXeCaVSnxuHwI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=JJluzrx356IN4ryQMt3P/32hsop/PY12c5QwMK1+bUAJz5W/0gkV2JRnVNm8RKCOE vZeKu71lGBiuwRv3aysW1tciC8i7OvOmNlqhtAbXucBu60INCb9uWwbxYHgbVVAJ+3 k+gAUA+sy/4YM5JipLiZxqvHkQBycKKvrUZ7C4AtRrGOKsW8r8O6h9HVZK4962PZU7 qL7nwKYfMb5mokPiex0tM82rK194+B8i/uvZRykrqK8fzIXtGFRNMH/NipaLiEZMll d4wxYag1AuYb6weXnnJ5oPBNYajaIjhBzZxSdyzpleEIvV2jbbETAytj+AtwR3ae58 ZSU/cfyVlO/gQ== 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 D1CA7C07E97; Tue, 5 Dec 2023 17:06:45 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 05 Dec 2023 18:06:43 +0100 Subject: [PATCH 3/8] iio: adc: ad9467: add mutex to struct ad9467_state Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231205-iio-backend-prep-v1-3-7c9bc18d612b@analog.com> References: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> In-Reply-To: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> To: linux-iio@vger.kernel.org Cc: Michael Hennerich , Jonathan Cameron , Lars-Peter Clausen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1701796004; l=1696; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=p8tduALMO1r7IbePJPY0Lc0yef4vRn/57H1G59OPIGE=; b=B0qup201Yzg8CckSdwz51Krqv80mIBFSdso8cdYL+njub3wLOeyaCY6flSfz1AOM/lx5yLif5 YrKHM6SllqpD2AVXJkPh6YwjuqY/TkT1gMK4imfO7osUMaFtD6Tobdm X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: From: Nuno Sa When calling ad9467_set_scale(), multiple calls to ad9467_spi_write() are done which means we need to properly protect the whole operation so we are sure we will be in a sane state if two concurrent calls occur. Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC") Signed-off-by: Nuno Sa --- drivers/iio/adc/ad9467.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index 0f2dce730a0a..badbef2ce9f8 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -4,8 +4,9 @@ * * Copyright 2012-2020 Analog Devices Inc. */ - +#include #include +#include #include #include #include @@ -121,6 +122,8 @@ struct ad9467_state { unsigned int output_mode; struct gpio_desc *pwrdown_gpio; + /* ensure consistent state obtained on multiple related accesses */ + struct mutex lock; }; static int ad9467_spi_read(struct spi_device *spi, unsigned int reg) @@ -161,6 +164,7 @@ static int ad9467_reg_access(struct adi_axi_adc_conv *conv, unsigned int reg, int ret; if (readval == NULL) { + guard(mutex)(&st->lock); ret = ad9467_spi_write(spi, reg, writeval); if (ret) return ret; @@ -310,6 +314,7 @@ static int ad9467_set_scale(struct adi_axi_adc_conv *conv, int val, int val2) if (scale_val[0] != val || scale_val[1] != val2) continue; + guard(mutex)(&st->lock); ret = ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, info->scale_table[i][1]); if (ret < 0) From patchwork Tue Dec 5 17:06:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13480482 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 4F05E69296 for ; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rskBMD5f" Received: by smtp.kernel.org (Postfix) with ESMTPS id 032BAC433CC; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701796006; bh=D2BYR7QCNhtNSgy1AlltqhD+2MENBWdudecgQXTK4Ug=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rskBMD5fr0zCj33IMrECP6LLIzUjLDex04O1xjWsYpOuKWwxvfW4mHyiJzUjBXNL2 onq/sEp0M1DaNywab7XswxF5KmRdcaknfx2ZK4FK0F3atzbH0OGOi7cUI2N7fsmUGL hHsTz/pq3bUF+UasZKNzUyQrU0HQNLw433YY1FmYXtRj/XUippAXc00Qo4SP8y80QS 7iBF2hMhQxBe1izPa2FAcgjXQJinoHgw3O9I03Q8oKRGGbGCOuJcYfHsNBdWlfjfMz w+3zlzzN11oAqXx4hLbIRh5mFDCZhsKN1KGtGbjwZUwo/lt2RMkpDyrko6fKfU+ehF ebkyzVOy5HquQ== 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 DFA04C46CA3; Tue, 5 Dec 2023 17:06:45 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 05 Dec 2023 18:06:44 +0100 Subject: [PATCH 4/8] iio: adc: ad9467: fix scale setting Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231205-iio-backend-prep-v1-4-7c9bc18d612b@analog.com> References: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> In-Reply-To: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> To: linux-iio@vger.kernel.org Cc: Michael Hennerich , Jonathan Cameron , Lars-Peter Clausen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1701796004; l=8225; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=z1Bj5nPWxaSA7iWZZc2SWPauBJoz1JQZRSjY+a7l1aE=; b=3IRyhmqEmn6VnhgtKPsJ/hXG8MYDgKwOcj1JJRWOvIgfcp0O2TXcEyIbGFpEqra0kjNIHBhOz 7yVGH0fNVIRDUUbvAtAAJQi+65Y4HxdftHROwT6SQcrA08SIn1v1rqt X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: From: Nuno Sa When reading in_voltage_scale we can get something like: root@analog:/sys/bus/iio/devices/iio:device2# cat in_voltage_scale 0.038146 However, when reading the available options: root@analog:/sys/bus/iio/devices/iio:device2# cat in_voltage_scale_available 2000.000000 2100.000006 2200.000007 2300.000008 2400.000009 2500.000010 which does not make sense. Moreover, when trying to set a new scale we get an error because there's no call to __ad9467_get_scale() to give us values as given when reading in_voltage_scale. Fix it by computing the available scales during probe and properly pass the list when .read_available() is called. While at it, change to use .read_available() from iio_info. Also note that to properly fix this, adi-axi-adc.c has to be changed accordingly. Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC") Signed-off-by: Nuno Sa --- drivers/iio/adc/ad9467.c | 47 +++++++++++++++++++++++ drivers/iio/adc/adi-axi-adc.c | 74 ++++++++----------------------------- include/linux/iio/adc/adi-axi-adc.h | 4 ++ 3 files changed, 66 insertions(+), 59 deletions(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index badbef2ce9f8..3c8bd6c821a4 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -120,6 +120,7 @@ struct ad9467_state { struct spi_device *spi; struct clk *clk; unsigned int output_mode; + unsigned int (*scales)[2]; struct gpio_desc *pwrdown_gpio; /* ensure consistent state obtained on multiple related accesses */ @@ -216,6 +217,7 @@ static void __ad9467_get_scale(struct adi_axi_adc_conv *conv, int index, .channel = _chan, \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE), \ .scan_index = _si, \ .scan_type = { \ .sign = _sign, \ @@ -370,6 +372,26 @@ static int ad9467_write_raw(struct adi_axi_adc_conv *conv, } } +static int ad9467_read_avail(struct adi_axi_adc_conv *conv, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + const struct adi_axi_adc_chip_info *info = conv->chip_info; + struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + *vals = (const int *)st->scales; + *type = IIO_VAL_INT_PLUS_MICRO; + /* Values are stored in a 2D matrix */ + *length = info->num_scales * 2; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } +} + static int ad9467_outputmode_set(struct spi_device *spi, unsigned int mode) { int ret; @@ -382,6 +404,26 @@ static int ad9467_outputmode_set(struct spi_device *spi, unsigned int mode) AN877_ADC_TRANSFER_SYNC); } +static int ad9467_scale_fill(struct adi_axi_adc_conv *conv) +{ + const struct adi_axi_adc_chip_info *info = conv->chip_info; + struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + unsigned int i, val1, val2; + + st->scales = devm_kcalloc(&st->spi->dev, ARRAY_SIZE(*st->scales), + info->num_scales, GFP_KERNEL); + if (!st->scales) + return -ENOMEM; + + for (i = 0; i < info->num_scales * 2; i++) { + __ad9467_get_scale(conv, i, &val1, &val2); + st->scales[i][0] = val1; + st->scales[i][1] = val2; + } + + return 0; +} + static int ad9467_preenable_setup(struct adi_axi_adc_conv *conv) { struct ad9467_state *st = adi_axi_adc_conv_priv(conv); @@ -442,6 +484,10 @@ static int ad9467_probe(struct spi_device *spi) conv->chip_info = &info->axi_adc_info; + ret = ad9467_scale_fill(conv); + if (ret) + return ret; + id = ad9467_spi_read(spi, AN877_ADC_REG_CHIP_ID); if (id != conv->chip_info->id) { dev_err(&spi->dev, "Mismatch CHIP_ID, got 0x%X, expected 0x%X\n", @@ -452,6 +498,7 @@ static int ad9467_probe(struct spi_device *spi) conv->reg_access = ad9467_reg_access; conv->write_raw = ad9467_write_raw; conv->read_raw = ad9467_read_raw; + conv->read_avail = ad9467_read_avail; conv->preenable_setup = ad9467_preenable_setup; st->output_mode = info->default_output_mode | diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index aff0532a974a..ae83ada7f9f2 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -144,6 +144,20 @@ static int adi_axi_adc_write_raw(struct iio_dev *indio_dev, return conv->write_raw(conv, chan, val, val2, mask); } +static int adi_axi_adc_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + struct adi_axi_adc_state *st = iio_priv(indio_dev); + struct adi_axi_adc_conv *conv = &st->client->conv; + + if (!conv->read_avail) + return -EOPNOTSUPP; + + return conv->read_avail(conv, chan, vals, type, length, mask); +} + static int adi_axi_adc_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask) { @@ -228,69 +242,11 @@ struct adi_axi_adc_conv *devm_adi_axi_adc_conv_register(struct device *dev, } EXPORT_SYMBOL_NS_GPL(devm_adi_axi_adc_conv_register, IIO_ADI_AXI); -static ssize_t in_voltage_scale_available_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct adi_axi_adc_state *st = iio_priv(indio_dev); - struct adi_axi_adc_conv *conv = &st->client->conv; - size_t len = 0; - int i; - - for (i = 0; i < conv->chip_info->num_scales; i++) { - const unsigned int *s = conv->chip_info->scale_table[i]; - - len += scnprintf(buf + len, PAGE_SIZE - len, - "%u.%06u ", s[0], s[1]); - } - buf[len - 1] = '\n'; - - return len; -} - -static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0); - -enum { - ADI_AXI_ATTR_SCALE_AVAIL, -}; - -#define ADI_AXI_ATTR(_en_, _file_) \ - [ADI_AXI_ATTR_##_en_] = &iio_dev_attr_##_file_.dev_attr.attr - -static struct attribute *adi_axi_adc_attributes[] = { - ADI_AXI_ATTR(SCALE_AVAIL, in_voltage_scale_available), - NULL -}; - -static umode_t axi_adc_attr_is_visible(struct kobject *kobj, - struct attribute *attr, int n) -{ - struct device *dev = kobj_to_dev(kobj); - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct adi_axi_adc_state *st = iio_priv(indio_dev); - struct adi_axi_adc_conv *conv = &st->client->conv; - - switch (n) { - case ADI_AXI_ATTR_SCALE_AVAIL: - if (!conv->chip_info->num_scales) - return 0; - return attr->mode; - default: - return attr->mode; - } -} - -static const struct attribute_group adi_axi_adc_attribute_group = { - .attrs = adi_axi_adc_attributes, - .is_visible = axi_adc_attr_is_visible, -}; - static const struct iio_info adi_axi_adc_info = { .read_raw = &adi_axi_adc_read_raw, .write_raw = &adi_axi_adc_write_raw, - .attrs = &adi_axi_adc_attribute_group, .update_scan_mode = &adi_axi_adc_update_scan_mode, + .read_avail = &adi_axi_adc_read_avail, }; static const struct adi_axi_adc_core_info adi_axi_adc_10_0_a_info = { diff --git a/include/linux/iio/adc/adi-axi-adc.h b/include/linux/iio/adc/adi-axi-adc.h index 52620e5b8052..b7904992d561 100644 --- a/include/linux/iio/adc/adi-axi-adc.h +++ b/include/linux/iio/adc/adi-axi-adc.h @@ -41,6 +41,7 @@ struct adi_axi_adc_chip_info { * @reg_access IIO debugfs_reg_access hook for the client ADC * @read_raw IIO read_raw hook for the client ADC * @write_raw IIO write_raw hook for the client ADC + * @read_avail IIO read_avail hook for the client ADC */ struct adi_axi_adc_conv { const struct adi_axi_adc_chip_info *chip_info; @@ -54,6 +55,9 @@ struct adi_axi_adc_conv { int (*write_raw)(struct adi_axi_adc_conv *conv, struct iio_chan_spec const *chan, int val, int val2, long mask); + int (*read_avail)(struct adi_axi_adc_conv *conv, + struct iio_chan_spec const *chan, + const int **val, int *type, int *length, long mask); }; struct adi_axi_adc_conv *devm_adi_axi_adc_conv_register(struct device *dev, From patchwork Tue Dec 5 17:06:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13480486 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 6FD726929F for ; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="knwV4FNa" Received: by smtp.kernel.org (Postfix) with ESMTPS id 03984C433D9; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701796006; bh=9euPM8fcQcmDfI+ietptv8VMBXvl4pFwlJit+YP43hY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=knwV4FNaLnAaQl/xK8CWaLx1G7Yj//jbQJrbT8/H7DU7STbtdsbNCJGeLUp0GPs4Q zH02FjN5IMkY4qQ9kEjZKZEpNiLloiIDBq4ztN3o+6hOquckcYlsPkvNYl3UkMIOA6 WZm0HN2OESQkqxnJrWyYhoLKBEFakI2t7ghMUJNPbOvT7hNdB1lG65PCUj7A/m1tSm zo4aJSr0mqdPqOTfdHsVjxNaCOFkm8tc/+NyxXrRIaKPEencgDOuaob3wg6V42h410 ISzDKFVUXn/o34TFXHxw2lbvwv8ftRRXMWArvyC/dlbExgS4uaVp63js262mlFRDCF 5ap/fZUCpkMqQ== 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 EB1B4C4167B; Tue, 5 Dec 2023 17:06:45 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 05 Dec 2023 18:06:45 +0100 Subject: [PATCH 5/8] iio: adc: ad9467: use spi_get_device_match_data() Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231205-iio-backend-prep-v1-5-7c9bc18d612b@analog.com> References: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> In-Reply-To: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> To: linux-iio@vger.kernel.org Cc: Michael Hennerich , Jonathan Cameron , Lars-Peter Clausen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1701796004; l=686; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=KwOoDJbfeKxv+O783O7duvsC7KCPDrH8MqqvCh2j2jc=; b=ACyqsphlXIDuXvqbAJcHv8gAMEISv6L/6J5c3+Urd4EdPSovL+SwSa9MknGlfJAdB8AN+7Xaf Zqvq3Q5WI5/Ah3xg5/nR3TdYz9RHKMFPLGMic3kZFe3DDmPI+N0p39E X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: From: Nuno Sa Make use of spi_get_device_match_data() to simplify things. Signed-off-by: Nuno Sa Reviewed-by: David Lechner --- drivers/iio/adc/ad9467.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index 3c8bd6c821a4..6bdbd0ea8d6c 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -456,9 +456,7 @@ static int ad9467_probe(struct spi_device *spi) unsigned int id; int ret; - info = of_device_get_match_data(&spi->dev); - if (!info) - info = (void *)spi_get_device_id(spi)->driver_data; + info = spi_get_device_match_data(spi); if (!info) return -ENODEV; From patchwork Tue Dec 5 17:06:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13480484 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 877BF692A3 for ; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X0J/Tqh4" Received: by smtp.kernel.org (Postfix) with ESMTPS id 15380C43395; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701796006; bh=zzUdDaQ/rSOdbkrMPGJRubpYY5Nh8A9hKPMOMeoLg9A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=X0J/Tqh4b39nYELFXFtKkC27OWse5xBu9avi+2aKLRgU7MPG9l4ck2EWUv5UV/mOU /61ZK/JCwKKrZn8hngaAogZ2u324JUuAEr9qfAsnMGXl/F0ZHE4Sngk6d0D8XHr12L eym2foFXYujVsEf3gjP2lG/KsOI6gl0YisSKC3zOce2hi7F7zdRh5S8y9XZN8wVEve tAattac43WBcJ1wCBt7lBAxdpqTEYUwX/IErqWburZt4UHlyqhyjTvS8lLto443OK/ b6N4wNxgu0ZXYRINOVkwP+TCXg2x2dREr4+jiCM5zBaQKt+d8APm/T+SfkIVujgMgX QJLGmAZEGIrbg== 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 01810C10F07; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 05 Dec 2023 18:06:46 +0100 Subject: [PATCH 6/8] iio: adc: ad9467: use chip_info variables instead of array Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231205-iio-backend-prep-v1-6-7c9bc18d612b@analog.com> References: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> In-Reply-To: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> To: linux-iio@vger.kernel.org Cc: Michael Hennerich , Jonathan Cameron , Lars-Peter Clausen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1701796004; l=4457; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=xePLVqcepEDlqcSx8DAfd33YoMuOTS8NXIi6omM4F+k=; b=fIauLChM7xfvh/Vx4qegvsJQUI9StprY4XT6Zys52EIvYCNOGv8VMKX79yAHhR7iP0wWNodaM oO62K6+KF9oAQyuJ+ispbgjmzjdZrcnemdsV0BBtasphfSL0z82AVva X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: From: Nuno Sa Instead of having an array and keeping IDs for each entry of the array, just have a chip_info struct per device. Signed-off-by: Nuno Sa Reviewed-by: David Lechner --- drivers/iio/adc/ad9467.c | 89 +++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index 6bdbd0ea8d6c..0d075e6b6248 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -101,12 +101,6 @@ #define AD9467_DEF_OUTPUT_MODE 0x08 #define AD9467_REG_VREF_MASK 0x0F -enum { - ID_AD9265, - ID_AD9434, - ID_AD9467, -}; - struct ad9467_chip_info { struct adi_axi_adc_chip_info axi_adc_info; unsigned int default_output_mode; @@ -234,43 +228,46 @@ static const struct iio_chan_spec ad9467_channels[] = { AD9467_CHAN(0, 0, 16, 'S'), }; -static const struct ad9467_chip_info ad9467_chip_tbl[] = { - [ID_AD9265] = { - .axi_adc_info = { - .id = CHIPID_AD9265, - .max_rate = 125000000UL, - .scale_table = ad9265_scale_table, - .num_scales = ARRAY_SIZE(ad9265_scale_table), - .channels = ad9467_channels, - .num_channels = ARRAY_SIZE(ad9467_channels), - }, - .default_output_mode = AD9265_DEF_OUTPUT_MODE, - .vref_mask = AD9265_REG_VREF_MASK, +static const struct ad9467_chip_info ad9467_chip_tbl = { + .axi_adc_info = { + .name = "ad9467", + .id = CHIPID_AD9467, + .max_rate = 250000000UL, + .scale_table = ad9467_scale_table, + .num_scales = ARRAY_SIZE(ad9467_scale_table), + .channels = ad9467_channels, + .num_channels = ARRAY_SIZE(ad9467_channels), }, - [ID_AD9434] = { - .axi_adc_info = { - .id = CHIPID_AD9434, - .max_rate = 500000000UL, - .scale_table = ad9434_scale_table, - .num_scales = ARRAY_SIZE(ad9434_scale_table), - .channels = ad9434_channels, - .num_channels = ARRAY_SIZE(ad9434_channels), - }, - .default_output_mode = AD9434_DEF_OUTPUT_MODE, - .vref_mask = AD9434_REG_VREF_MASK, + .default_output_mode = AD9467_DEF_OUTPUT_MODE, + .vref_mask = AD9467_REG_VREF_MASK, +}; + +static const struct ad9467_chip_info ad9434_chip_tbl = { + .axi_adc_info = { + .name = "ad9434", + .id = CHIPID_AD9434, + .max_rate = 500000000UL, + .scale_table = ad9434_scale_table, + .num_scales = ARRAY_SIZE(ad9434_scale_table), + .channels = ad9434_channels, + .num_channels = ARRAY_SIZE(ad9434_channels), }, - [ID_AD9467] = { - .axi_adc_info = { - .id = CHIPID_AD9467, - .max_rate = 250000000UL, - .scale_table = ad9467_scale_table, - .num_scales = ARRAY_SIZE(ad9467_scale_table), - .channels = ad9467_channels, - .num_channels = ARRAY_SIZE(ad9467_channels), - }, - .default_output_mode = AD9467_DEF_OUTPUT_MODE, - .vref_mask = AD9467_REG_VREF_MASK, + .default_output_mode = AD9434_DEF_OUTPUT_MODE, + .vref_mask = AD9434_REG_VREF_MASK, +}; + +static const struct ad9467_chip_info ad9265_chip_tbl = { + .axi_adc_info = { + .name = "ad9265", + .id = CHIPID_AD9265, + .max_rate = 125000000UL, + .scale_table = ad9265_scale_table, + .num_scales = ARRAY_SIZE(ad9265_scale_table), + .channels = ad9467_channels, + .num_channels = ARRAY_SIZE(ad9467_channels), }, + .default_output_mode = AD9265_DEF_OUTPUT_MODE, + .vref_mask = AD9265_REG_VREF_MASK, }; static int ad9467_get_scale(struct adi_axi_adc_conv *conv, int *val, int *val2) @@ -506,17 +503,17 @@ static int ad9467_probe(struct spi_device *spi) } static const struct of_device_id ad9467_of_match[] = { - { .compatible = "adi,ad9265", .data = &ad9467_chip_tbl[ID_AD9265], }, - { .compatible = "adi,ad9434", .data = &ad9467_chip_tbl[ID_AD9434], }, - { .compatible = "adi,ad9467", .data = &ad9467_chip_tbl[ID_AD9467], }, + { .compatible = "adi,ad9265", .data = &ad9265_chip_tbl, }, + { .compatible = "adi,ad9434", .data = &ad9434_chip_tbl, }, + { .compatible = "adi,ad9467", .data = &ad9467_chip_tbl, }, {} }; MODULE_DEVICE_TABLE(of, ad9467_of_match); static const struct spi_device_id ad9467_ids[] = { - { "ad9265", (kernel_ulong_t)&ad9467_chip_tbl[ID_AD9265] }, - { "ad9434", (kernel_ulong_t)&ad9467_chip_tbl[ID_AD9434] }, - { "ad9467", (kernel_ulong_t)&ad9467_chip_tbl[ID_AD9467] }, + { "ad9265", (kernel_ulong_t)&ad9265_chip_tbl }, + { "ad9434", (kernel_ulong_t)&ad9434_chip_tbl }, + { "ad9467", (kernel_ulong_t)&ad9467_chip_tbl }, {} }; MODULE_DEVICE_TABLE(spi, ad9467_ids); From patchwork Tue Dec 5 17:06:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13480485 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 70911692A0 for ; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IugFukPu" Received: by smtp.kernel.org (Postfix) with ESMTPS id 1CC2EC433AB; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701796006; bh=lCObtoTpSqkaFQwyOFhNJ1ryAu4Gcs5xCQOhbPA4SMs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=IugFukPuXBBRW1lreAmzjRw/SWxikJQjbilwC8Cf1WtTUh4ejHVk4pGGQAEIh0fJu imlxEBHFQOWbqgMn+E5u98C93rRsaJfvJHxRWauhsN/wnm9aL5tu5nMk4yibFBMOk0 Z188+4t8lPwybxD3C9WIGPB5ncCVFA2kfzRq/diUT9NXO9FDF37cG0rVAj7nx4E/lK N5VRV1eCyrrjwWzfKO63BwaSZkR0g3XqUDyoflMbWR4hpd/7qXZsYP7JXromzczlME j1Ib+EtmkNOL6mpNRXDGcIAMcx9Ce4d9oxiN/xmxzG2LTN/41QQMpDYozxDVA0epLy 9VCp8PZW5SkKA== 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 0CE9EC10DCE; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 05 Dec 2023 18:06:47 +0100 Subject: [PATCH 7/8] iio: adc: ad9467: use the more common !val NULL check Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231205-iio-backend-prep-v1-7-7c9bc18d612b@analog.com> References: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> In-Reply-To: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> To: linux-iio@vger.kernel.org Cc: Michael Hennerich , Jonathan Cameron , Lars-Peter Clausen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1701796004; l=707; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=3jM1tUSsUENHFVqpXxzR/Yo8ri6HTO5FowZWdC38P+c=; b=puuU1b0SdAO4L8t9ZAspVLPBtIUt4FOZedOvK6dpK0P7rCQwwtLtNKdQu+4P/hQ4K8yvkT1GY Ez+SKlkCjXqA4JyGY43Xoc/SDvd2DR8yWhZ8ghLHkOKavaOPMm/X0lB X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: From: Nuno Sa Check !val instead of directing checking for NULL (val == NULL). No functional changes intended. Signed-off-by: Nuno Sa Reviewed-by: David Lechner --- drivers/iio/adc/ad9467.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index 0d075e6b6248..637823de712f 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -158,7 +158,7 @@ static int ad9467_reg_access(struct adi_axi_adc_conv *conv, unsigned int reg, struct spi_device *spi = st->spi; int ret; - if (readval == NULL) { + if (!readval) { guard(mutex)(&st->lock); ret = ad9467_spi_write(spi, reg, writeval); if (ret) From patchwork Tue Dec 5 17:06:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13480487 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 871C8692A2 for ; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O5dYQ9zl" Received: by smtp.kernel.org (Postfix) with ESMTPS id 2A91AC433B6; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701796006; bh=oSeujLaFf8i2ZG9xK+nIVBz3hziiflDh2ViXEFLzGHo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=O5dYQ9zluX1seYnKR9ntpyu/IdXbuloDxA1T+5hk2lLX0ADg2Qi9DN8Jhvy4BFXcV ltz9+YWH6NckuZAzgh6uptoJSm9r8XD5WtnDSbv+lYxPVJNnw4TT2nS3Oxmqtv4+qX BLHUTrdJRcIl6R1zLO6yAszg6J86JrllErjU7i+pwhGuFqU5fwD52EyqwUybLGL5ea /7BbTE/r/Je2rVo+UygnFSfQqpaRdt59h24xzLa2Pahqaxpdez0OncMA30HoEBxwDS l1bBc9+BOwvE3ONL/dg65baxtwqxv9ZULEHTfqEYfzPEOiyVbqvtqbiF4aHJu7P+mD UoY1A771tiGFw== 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 18DE0C10F09; Tue, 5 Dec 2023 17:06:46 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 05 Dec 2023 18:06:48 +0100 Subject: [PATCH 8/8] iio: adc: adi-axi-adc: convert to regmap Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231205-iio-backend-prep-v1-8-7c9bc18d612b@analog.com> References: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> In-Reply-To: <20231205-iio-backend-prep-v1-0-7c9bc18d612b@analog.com> To: linux-iio@vger.kernel.org Cc: Michael Hennerich , Jonathan Cameron , Lars-Peter Clausen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1701796004; l=4779; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=pXYTHlTNV0lEKqQpwgzCRwzdqvuOQxn+WxE6GekCLjY=; b=Xi31l1QZs6q4LaGqTXlAxo6t1vAzB3KErDwZU8OuKdW+DfAtkJeUSR227iTJmTxdNMlTdo3Dg ypm6VmShTShA3bbhjBv6BbJTeXyUbWT78Vl06Jgx9q7H1nslI85NHXM X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: From: Nuno Sa Use MMIO regmap interface. It makes things easier for manipulating bits. Signed-off-by: Nuno Sa Reviewed-by: David Lechner --- drivers/iio/adc/adi-axi-adc.c | 85 ++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index ae83ada7f9f2..c247ff1541d2 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -62,7 +63,7 @@ struct adi_axi_adc_state { struct mutex lock; struct adi_axi_adc_client *client; - void __iomem *regs; + struct regmap *regmap; }; struct adi_axi_adc_client { @@ -90,19 +91,6 @@ void *adi_axi_adc_conv_priv(struct adi_axi_adc_conv *conv) } EXPORT_SYMBOL_NS_GPL(adi_axi_adc_conv_priv, IIO_ADI_AXI); -static void adi_axi_adc_write(struct adi_axi_adc_state *st, - unsigned int reg, - unsigned int val) -{ - iowrite32(val, st->regs + reg); -} - -static unsigned int adi_axi_adc_read(struct adi_axi_adc_state *st, - unsigned int reg) -{ - return ioread32(st->regs + reg); -} - static int adi_axi_adc_config_dma_buffer(struct device *dev, struct iio_dev *indio_dev) { @@ -163,17 +151,20 @@ static int adi_axi_adc_update_scan_mode(struct iio_dev *indio_dev, { struct adi_axi_adc_state *st = iio_priv(indio_dev); struct adi_axi_adc_conv *conv = &st->client->conv; - unsigned int i, ctrl; + unsigned int i; + int ret; for (i = 0; i < conv->chip_info->num_channels; i++) { - ctrl = adi_axi_adc_read(st, ADI_AXI_REG_CHAN_CTRL(i)); - if (test_bit(i, scan_mask)) - ctrl |= ADI_AXI_REG_CHAN_CTRL_ENABLE; + ret = regmap_set_bits(st->regmap, + ADI_AXI_REG_CHAN_CTRL(i), + ADI_AXI_REG_CHAN_CTRL_ENABLE); else - ctrl &= ~ADI_AXI_REG_CHAN_CTRL_ENABLE; - - adi_axi_adc_write(st, ADI_AXI_REG_CHAN_CTRL(i), ctrl); + ret = regmap_clear_bits(st->regmap, + ADI_AXI_REG_CHAN_CTRL(i), + ADI_AXI_REG_CHAN_CTRL_ENABLE); + if (ret) + return ret; } return 0; @@ -310,21 +301,32 @@ static int adi_axi_adc_setup_channels(struct device *dev, } for (i = 0; i < conv->chip_info->num_channels; i++) { - adi_axi_adc_write(st, ADI_AXI_REG_CHAN_CTRL(i), - ADI_AXI_REG_CHAN_CTRL_DEFAULTS); + ret = regmap_write(st->regmap, ADI_AXI_REG_CHAN_CTRL(i), + ADI_AXI_REG_CHAN_CTRL_DEFAULTS); + if (ret) + return ret; } return 0; } -static void axi_adc_reset(struct adi_axi_adc_state *st) +static int axi_adc_reset(struct adi_axi_adc_state *st) { - adi_axi_adc_write(st, ADI_AXI_REG_RSTN, 0); + int ret; + + ret = regmap_write(st->regmap, ADI_AXI_REG_RSTN, 0); + if (ret) + return ret; + mdelay(10); - adi_axi_adc_write(st, ADI_AXI_REG_RSTN, ADI_AXI_REG_RSTN_MMCM_RSTN); + ret = regmap_write(st->regmap, ADI_AXI_REG_RSTN, + ADI_AXI_REG_RSTN_MMCM_RSTN); + if (ret) + return ret; + mdelay(10); - adi_axi_adc_write(st, ADI_AXI_REG_RSTN, - ADI_AXI_REG_RSTN_RSTN | ADI_AXI_REG_RSTN_MMCM_RSTN); + return regmap_write(st->regmap, ADI_AXI_REG_RSTN, + ADI_AXI_REG_RSTN_RSTN | ADI_AXI_REG_RSTN_MMCM_RSTN); } static void adi_axi_adc_cleanup(void *data) @@ -335,12 +337,20 @@ static void adi_axi_adc_cleanup(void *data) module_put(cl->dev->driver->owner); } +static const struct regmap_config axi_adc_regmap_config = { + .val_bits = 32, + .reg_bits = 32, + .reg_stride = 4, + .max_register = 0x0800, +}; + static int adi_axi_adc_probe(struct platform_device *pdev) { struct adi_axi_adc_conv *conv; struct iio_dev *indio_dev; struct adi_axi_adc_client *cl; struct adi_axi_adc_state *st; + void __iomem *base; unsigned int ver; int ret; @@ -361,15 +371,24 @@ static int adi_axi_adc_probe(struct platform_device *pdev) cl->state = st; mutex_init(&st->lock); - st->regs = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(st->regs)) - return PTR_ERR(st->regs); + base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(base)) + return PTR_ERR(base); + + st->regmap = devm_regmap_init_mmio(&pdev->dev, base, + &axi_adc_regmap_config); + if (IS_ERR(st->regmap)) + return PTR_ERR(st->regmap); conv = &st->client->conv; - axi_adc_reset(st); + ret = axi_adc_reset(st); + if (ret) + return ret; - ver = adi_axi_adc_read(st, ADI_AXI_REG_VERSION); + ret = regmap_read(st->regmap, ADI_AXI_REG_VERSION, &ver); + if (ret) + return ret; if (cl->info->version > ver) { dev_err(&pdev->dev,