Received: by 10.223.185.116 with SMTP id b49csp1826105wrg; Sat, 24 Feb 2018 05:02:35 -0800 (PST) X-Google-Smtp-Source: AH8x2274StCcn+r08mMW4i12p5wg9o3Nx2t9cc3rNE2VnzL67bXNh0LibiDWxLKUi0f6Q9n6vFUv X-Received: by 10.99.44.22 with SMTP id s22mr3968177pgs.111.1519477355263; Sat, 24 Feb 2018 05:02:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519477355; cv=none; d=google.com; s=arc-20160816; b=kbsNOE240E1t9Vo5mJzcESVCes+kPMvlS/nd+4tuToxGI+6jv5b2aWyOL4ifkGJ/V4 TpE1RqyGcBj4Hk4q5FcWkJfg9jafRFR29mkR1uq2ajLbkkEZ2TVH2VmtKLmwJo3SL6sQ HQ++VjOp8nvE3R5cY61I6fE1eTLNK3tJgtiYM1vVmvM7xBy7Coa4ZTNbofQGNiEtBsTL U24iGxrSFos9S5zjh1SHuU6X+gtSGvBfqmGVC3xLWhoLwrDQZEyATMgva4InfOzAG1Fx mtvx4YUrHwl3bYMzNHAyzqImpopd+1CTzEB6ylgYPA83i+95/vUoaBtQsThpc2ZTga9R 4+vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dmarc-filter:arc-authentication-results; bh=mZu4qYGFuhFtHwY0SxrdBNc4fQ2OiHYMp5THtYnlvDs=; b=goawtAEA22ejQuPRjkQYIQ1TWnrTYe6c130k5e2rBXjucXwxJlQ8PiM3mFs9zXVcqX 3SxuRP0QiWa1iYlBRzIGGLT7bXzTII/4IVNooIGPG7QY8fcfBO9F7v2+rWARLNxdi+kB bgjmf6BP3uATD+hZaVlmmvYhD1weMer4H7j02/hMEJzh3htQ1Ae4ftGy7xPSezSxG2Dk lvG1l7/3Z/lnYyESUK+dd9D3Nxk7KTWlCVLxlCI1GWi+DHJTqt5NUuqjV8zsrROwmDwi RJW/u/k2gKuoaPzG+8jmV2Qb43P60WRo6rsxGPd/nqfexDVhRw5CxRtEiaCwiwKx0yMt MKww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m70si3546138pfk.201.2018.02.24.05.02.20; Sat, 24 Feb 2018 05:02:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751440AbeBXNBn (ORCPT + 99 others); Sat, 24 Feb 2018 08:01:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:46500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750934AbeBXNBl (ORCPT ); Sat, 24 Feb 2018 08:01:41 -0500 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (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 4D1C3214C5; Sat, 24 Feb 2018 13:01:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D1C3214C5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=jic23@kernel.org Date: Sat, 24 Feb 2018 13:01:36 +0000 From: Jonathan Cameron To: Fabrice Gasnier Cc: , , , , , , , , , Subject: Re: [PATCH 4/7] iio: adc: stm32-dfsdm: fix multiple channel initialization Message-ID: <20180224130136.0e4fae4b@archlinux> In-Reply-To: <1519390261-25453-5-git-send-email-fabrice.gasnier@st.com> References: <1519390261-25453-1-git-send-email-fabrice.gasnier@st.com> <1519390261-25453-5-git-send-email-fabrice.gasnier@st.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 23 Feb 2018 13:50:58 +0100 Fabrice Gasnier wrote: > When several channels are registered (e.g. via st,adc-channels property): > - channels array is wrongly filled in. Only 1st element in array is being > initialized with last registered channel. > Fix it by passing reference to relevant channel (e.g. array[index]). > - only last initialized channel can work properly (e.g. unique 'ch_id' > is used). Converting any other channel result in conversion timeout. > Fix it by getting rid of 'ch_id', use chan->channel instead. > > Signed-off-by: Fabrice Gasnier Applied to the fixes-togreg branch of iio.git. Thanks, Jonathan > --- > drivers/iio/adc/stm32-dfsdm-adc.c | 39 +++++++++++++++++++++------------------ > 1 file changed, 21 insertions(+), 18 deletions(-) > > diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c > index 0eff811..01422d1 100644 > --- a/drivers/iio/adc/stm32-dfsdm-adc.c > +++ b/drivers/iio/adc/stm32-dfsdm-adc.c > @@ -54,7 +54,6 @@ struct stm32_dfsdm_adc { > struct stm32_dfsdm *dfsdm; > const struct stm32_dfsdm_dev_data *dev_data; > unsigned int fl_id; > - unsigned int ch_id; > > /* ADC specific */ > unsigned int oversamp; > @@ -384,7 +383,7 @@ static ssize_t dfsdm_adc_audio_set_spiclk(struct iio_dev *indio_dev, > { > struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); > struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id]; > - struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[adc->ch_id]; > + struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel]; > unsigned int sample_freq = adc->sample_freq; > unsigned int spi_freq; > int ret; > @@ -419,18 +418,20 @@ static ssize_t dfsdm_adc_audio_set_spiclk(struct iio_dev *indio_dev, > return len; > } > > -static int stm32_dfsdm_start_conv(struct stm32_dfsdm_adc *adc, bool dma) > +static int stm32_dfsdm_start_conv(struct stm32_dfsdm_adc *adc, > + const struct iio_chan_spec *chan, > + bool dma) > { > struct regmap *regmap = adc->dfsdm->regmap; > int ret; > unsigned int dma_en = 0, cont_en = 0; > > - ret = stm32_dfsdm_start_channel(adc->dfsdm, adc->ch_id); > + ret = stm32_dfsdm_start_channel(adc->dfsdm, chan->channel); > if (ret < 0) > return ret; > > ret = stm32_dfsdm_filter_configure(adc->dfsdm, adc->fl_id, > - adc->ch_id); > + chan->channel); > if (ret < 0) > goto stop_channels; > > @@ -464,12 +465,13 @@ static int stm32_dfsdm_start_conv(struct stm32_dfsdm_adc *adc, bool dma) > > regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id), > DFSDM_CR1_RCONT_MASK, 0); > - stm32_dfsdm_stop_channel(adc->dfsdm, adc->ch_id); > + stm32_dfsdm_stop_channel(adc->dfsdm, chan->channel); > > return ret; > } > > -static void stm32_dfsdm_stop_conv(struct stm32_dfsdm_adc *adc) > +static void stm32_dfsdm_stop_conv(struct stm32_dfsdm_adc *adc, > + const struct iio_chan_spec *chan) > { > struct regmap *regmap = adc->dfsdm->regmap; > > @@ -482,7 +484,7 @@ static void stm32_dfsdm_stop_conv(struct stm32_dfsdm_adc *adc) > regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id), > DFSDM_CR1_RCONT_MASK, 0); > > - stm32_dfsdm_stop_channel(adc->dfsdm, adc->ch_id); > + stm32_dfsdm_stop_channel(adc->dfsdm, chan->channel); > } > > static int stm32_dfsdm_set_watermark(struct iio_dev *indio_dev, > @@ -609,6 +611,7 @@ static int stm32_dfsdm_adc_dma_start(struct iio_dev *indio_dev) > static int stm32_dfsdm_postenable(struct iio_dev *indio_dev) > { > struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); > + const struct iio_chan_spec *chan = &indio_dev->channels[0]; > int ret; > > /* Reset adc buffer index */ > @@ -618,7 +621,7 @@ static int stm32_dfsdm_postenable(struct iio_dev *indio_dev) > if (ret < 0) > return ret; > > - ret = stm32_dfsdm_start_conv(adc, true); > + ret = stm32_dfsdm_start_conv(adc, chan, true); > if (ret) { > dev_err(&indio_dev->dev, "Can't start conversion\n"); > goto stop_dfsdm; > @@ -635,7 +638,7 @@ static int stm32_dfsdm_postenable(struct iio_dev *indio_dev) > return 0; > > err_stop_conv: > - stm32_dfsdm_stop_conv(adc); > + stm32_dfsdm_stop_conv(adc, chan); > stop_dfsdm: > stm32_dfsdm_stop_dfsdm(adc->dfsdm); > > @@ -645,11 +648,12 @@ static int stm32_dfsdm_postenable(struct iio_dev *indio_dev) > static int stm32_dfsdm_predisable(struct iio_dev *indio_dev) > { > struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); > + const struct iio_chan_spec *chan = &indio_dev->channels[0]; > > if (adc->dma_chan) > dmaengine_terminate_all(adc->dma_chan); > > - stm32_dfsdm_stop_conv(adc); > + stm32_dfsdm_stop_conv(adc, chan); > > stm32_dfsdm_stop_dfsdm(adc->dfsdm); > > @@ -730,7 +734,7 @@ static int stm32_dfsdm_single_conv(struct iio_dev *indio_dev, > if (ret < 0) > goto stop_dfsdm; > > - ret = stm32_dfsdm_start_conv(adc, false); > + ret = stm32_dfsdm_start_conv(adc, chan, false); > if (ret < 0) { > regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id), > DFSDM_CR2_REOCIE_MASK, DFSDM_CR2_REOCIE(0)); > @@ -751,7 +755,7 @@ static int stm32_dfsdm_single_conv(struct iio_dev *indio_dev, > else > ret = IIO_VAL_INT; > > - stm32_dfsdm_stop_conv(adc); > + stm32_dfsdm_stop_conv(adc, chan); > > stop_dfsdm: > stm32_dfsdm_stop_dfsdm(adc->dfsdm); > @@ -765,7 +769,7 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, > { > struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); > struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id]; > - struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[adc->ch_id]; > + struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel]; > unsigned int spi_freq = adc->spi_freq; > int ret = -EINVAL; > > @@ -972,7 +976,6 @@ static int stm32_dfsdm_adc_chan_init_one(struct iio_dev *indio_dev, > } > ch->scan_type.realbits = 24; > ch->scan_type.storagebits = 32; > - adc->ch_id = ch->channel; > > return stm32_dfsdm_chan_configure(adc->dfsdm, > &adc->dfsdm->ch_list[ch->channel]); > @@ -1001,7 +1004,7 @@ static int stm32_dfsdm_audio_init(struct iio_dev *indio_dev) > } > ch->info_mask_separate = BIT(IIO_CHAN_INFO_SAMP_FREQ); > > - d_ch = &adc->dfsdm->ch_list[adc->ch_id]; > + d_ch = &adc->dfsdm->ch_list[ch->channel]; > if (d_ch->src != DFSDM_CHANNEL_SPI_CLOCK_EXTERNAL) > adc->spi_freq = adc->dfsdm->spi_master_freq; > > @@ -1042,8 +1045,8 @@ static int stm32_dfsdm_adc_init(struct iio_dev *indio_dev) > return -ENOMEM; > > for (chan_idx = 0; chan_idx < num_ch; chan_idx++) { > - ch->scan_index = chan_idx; > - ret = stm32_dfsdm_adc_chan_init_one(indio_dev, ch); > + ch[chan_idx].scan_index = chan_idx; > + ret = stm32_dfsdm_adc_chan_init_one(indio_dev, &ch[chan_idx]); > if (ret < 0) { > dev_err(&indio_dev->dev, "Channels init failed\n"); > return ret;