From patchwork Mon Mar 27 08:34:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Nyekjaer X-Patchwork-Id: 13188842 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 01ADCC761A6 for ; Mon, 27 Mar 2023 09:06:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232454AbjC0JGl (ORCPT ); Mon, 27 Mar 2023 05:06:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232983AbjC0JFx (ORCPT ); Mon, 27 Mar 2023 05:05:53 -0400 Received: from www530.your-server.de (www530.your-server.de [188.40.30.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F7AE10FE for ; Mon, 27 Mar 2023 02:05:22 -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=nlRe8f4/ag5dmmxfq8dbVSW6Imwp09NDX9J36bNmqcE=; b=1n9DpUdWR7h3HKncZodKxLLvt/ PmX3+2bFVlysh3j9qIRbC5G6/HPMQJavh1DU1tvIgnQAAR/p7Zb+/jENNUG/cDYYefi0Exxh+czVd y82FrJ/dJ9NiIbNLQAjCXG6eIOpHfNWVK436x4OwNTeJwQEnIDzmrCDFCZ05ZM2A8Z3fNZ7JwVq32 NQisL69TjgIKd9lmZUqRjc25fqOgQ+SoanQyihH5OZriZB3iZ9KSaGXLe5Cx9mXSXirolDKJKJfsy sAlWe+BKSvXmG2Trg8wNEjR0mQ/l1GIk9Vzny9OwL6CStRLw9JqCDcnj5jzrMifS1nlvLDmdE7JkA wy9ZnFyw==; Received: from sslproxy06.your-server.de ([78.46.172.3]) by www530.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pgiJo-000PcX-Bq; Mon, 27 Mar 2023 10:35:08 +0200 Received: from [185.17.218.86] (helo=zen..) by sslproxy06.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pgiJo-000H3h-1k; Mon, 27 Mar 2023 10:35:08 +0200 From: Sean Nyekjaer To: jic23@kernel.org, lars@metafoo.de, 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 1/3] iio: adc: stm32-adc: warn if dt uses legacy channel config Date: Mon, 27 Mar 2023 10:34:47 +0200 Message-Id: <20230327083449.1098174-1-sean@geanix.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Authenticated-Sender: sean@geanix.com X-Virus-Scanned: Clear (ClamAV 0.103.8/26856/Mon Mar 27 09:24:05 2023) Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Since nearly all stm32 dt's are using the legacy adc channel config, we should warn users about using it. Signed-off-by: Sean Nyekjaer --- drivers/iio/adc/stm32-adc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c index 1aadb2ad2cab..d8e755d0cc52 100644 --- a/drivers/iio/adc/stm32-adc.c +++ b/drivers/iio/adc/stm32-adc.c @@ -1993,6 +1993,8 @@ static int stm32_adc_get_legacy_chan_count(struct iio_dev *indio_dev, struct stm const struct stm32_adc_info *adc_info = adc->cfg->adc_info; int num_channels = 0, ret; + dev_warn(&indio_dev->dev, "using legacy channel config\n"); + ret = device_property_count_u32(dev, "st,adc-channels"); if (ret > adc_info->max_channels) { dev_err(&indio_dev->dev, "Bad st,adc-channels?\n"); From patchwork Mon Mar 27 08:34:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Nyekjaer X-Patchwork-Id: 13188843 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 5157DC76195 for ; Mon, 27 Mar 2023 09:07:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232660AbjC0JGt (ORCPT ); Mon, 27 Mar 2023 05:06:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232384AbjC0JGJ (ORCPT ); Mon, 27 Mar 2023 05:06:09 -0400 Received: from www530.your-server.de (www530.your-server.de [188.40.30.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E1B655A5 for ; Mon, 27 Mar 2023 02:05:27 -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=NhCskZWj5emexPdjn3uIw47avpX8Bt9NtqvL+U/jfag=; b=f0bVMI+4UdzTOpXtQOhc5By35H Fo37ovlF8Yq56KWJvXkYPXhq5c03330PyXaiciX11vNXXIZTPMHy3dAEV7r0y664aH+gHaL4Z30RD XBgMyl+FDwfDLsEoAXOE0VRvj7GuwWyl/wWIfqA024NPVbyYfIjbY0hHecGWsZlVdzX+Z/H7/yTLB Ic2Ht1LYM0vJubdLYcAXDdCFOePIHf0DTJFTfZ9aZcl9xTK/ukxhwtMMwW0UkS53mYhSh9+J3EsFV sNIGV712gLrBjRg/bj06Q5qfsMzcDElCw9m2qTTR75HntbfL2OfN4lyC6Jfls70jz6jufCuHZNc4e r/mx/oqg==; Received: from sslproxy06.your-server.de ([78.46.172.3]) by www530.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pgiJo-000PcY-Hf; Mon, 27 Mar 2023 10:35:08 +0200 Received: from [185.17.218.86] (helo=zen..) by sslproxy06.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pgiJo-000H3h-7e; Mon, 27 Mar 2023 10:35:08 +0200 From: Sean Nyekjaer To: jic23@kernel.org, lars@metafoo.de, 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 2/3] iio: adc: stm32-adc: skip adc-diff-channels setup if none is present Date: Mon, 27 Mar 2023 10:34:48 +0200 Message-Id: <20230327083449.1098174-2-sean@geanix.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230327083449.1098174-1-sean@geanix.com> References: <20230327083449.1098174-1-sean@geanix.com> MIME-Version: 1.0 X-Authenticated-Sender: sean@geanix.com X-Virus-Scanned: Clear (ClamAV 0.103.8/26856/Mon Mar 27 09:24:05 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 --- 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 d8e755d0cc52..a04fcb2dc80a 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 Mon Mar 27 08:34:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Nyekjaer X-Patchwork-Id: 13188841 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 C0540C7619A for ; Mon, 27 Mar 2023 09:06:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231740AbjC0JGl (ORCPT ); Mon, 27 Mar 2023 05:06:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232870AbjC0JFp (ORCPT ); Mon, 27 Mar 2023 05:05:45 -0400 X-Greylist: delayed 1806 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 27 Mar 2023 02:05:18 PDT Received: from www530.your-server.de (www530.your-server.de [188.40.30.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D8DB2D57 for ; Mon, 27 Mar 2023 02:05:17 -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=L5Dqgb+CDPVOE1GUe8LDUQNM6b2zd6pn+JZmdwO8gaA=; b=HrCrlkpRM9PuBtY1323BsaO2eq mGuKU/45rnf9nCVCzdG2meds+MjBcZvUf7+1IwpnOrlatZPP3bQ/oaJgUcUqlEkrdQsmcxG+XTH+s HlPu7vrttnBXUOi+1rvSx9yWWLHbGRY0GPUOmZUEpIo0AtUUoP5kOnVd52xpl3SO1GUMfTRUd+pA6 HOHBlfVDZJvXcby3c/Kfm3PZPNPslGX/pt8U8OlkZ4oBHiNRn9QssmOAjN9Alo3t64tHihPwx4Mrc 6Mwcjvznn1XjDO1FPDIesQTyNzC6G+QHSX8VUfyB0hFYb+EAljX1WHPzvm7tPt+Bp82/f1SbbwMoS YVIQxQRg==; Received: from sslproxy06.your-server.de ([78.46.172.3]) by www530.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pgiJo-000Pcb-Nk; Mon, 27 Mar 2023 10:35:08 +0200 Received: from [185.17.218.86] (helo=zen..) by sslproxy06.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pgiJo-000H3h-De; Mon, 27 Mar 2023 10:35:08 +0200 From: Sean Nyekjaer To: jic23@kernel.org, lars@metafoo.de, 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 3/3] iio: adc: stm32-adc: skip adc-channels setup if none is present Date: Mon, 27 Mar 2023 10:34:49 +0200 Message-Id: <20230327083449.1098174-3-sean@geanix.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230327083449.1098174-1-sean@geanix.com> References: <20230327083449.1098174-1-sean@geanix.com> MIME-Version: 1.0 X-Authenticated-Sender: sean@geanix.com X-Virus-Scanned: Clear (ClamAV 0.103.8/26856/Mon Mar 27 09:24:05 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 --- drivers/iio/adc/stm32-adc.c | 38 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c index a04fcb2dc80a..6d87cfaadb5d 100644 --- a/drivers/iio/adc/stm32-adc.c +++ b/drivers/iio/adc/stm32-adc.c @@ -2065,28 +2065,30 @@ 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; - } + if (nchans - num_diff > 0) { + ret = device_property_read_u32_array(dev, "st,adc-channels", chans, + nchans); + if (ret) + return ret; - /* 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]); + 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; } - } - stm32_adc_chan_init_one(indio_dev, &channels[scan_index], + + /* 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++; + scan_index++; + } } if (adc->nsmps > 0) {