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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id CF073C27C4F for ; Sun, 23 Jun 2024 15:01:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type: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=u4ZuTq4d1CD4LI35RuTVyKbxtW70KGgvTYd1Klfnxo0=; b=yVPeXiNg0+WoQg/PaBQu/RbgI/ i+NEZ1nzA96lRDyE9Fsopm8lfu6EzQ9Xu6Xpq0MU0IfFoZJwcBPVzNoCBv1tS9DHwRQ3YW+21tkWP Oa9K9ReELCOiiHIjpZRDA3SzCehcaF/NUQCQJgvXr6FoaBglObVITD2gSmeOnjhfH5vrRQ7u8hAF8 ULzrOdGtlPqEkbni2fet62YueoMqGBAWyY1pdn0TaYg1ccKhdnFUe+WrNwWkmt5ZBg6GgGSL7lcRm H7TqTVWFIa6EojHtcvRLf/S53p0ov18Ew5RR3ZaWkpafOG1DUmlLBW63QasYlf9Q4PN3FL4k0hYsy 4tveqfTw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLOia-0000000EEQS-3iZi; Sun, 23 Jun 2024 15:01:24 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLOiX-0000000EEPs-0hdt for linux-arm-kernel@lists.infradead.org; Sun, 23 Jun 2024 15:01:22 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 48A6DCE0EA9; Sun, 23 Jun 2024 15:01:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D699C2BD10; Sun, 23 Jun 2024 15:01:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719154878; bh=pLL5EMg6eoF8fo4wvsJ8liZlmjZcP3+0z3EaGf28jIo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=oZ8Zhmwi++sv43JIaLV3EeEl6tMSMVE08IJQfwF6QpLLYs6I/4wbFsrsOXX5dcEEB XeiTJyJHikVUmlEBINZAFZGwqtpkVL2jTMDlSOooQ/uwCu4hoRcVM7JGy4pg/A/ct0 GL4jsvEtLVRY39ou7VzKS5i5eYfxt6nEBWxbciUr6S8lnlnDNnsIdVxjfOFjdiZS1S D9ZE9/YPS/GIttRocC9evp+dqnEB1CE0zWwnqbDDnzQ34aPUyUtKo3Rm+THXS3miKA E+eQmYJEmJJH9F3bELBzlD9KX5ZQp7En6tDmjZanwFN57mZtsrCDdAt0nAGsjZofGQ jSpdPi6fm+qkQ== Date: Sun, 23 Jun 2024 16:01:11 +0100 From: Jonathan Cameron To: Olivier Moysan Cc: Lars-Peter Clausen , Maxime Coquelin , Alexandre Torgue , , , , Subject: Re: [PATCH 6/8] iio: adc: stm32-dfsdm: adopt generic channels bindings Message-ID: <20240623160111.3a675e0b@jic23-huawei> In-Reply-To: <20240618160836.945242-7-olivier.moysan@foss.st.com> References: <20240618160836.945242-1-olivier.moysan@foss.st.com> <20240618160836.945242-7-olivier.moysan@foss.st.com> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240623_080121_425846_D5138452 X-CRM114-Status: GOOD ( 28.59 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 18 Jun 2024 18:08:32 +0200 Olivier Moysan wrote: > Move to generic channels binding to ease new backend framework adoption > and prepare the convergence with MDF IP support on STM32MP2 SoC family. > > Legacy binding: > DFSDM is an IIO channel consumer. > SD modulator is an IIO channels provider. > The channel phandles are provided in DT through io-channels property > and channel indexes through st,adc-channels property. > > New binding: > DFSDM is an IIO channel provider. > The channel indexes are given by reg property in channel child node. > > This new binding is intended to be used with SD modulator IIO backends. > It does not support SD modulator legacy IIO devices. > The st,adc-channels property presence is used to discriminate > between legacy and backend bindings. > > The support of the DFSDM legacy channels and SD modulator IIO devices > is kept for backward compatibility. > > Signed-off-by: Olivier Moysan Hi Oliver A few minor things inline. Jonathan > --- > drivers/iio/adc/stm32-dfsdm-adc.c | 208 ++++++++++++++++++++++++------ > 1 file changed, 171 insertions(+), 37 deletions(-) > > diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c > index 9a47d2c87f05..69b4764d7cba 100644 > --- a/drivers/iio/adc/stm32-dfsdm-adc.c > +++ b/drivers/iio/adc/stm32-dfsdm-adc.c > @@ -666,6 +666,64 @@ static int stm32_dfsdm_channel_parse_of(struct stm32_dfsdm *dfsdm, > return 0; > } > > +static int stm32_dfsdm_generic_channel_parse_of(struct stm32_dfsdm *dfsdm, > + struct iio_dev *indio_dev, > + struct iio_chan_spec *ch, > + struct fwnode_handle *node) > +{ > + struct stm32_dfsdm_channel *df_ch; > + const char *of_str; > + int ret, val; > + > + ret = fwnode_property_read_u32(node, "reg", &ch->channel); > + if (ret < 0) { > + dev_err(&indio_dev->dev, "Missing channel index %d\n", ret); > + return ret; > + } > + > + if (ch->channel >= dfsdm->num_chs) { > + dev_err(&indio_dev->dev, " Error bad channel number %d (max = %d)\n", > + ch->channel, dfsdm->num_chs); > + return -EINVAL; > + } > + > + ret = fwnode_property_read_string(node, "label", &ch->datasheet_name); > + if (ret < 0) { > + dev_err(&indio_dev->dev, > + " Error parsing 'label' for idx %d\n", ch->channel); > + return ret; > + } > + > + df_ch = &dfsdm->ch_list[ch->channel]; > + df_ch->id = ch->channel; > + > + ret = fwnode_property_read_string(node, "st,adc-channel-types", &of_str); > + if (!ret) { > + val = stm32_dfsdm_str2val(of_str, stm32_dfsdm_chan_type); > + if (val < 0) > + return val; > + } else { > + val = 0; Sometimes better to set a default, then override if if the property is read successfully. df_ch->type = 0; if (!fwnode_property_read_string()) { int val = ... df_ch->type = val; } etc > + } > + df_ch->type = val; > + > + ret = fwnode_property_read_string(node, "st,adc-channel-clk-src", &of_str); > + if (!ret) { > + val = stm32_dfsdm_str2val(of_str, stm32_dfsdm_chan_src); > + if (val < 0) > + return val; > + } else { > + val = 0; > + } > + df_ch->src = val; > + > + ret = fwnode_property_read_u32(node, "st,adc-alt-channel", &df_ch->alt_si); > + if (ret != -EINVAL) > + df_ch->alt_si = 0; I'm confused. If it does == EINVAL we just silently carry on with alt_si sort of undefined. I guess 0? > + > + return 0; > +} > + ... > +static int stm32_dfsdm_chan_init(struct iio_dev *indio_dev, struct iio_chan_spec *channels) > +{ > + int num_ch = indio_dev->num_channels; > + int chan_idx = 0, ret = 0; > + > + for (chan_idx = 0; chan_idx < num_ch; chan_idx++) { > + channels[chan_idx].scan_index = chan_idx; > + ret = stm32_dfsdm_adc_chan_init_one(indio_dev, &channels[chan_idx], NULL); > + if (ret < 0) { > + dev_err(&indio_dev->dev, "Channels init failed\n"); > + return ret; > + } > + } > + > + return ret; return 0; I don't think it's ever positive and can't get here with it negative. > +} > + > +static int stm32_dfsdm_generic_chan_init(struct iio_dev *indio_dev, struct iio_chan_spec *channels) > +{ > + struct fwnode_handle *child; > + int chan_idx = 0, ret; > + > + device_for_each_child_node(&indio_dev->dev, child) { device_for_each_child_node_scoped() and direct returns should tidy this up a tiny bit. > + /* Skip DAI node in DFSDM audio nodes */ > + if (fwnode_property_present(child, "compatible")) > + continue; > + > + channels[chan_idx].scan_index = chan_idx; > + ret = stm32_dfsdm_adc_chan_init_one(indio_dev, &channels[chan_idx], child); > + if (ret < 0) { > + dev_err(&indio_dev->dev, "Channels init failed\n"); > + goto err; This is consistent with existing code, but would be nice to make extensive use of dev_err_probe() in this driver and this is a gone place for that. return dev_err_probe(indio_dev->dev, ret, "...); > + } > + > + chan_idx++; > + } > + return chan_idx; > + > +err: > + fwnode_handle_put(child); > + > + return ret; > } >