From patchwork Fri Apr 21 11:35:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Nyekjaer X-Patchwork-Id: 13219816 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20827C77B7C for ; Fri, 21 Apr 2023 11:35:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231633AbjDULfY (ORCPT ); Fri, 21 Apr 2023 07:35:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231604AbjDULfX (ORCPT ); Fri, 21 Apr 2023 07:35:23 -0400 Received: from www530.your-server.de (www530.your-server.de [188.40.30.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1EDE44A5 for ; Fri, 21 Apr 2023 04:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=geanix.com; s=default2211; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=C9OIXHKoxJiLF9g2Txj4+bFVodwDJzn88JiDF+haznA=; b=JcIyrrQDKP7E6oLEhP/y2R/SSQ xXCqhRh3DKYmpD50Ks6waE905wRwbt63LT4uDKji2qFb602PF/0ukOZ1rQ6QRgpLA4feGSCR2Bsed k/wFgX3Tr/Y3qIWUgYDXogNSU2Rx26NSElhH1SUbOPNv6A85h0vDlGncmbAjFX23uixovpbN7sb0X xVEJaWJYzC3RiP+Lj/7KbZggWM1RD7ZzT1flSyN9pHtC4Yj5XNfzjUHAJ5dhWhjoxH5T6k9Pue2+G 9yKDHHeWVbp6HOzOhqZWtmWfXlfCWrL4zUjR9+0b6juxkEsy8B4bHHkT9pfJLkBhM8pbIj5MnSckd U6dBgKaA==; Received: from sslproxy03.your-server.de ([88.198.220.132]) by www530.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ppp2t-0002Vs-0u; Fri, 21 Apr 2023 13:35:19 +0200 Received: from [185.17.218.86] (helo=zen..) by sslproxy03.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ppp2s-000MPW-KY; Fri, 21 Apr 2023 13:35:18 +0200 From: Sean Nyekjaer To: jic23@kernel.org, olivier.moysan@foss.st.com, alexandre.torgue@foss.st.com, nuno.sa@analog.com Cc: Sean Nyekjaer , linux-iio@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Subject: [PATCH v2 1/2] iio: adc: stm32-adc: skip adc-diff-channels setup if none is present Date: Fri, 21 Apr 2023 13:35:15 +0200 Message-Id: <20230421113516.2710454-1-sean@geanix.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Authenticated-Sender: sean@geanix.com X-Virus-Scanned: Clear (ClamAV 0.103.8/26883/Fri Apr 21 09:25:39 2023) Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org If no adc differential channels are defined driver will fail with EINVAL: stm32-adc: probe of 48003000.adc:adc@0 failed with error -22 Fix this by skipping the initialization if no channels are defined. This applies only to the legacy way of initializing adc channels. Fixes: d7705f35448a ("iio: adc: stm32-adc: convert to device properties") Signed-off-by: Sean Nyekjaer --- Changes since v1: - None drivers/iio/adc/stm32-adc.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c index e179b6611e4d..14524c1b5583 100644 --- a/drivers/iio/adc/stm32-adc.c +++ b/drivers/iio/adc/stm32-adc.c @@ -2008,16 +2008,15 @@ static int stm32_adc_get_legacy_chan_count(struct iio_dev *indio_dev, struct stm * to get the *real* number of channels. */ ret = device_property_count_u32(dev, "st,adc-diff-channels"); - if (ret < 0) - return ret; - - ret /= (int)(sizeof(struct stm32_adc_diff_channel) / sizeof(u32)); - if (ret > adc_info->max_channels) { - dev_err(&indio_dev->dev, "Bad st,adc-diff-channels?\n"); - return -EINVAL; - } else if (ret > 0) { - adc->num_diff = ret; - num_channels += ret; + if (ret > 0) { + ret /= (int)(sizeof(struct stm32_adc_diff_channel) / sizeof(u32)); + if (ret > adc_info->max_channels) { + dev_err(&indio_dev->dev, "Bad st,adc-diff-channels?\n"); + return -EINVAL; + } else if (ret > 0) { + adc->num_diff = ret; + num_channels += ret; + } } /* Optional sample time is provided either for each, or all channels */ From patchwork Fri Apr 21 11:35:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Nyekjaer X-Patchwork-Id: 13219817 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89537C7618E for ; Fri, 21 Apr 2023 11:35:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231643AbjDULfZ (ORCPT ); Fri, 21 Apr 2023 07:35:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231617AbjDULfX (ORCPT ); Fri, 21 Apr 2023 07:35:23 -0400 Received: from www530.your-server.de (www530.your-server.de [188.40.30.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2336AD34 for ; Fri, 21 Apr 2023 04:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=geanix.com; s=default2211; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=ox+YMMP5BtU7nkNA6WBhHsW92G5sHmgRrz8uI0MSILA=; b=1JVorq+75IC7YDEivOdPAo3gWJ VIDfVveqSFJtcsAHuP9xNBlvv9z6fvvgOV9iEGsKjtIdvBIbVGDtej4WeefIEB98hUHQ5zL7LVFd2 nElRl/CMBr/Fp1cZPP6T5vdCf+FAf8pCVm2XrPpqFkoVNUYVyxP2Dm8Jo+V4cBFzzHBaJdWD8JjGy x1z7yyfy1+MNSMR0U/2rbXbJhTAC/rvNdXp1MUSjfdl7AoG75SSepUG5PHRAqdpN9/JQjn/53X2y7 o8e1nYerEWp1rb2Kg3EgSZzd1iYbM1oyInNDIdFhUtuyVCMKRitTLQkL/T8Nxw/iXxnOfxwVcirxY bQzcWPnQ==; Received: from sslproxy03.your-server.de ([88.198.220.132]) by www530.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ppp2t-0002Vw-5G; Fri, 21 Apr 2023 13:35:19 +0200 Received: from [185.17.218.86] (helo=zen..) by sslproxy03.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ppp2s-000MPW-R2; Fri, 21 Apr 2023 13:35:18 +0200 From: Sean Nyekjaer To: jic23@kernel.org, olivier.moysan@foss.st.com, alexandre.torgue@foss.st.com, nuno.sa@analog.com Cc: Sean Nyekjaer , linux-iio@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Subject: [PATCH v2 2/2] iio: adc: stm32-adc: skip adc-channels setup if none is present Date: Fri, 21 Apr 2023 13:35:16 +0200 Message-Id: <20230421113516.2710454-2-sean@geanix.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230421113516.2710454-1-sean@geanix.com> References: <20230421113516.2710454-1-sean@geanix.com> MIME-Version: 1.0 X-Authenticated-Sender: sean@geanix.com X-Virus-Scanned: Clear (ClamAV 0.103.8/26883/Fri Apr 21 09:25:39 2023) Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org If only adc differential channels are defined driver will fail with stm32-adc: probe of 48003000.adc:adc@0 failed with error -22 Fix this by skipping the initialization if no channels are defined. This applies only to the legacy way of initializing adc channels. Fixes: d7705f35448a ("iio: adc: stm32-adc: convert to device properties") Signed-off-by: Sean Nyekjaer --- Changes since v1: - Ignore extra channel for timestamps in PIO mode - Use single ended count in channel creation (Thanks Olivier Moysan) drivers/iio/adc/stm32-adc.c | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c index 14524c1b5583..99bfe995b6f1 100644 --- a/drivers/iio/adc/stm32-adc.c +++ b/drivers/iio/adc/stm32-adc.c @@ -2038,6 +2038,7 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev, struct stm32_adc_diff_channel diff[STM32_ADC_CH_MAX]; struct device *dev = &indio_dev->dev; u32 num_diff = adc->num_diff; + int num_se = nchans - num_diff; int size = num_diff * sizeof(*diff) / sizeof(u32); int scan_index = 0, ret, i, c; u32 smp = 0, smps[STM32_ADC_CH_MAX], chans[STM32_ADC_CH_MAX]; @@ -2065,28 +2066,27 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev, } } - ret = device_property_read_u32_array(dev, "st,adc-channels", chans, - nchans); - if (ret) - return ret; - - for (c = 0; c < nchans; c++) { - if (chans[c] >= adc_info->max_channels) { - dev_err(&indio_dev->dev, "Invalid channel %d\n", - chans[c]); - return -EINVAL; - } - - /* Channel can't be configured both as single-ended & diff */ - for (i = 0; i < num_diff; i++) { - if (chans[c] == diff[i].vinp) { - dev_err(&indio_dev->dev, "channel %d misconfigured\n", chans[c]); + ret = device_property_read_u32_array(dev, "st,adc-channels", chans, num_se); + if (ret == 0 && num_se > 0) { + for (c = 0; c < num_se; c++) { + if (chans[c] >= adc_info->max_channels) { + dev_err(&indio_dev->dev, "Invalid channel %d\n", + chans[c]); return -EINVAL; } + + /* Channel can't be configured both as single-ended & diff */ + for (i = 0; i < num_diff; i++) { + if (chans[c] == diff[i].vinp) { + dev_err(&indio_dev->dev, "channel %d misconfigured\n", + chans[c]); + return -EINVAL; + } + } + stm32_adc_chan_init_one(indio_dev, &channels[scan_index], + chans[c], 0, scan_index, false); + scan_index++; } - stm32_adc_chan_init_one(indio_dev, &channels[scan_index], - chans[c], 0, scan_index, false); - scan_index++; } if (adc->nsmps > 0) { @@ -2307,7 +2307,7 @@ static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping) if (legacy) ret = stm32_adc_legacy_chan_init(indio_dev, adc, channels, - num_channels); + timestamping ? num_channels - 1 : num_channels); else ret = stm32_adc_generic_chan_init(indio_dev, adc, channels); if (ret < 0)