Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3952308imb; Wed, 6 Mar 2019 01:25:36 -0800 (PST) X-Google-Smtp-Source: APXvYqzANylgBKodW1+NzJpVki/mNdqq+A182hbUaSadvNmcixA72yUoBUw9Ljlvfaf9YOM5WA5x X-Received: by 2002:a65:6546:: with SMTP id a6mr5501311pgw.296.1551864336330; Wed, 06 Mar 2019 01:25:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551864336; cv=none; d=google.com; s=arc-20160816; b=qlEZVwv6vwOwDF59p7gdcx2X6vPdPDyTsKjms/sxf9BXYiA4lfNZ7L8MoK1M+XupEX lRq4cxodQocXzWCjenofVgoqk/gnPe54l20CntlUhxppM9VuzNXvJnfnAOYw+QZtMEdL IVq9pSxhI9fgszfGqKrvwg64xcwZn8X4VCKn9QJh1YRAWHKIEMQhF/rRVP9EunCJyi7c UCVVb3atXDmeukvy7x9kMakL305Ppi67Fd4uvsp5l32GneX8vO0vAkkc/7qgO/mvtaPG fwoVCHF8AubC3+/gFdTjrwDMGKIIIn/3CGllyq60AXbrYbETHhya+WK7fCkBSYz61FFA 2DaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=R9JcBriSpy1rCz6qNpMkw5k+Bj9e63JXGLq5stcOuug=; b=ZfvtSfvpYZmlTF1q8a5NIrlI2noDBgaxecf08mBpnbgoCcyS74LBesORRTAuCmywjE iuA5hvro86w6L1NpBsE9KYbAWd+57gwyrUrmSvkHI7Q4e/V+jIiPP5oNdbW/FpXG3CAX USJPbbgG+oMxuJ5q9k9pv6aO6gddnei/MlndyO+IzRc5zDDg3+NffTMXSkPjr9a+TKg9 ORE23SBdnjlucfYy6QYE2eBO08s2+RvPBT7EHoXC9bJ68VgLGr9qOcnU9vrnh4p6sUft JeMl6P4CvUJ4xOw6wUgmIAos4j/zRvQxs9hR7xLeTPa3mUX0t/MwUBldNp74pGa/C4ua M0dA== 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 o2si991369pgh.565.2019.03.06.01.25.21; Wed, 06 Mar 2019 01:25:36 -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 S1729414AbfCFI4U (ORCPT + 99 others); Wed, 6 Mar 2019 03:56:20 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:58447 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728899AbfCFI4S (ORCPT ); Wed, 6 Mar 2019 03:56:18 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x268p4Wg001186; Wed, 6 Mar 2019 09:55:50 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2r0ju8yewt-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 06 Mar 2019 09:55:50 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 5AA1841; Wed, 6 Mar 2019 08:55:49 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node3.st.com [10.75.127.15]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C53772400; Wed, 6 Mar 2019 08:55:48 +0000 (GMT) Received: from localhost (10.75.127.44) by SFHDAG5NODE3.st.com (10.75.127.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 6 Mar 2019 09:55:48 +0100 From: Fabrice Gasnier To: CC: , , , , , , , , , , , Subject: [PATCH 2/8] iio: adc: stm32-dfsdm: continuous mode depends on current mode Date: Wed, 6 Mar 2019 09:55:18 +0100 Message-ID: <1551862524-25098-3-git-send-email-fabrice.gasnier@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1551862524-25098-1-git-send-email-fabrice.gasnier@st.com> References: <1551862524-25098-1-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG5NODE1.st.com (10.75.127.13) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-06_06:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org DFSDM regular continuous mode usage depends on current mode (not DMA): - for single conversion, RCONT doesn't need to be set. - for buffer mode, RCONT has to be set (e.g. INDIO_BUFFER_SOFTWARE used by audio currently). This is related to filter configuration, move it to relevant routine. This is precursor patch to ease support of triggered buffer mode. Signed-off-by: Fabrice Gasnier --- drivers/iio/adc/stm32-dfsdm-adc.c | 54 +++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c index fcd4a1c..8690672 100644 --- a/drivers/iio/adc/stm32-dfsdm-adc.c +++ b/drivers/iio/adc/stm32-dfsdm-adc.c @@ -38,6 +38,10 @@ #define DFSDM_MAX_RES BIT(31) #define DFSDM_DATA_RES BIT(23) +/* Filter configuration */ +#define DFSDM_CR1_CFG_MASK (DFSDM_CR1_RCH_MASK | DFSDM_CR1_RCONT_MASK | \ + DFSDM_CR1_RSYNC_MASK) + enum sd_converter_type { DFSDM_AUDIO, DFSDM_IIO, @@ -262,11 +266,13 @@ static void stm32_dfsdm_stop_filter(struct stm32_dfsdm *dfsdm, DFSDM_CR1_DFEN_MASK, DFSDM_CR1_DFEN(0)); } -static int stm32_dfsdm_filter_configure(struct stm32_dfsdm *dfsdm, +static int stm32_dfsdm_filter_configure(struct stm32_dfsdm_adc *adc, unsigned int fl_id, unsigned int ch_id) { - struct regmap *regmap = dfsdm->regmap; - struct stm32_dfsdm_filter *fl = &dfsdm->fl_list[fl_id]; + struct iio_dev *indio_dev = iio_priv_to_dev(adc); + struct regmap *regmap = adc->dfsdm->regmap; + struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[fl_id]; + u32 cr1; int ret; /* Average integrator oversampling */ @@ -287,14 +293,16 @@ static int stm32_dfsdm_filter_configure(struct stm32_dfsdm *dfsdm, return ret; /* No scan mode supported for the moment */ - ret = regmap_update_bits(regmap, DFSDM_CR1(fl_id), DFSDM_CR1_RCH_MASK, - DFSDM_CR1_RCH(ch_id)); - if (ret) - return ret; + cr1 = DFSDM_CR1_RCH(ch_id); + + /* Continuous conversions triggered by SPI clock in buffer mode */ + if (indio_dev->currentmode & INDIO_BUFFER_SOFTWARE) + cr1 |= DFSDM_CR1_RCONT(1); - return regmap_update_bits(regmap, DFSDM_CR1(fl_id), - DFSDM_CR1_RSYNC_MASK, - DFSDM_CR1_RSYNC(fl->sync_mode)); + cr1 |= DFSDM_CR1_RSYNC(fl->sync_mode); + + return regmap_update_bits(regmap, DFSDM_CR1(fl_id), DFSDM_CR1_CFG_MASK, + cr1); } static int stm32_dfsdm_channel_parse_of(struct stm32_dfsdm *dfsdm, @@ -426,47 +434,39 @@ static int stm32_dfsdm_start_conv(struct stm32_dfsdm_adc *adc, { struct regmap *regmap = adc->dfsdm->regmap; int ret; - unsigned int dma_en = 0, cont_en = 0; + unsigned int dma_en = 0; ret = stm32_dfsdm_start_channel(adc->dfsdm, chan->channel); if (ret < 0) return ret; - ret = stm32_dfsdm_filter_configure(adc->dfsdm, adc->fl_id, - chan->channel); + ret = stm32_dfsdm_filter_configure(adc, adc->fl_id, chan->channel); if (ret < 0) goto stop_channels; if (dma) { /* Enable DMA transfer*/ dma_en = DFSDM_CR1_RDMAEN(1); - /* Enable conversion triggered by SPI clock*/ - cont_en = DFSDM_CR1_RCONT(1); } /* Enable DMA transfer*/ ret = regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id), DFSDM_CR1_RDMAEN_MASK, dma_en); if (ret < 0) - goto stop_channels; - - /* Enable conversion triggered by SPI clock*/ - ret = regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id), - DFSDM_CR1_RCONT_MASK, cont_en); - if (ret < 0) - goto stop_channels; + goto filter_unconfigure; ret = stm32_dfsdm_start_filter(adc->dfsdm, adc->fl_id); if (ret < 0) - goto stop_channels; + goto stop_dma; return 0; -stop_channels: +stop_dma: regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id), DFSDM_CR1_RDMAEN_MASK, 0); - +filter_unconfigure: regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id), - DFSDM_CR1_RCONT_MASK, 0); + DFSDM_CR1_CFG_MASK, 0); +stop_channels: stm32_dfsdm_stop_channel(adc->dfsdm, chan->channel); return ret; @@ -484,7 +484,7 @@ static void stm32_dfsdm_stop_conv(struct stm32_dfsdm_adc *adc, DFSDM_CR1_RDMAEN_MASK, 0); regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id), - DFSDM_CR1_RCONT_MASK, 0); + DFSDM_CR1_CFG_MASK, 0); stm32_dfsdm_stop_channel(adc->dfsdm, chan->channel); } -- 2.7.4