From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32B67C433EF for ; Sat, 11 Sep 2021 16:06:50 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F143560F9C for ; Sat, 11 Sep 2021 16:06:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F143560F9C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=a91Le7fm2qlp5dIO0Zi648QN4lgw29nJRCqX7dmfF4k=; b=oslx6Tzn9mQc4o uVU3PfwJADcyyP/Nc9Af0B5DJ7LztDw3Qa10TJOzLtdyDPChGb+s2TDQEZYdgCcS1lw23TpgJrJP4 IH6oAsySdBkwpGQOf1x1SOP4gEgXDBKTrPC/HK7PLyp5PCOJ1zmmkv3Nfwmy0EWKlYYAZ09ue3sWL NyQVLTd+B1iQalkjIr8XjPvQjWzXMtmAfBPbk9TJbI5KeZej9ENr3DR01fTVxZINCi+3YSIenNLoB WDl3IRipNvXmiucD1SIVEMkrgNb5oVsij3DEEnLVT0P8VUCAFm3TeD15ZQdJTrMQsYeLlGMevL2i3 Gq+n8BBHhj0g50L7Sr8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mP5Uz-00FCFE-28; Sat, 11 Sep 2021 16:05:01 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mP5Uu-00FCEf-F5 for linux-arm-kernel@lists.infradead.org; Sat, 11 Sep 2021 16:04:58 +0000 Received: from jic23-huawei (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E1A5560F9C; Sat, 11 Sep 2021 16:04:52 +0000 (UTC) Date: Sat, 11 Sep 2021 17:08:23 +0100 From: Jonathan Cameron To: Olivier Moysan Cc: Alexandre Torgue , Arnaud Pouliquen , Fabrice Gasnier , Lars-Peter Clausen , Maxime Coquelin , Rob Herring , , , , , , Subject: Re: [PATCH 4/7] iio: adc: stm32-adc: add support of generic channels binding Message-ID: <20210911170823.292aa672@jic23-huawei> In-Reply-To: <20210908155452.25458-5-olivier.moysan@foss.st.com> References: <20210908155452.25458-1-olivier.moysan@foss.st.com> <20210908155452.25458-5-olivier.moysan@foss.st.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210911_090456_602570_27900543 X-CRM114-Status: GOOD ( 30.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 8 Sep 2021 17:54:49 +0200 Olivier Moysan wrote: > Add support of generic IIO channel binding: > ./devicetree/bindings/iio/adc/adc.yaml > Keep support of st,adc-channels and st,adc-diff-channels > for backward compatibility. > > Signed-off-by: Olivier Moysan Hi Olivier, A few minor things inline. Thanks, Jonathan > --- > drivers/iio/adc/stm32-adc.c | 99 +++++++++++++++++++++++++++++++++---- > 1 file changed, 90 insertions(+), 9 deletions(-) > > diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c > index 2f137d14f141..ae4a314854f7 100644 > --- a/drivers/iio/adc/stm32-adc.c > +++ b/drivers/iio/adc/stm32-adc.c > @@ -35,7 +35,7 @@ > #define STM32H7_BOOST_CLKRATE 20000000UL > > #define STM32_ADC_CH_MAX 20 /* max number of channels */ > -#define STM32_ADC_CH_SZ 10 /* max channel name size */ > +#define STM32_ADC_CH_SZ 16 /* max channel name size */ > #define STM32_ADC_MAX_SQ 16 /* SQ1..SQ16 */ > #define STM32_ADC_MAX_SMP 7 /* SMPx range is [0..7] */ > #define STM32_ADC_TIMEOUT_US 100000 > @@ -1732,6 +1732,11 @@ static int stm32_adc_get_legacy_chan_count(struct iio_dev *indio_dev, struct stm > num_channels += ret; > } > > + if (!num_channels) { > + dev_err(indio_dev->dev.parent, "No channel found\n"); > + return -ENODATA; I'd return 0 and handle this at the caller. Both because it makes this patch more readable and because a count of 0 isn't an error of the function reading how many they are, but rather at a higher level. > + } > + > return num_channels; > } > > @@ -1792,6 +1797,73 @@ static int stm32_adc_legacy_chan_init(struct iio_dev *indio_dev, > return scan_index; > } > > +static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, > + struct stm32_adc *adc, > + struct iio_chan_spec *channels) > +{ > + struct device_node *node = indio_dev->dev.of_node; > + const struct stm32_adc_info *adc_info = adc->cfg->adc_info; > + struct device_node *child; > + const char *name; > + int val, scan_index = 0, ret; > + bool differential; > + u32 vin[2]; > + > + for_each_available_child_of_node(node, child) { > + ret = of_property_read_u32(child, "reg", &val); > + if (ret) { > + dev_err(&indio_dev->dev, "Missing channel index %d\n", ret); > + goto err; > + } > + > + ret = of_property_read_string(child, "label", &name); > + /* label is optional */ > + if (!ret) { > + if (strlen(name) >= STM32_ADC_CH_SZ) { > + dev_err(&indio_dev->dev, "Label %s exceeds %d characters\n", > + name, STM32_ADC_CH_SZ); > + return -EINVAL; > + } > + strncpy(adc->chan_name[val], name, STM32_ADC_CH_SZ); > + } else if (ret != -EINVAL) { > + dev_err(&indio_dev->dev, "Invalid label %d\n", ret); > + goto err; > + } > + > + if (val >= adc_info->max_channels) { > + dev_err(&indio_dev->dev, "Invalid channel %d\n", val); > + ret = -EINVAL; > + goto err; > + } > + > + differential = false; > + ret = of_property_read_u32_array(child, "diff-channels", vin, 2); > + /* diff-channels is optional */ > + if (!ret) { > + differential = true; > + if (vin[0] != val || vin[1] >= adc_info->max_channels) { > + dev_err(&indio_dev->dev, "Invalid channel in%d-in%d\n", > + vin[0], vin[1]); > + goto err; > + } > + } else if (ret != -EINVAL) { > + dev_err(&indio_dev->dev, "Invalid diff-channels property %d\n", ret); > + goto err; > + } > + > + stm32_adc_chan_init_one(indio_dev, &channels[scan_index], val, > + vin[1], scan_index, differential); > + scan_index++; > + } > + > + return scan_index; > + > +err: > + of_node_put(child); > + > + return ret; > +} > + > static int stm32_adc_chan_of_init(struct iio_dev *indio_dev, bool timestamping) > { > struct device_node *node = indio_dev->dev.of_node; > @@ -1800,15 +1872,21 @@ static int stm32_adc_chan_of_init(struct iio_dev *indio_dev, bool timestamping) > struct iio_chan_spec *channels; > int scan_index = 0, num_channels = 0, ret, i; > u32 smp = 0; > + bool legacy = false; > > - ret = stm32_adc_get_legacy_chan_count(indio_dev, adc); > - if (ret < 0) > - return ret; > - num_channels = ret; > - > + num_channels = of_get_available_child_count(node); > + /* > + * If no channels have been found, fallback to channels legacy properties. > + * Legacy channel properties will be ignored, if some channels are drop the , Legacy channel properties will be ignored if some channels... > + * already defined using the standard binding. > + */ > if (!num_channels) { > - dev_err(&indio_dev->dev, "No channels configured\n"); > - return -ENODATA; > + ret = stm32_adc_get_legacy_chan_count(indio_dev, adc); > + if (ret < 0) > + return ret; > + > + legacy = true; Trivial but I would set legacy at top of this if block so it is nearer the comment. > + num_channels = ret; > } > > if (num_channels > adc_info->max_channels) { > @@ -1832,7 +1910,10 @@ static int stm32_adc_chan_of_init(struct iio_dev *indio_dev, bool timestamping) > if (!channels) > return -ENOMEM; > > - ret = stm32_adc_legacy_chan_init(indio_dev, adc, channels); > + if (legacy) > + ret = stm32_adc_legacy_chan_init(indio_dev, adc, channels); > + else > + ret = stm32_adc_generic_chan_init(indio_dev, adc, channels); > if (ret < 0) > return ret; > scan_index = ret; _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel