Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5510709ybc; Wed, 27 Nov 2019 05:15:04 -0800 (PST) X-Google-Smtp-Source: APXvYqw8JKV5X/QH2Au4uArpyMLglMDWgh837hV4w8rtRvuf2GWRO1IbmmU3VWcxDZEN3kIQOxuz X-Received: by 2002:aa7:c25a:: with SMTP id y26mr26987926edo.248.1574860504611; Wed, 27 Nov 2019 05:15:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574860504; cv=none; d=google.com; s=arc-20160816; b=NOxJ5zb+tWH1Z/spc6gM7QavJULmf67o9wCInkBFhsWsu27+SDVP77IdsPFwgap9Kj 4mbQ76jqexU7jsmJ5zfiZNEE3OOi7tdf5xV/tQhwWcG4rbH8LjLkag95AprDMUFZF5sU rFM5nd9hOtvE7INnPDiRKWzeYlW39HdiyodsN+WT0l5Rmtxt0BoKMXJ6KATZxQuGye/i /0y+va2BwxxfHNKBkWIhfOrS5xm6A+AL0g2xy8LVxJBAddor77IFYH2qvOGI1zwl9JiP 6vIqz0vyBn2Fj1tqjIGtX3+BnjS53oBJhx5D80/o6neUEDGNE/sXpPVRJqJ2cgPaRxh5 u1Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:to :from:dkim-signature; bh=igm3D/p5FLqgRVPoSI6/qpaaV5+h4X7oZSLPmG0YbEs=; b=N2I7Kzaf1PGcam7U2ZPAIJEF9N8TmWl7CQfooNG8da5Wdmv0F72qWLQUI69SVqIitz eYb2spyfJuDPaY1TKMsOwatwSzDiaMqEBefWC2J8csXYOwHwGVPdRbwob4KyNR9RMqFz oTElEnr/zIy7uU0Xi/PBlIvN/5dLWpJ2jxG6IAAePJMKyT9g8KGNj4V9ZZVBjqAOCYhz 7DiwHD/f2/acktcCycYsnt1YA/V3tpDXnANimT3wI6zYFdaw4mSXQrv7NzaskDPu3mWf dc82CJ5hDUiNIOtP5i+x1s7a/oVWqi0EjFmrLUUrts1RAclmGaAtT1ue3uBdk4vnXS34 pdxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=Pl4afNHN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=st.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si9314922ejs.376.2019.11.27.05.14.38; Wed, 27 Nov 2019 05:15:04 -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; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=Pl4afNHN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726980AbfK0NKn (ORCPT + 99 others); Wed, 27 Nov 2019 08:10:43 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:53654 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726514AbfK0NKn (ORCPT ); Wed, 27 Nov 2019 08:10:43 -0500 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id xARD7OtN030867; Wed, 27 Nov 2019 14:10:23 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : subject : date : message-id : mime-version : content-type; s=STMicroelectronics; bh=igm3D/p5FLqgRVPoSI6/qpaaV5+h4X7oZSLPmG0YbEs=; b=Pl4afNHN1aK10wyyNGAR27PgIqU77ofhi97vGCRs4bix8f9y69Qpw3uz/P9pac/RAulQ bblmjkI5VI7Asio9kHK7jCtpAhQTvDygYIq6FKSI5ud3AIBJ+/hPAjX6Lxenj2yLgJ7O Lj2897qrdAo4t2Y4GEl/UPr9sq1/H3eVBqmQvU6BmdgMWR3HG5aPAFSWvDqwSLQhPlXW kegyo5tXrfG8McywOXcQ5Imi1kxzGBJvjyIjym7e/HTjA7sKESKhCYhlD181KUmcfrmb urksOvSikTwc/mBeKMB+bWOIwpCOPEzcMBTkDOojhyJOdM9e0Uvv/Oa5Xm1KS145YXX8 HQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2whcxybt1q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Nov 2019 14:10:22 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 76DC5100034; Wed, 27 Nov 2019 14:10:22 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag6node2.st.com [10.75.127.17]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 58DA82B8B2C; Wed, 27 Nov 2019 14:10:22 +0100 (CET) Received: from localhost (10.75.127.44) by SFHDAG6NODE2.st.com (10.75.127.17) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 27 Nov 2019 14:10:21 +0100 From: Olivier Moysan To: , , , , , , , , , , , , Subject: [PATCH v2] iio: adc: stm32-dfsdm: adapt sampling rate to oversampling ratio Date: Wed, 27 Nov 2019 14:10:08 +0100 Message-ID: <20191127131008.18896-1-olivier.moysan@st.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG6NODE2.st.com (10.75.127.17) To SFHDAG6NODE2.st.com (10.75.127.17) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,18.0.572 definitions=2019-11-27_02:2019-11-27,2019-11-27 signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Update sampling rate when oversampling ratio is changed through the IIO ABI. Signed-off-by: Olivier Moysan --- changes in version 2: - correct title --- drivers/iio/adc/stm32-dfsdm-adc.c | 32 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c index 0339ecdd06bd..87a842507509 100644 --- a/drivers/iio/adc/stm32-dfsdm-adc.c +++ b/drivers/iio/adc/stm32-dfsdm-adc.c @@ -1221,14 +1221,32 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, unsigned int spi_freq; int ret = -EINVAL; + switch (ch->src) { + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL: + spi_freq = adc->dfsdm->spi_master_freq; + break; + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING: + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING: + spi_freq = adc->dfsdm->spi_master_freq / 2; + break; + default: + spi_freq = adc->spi_freq; + } + switch (mask) { case IIO_CHAN_INFO_OVERSAMPLING_RATIO: ret = iio_device_claim_direct_mode(indio_dev); if (ret) return ret; + ret = stm32_dfsdm_compute_all_osrs(indio_dev, val); - if (!ret) + if (!ret) { + dev_dbg(&indio_dev->dev, + "Sampling rate changed from (%u) to (%u)\n", + adc->sample_freq, spi_freq / val); adc->oversamp = val; + adc->sample_freq = spi_freq / val; + } iio_device_release_direct_mode(indio_dev); return ret; @@ -1240,18 +1258,6 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, if (ret) return ret; - switch (ch->src) { - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL: - spi_freq = adc->dfsdm->spi_master_freq; - break; - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING: - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING: - spi_freq = adc->dfsdm->spi_master_freq / 2; - break; - default: - spi_freq = adc->spi_freq; - } - ret = dfsdm_adc_set_samp_freq(indio_dev, val, spi_freq); iio_device_release_direct_mode(indio_dev); return ret; -- 2.17.1