Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3937916imb; Wed, 6 Mar 2019 01:01:09 -0800 (PST) X-Google-Smtp-Source: APXvYqy0AQsyZczazmAaNHH3ZsaLrTv1JMlpN+tJnUu0+f6l92QCZnaXP/gJpWejgvH1K740h7Nh X-Received: by 2002:aa7:854d:: with SMTP id y13mr6170136pfn.175.1551862868947; Wed, 06 Mar 2019 01:01:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551862868; cv=none; d=google.com; s=arc-20160816; b=P+K+J5C2dONpioKLFqLdYOjpcHdjABQLRCgLnE/VPl+cWu5519BTbactZwJqyCmvEO 3huCx1WIXXS9nX8V4SBkp2zDMOuEi2HrzEq94658Ouh+pYBWoxu4S7s4MB5TT9TsaRgq S5AJN7UGpx6DOl0lbXKRpwURDXcUyBU/CDpq3n4HjHGW+qMFuiAOjzANXw8zX4li4ldy yF+vAp6U8RPO9/36W8cZHG9/vbDNPjMMSysg6kygWT8HITo3XEgw+MGQQVjPNDwNZqlA 01v6InY2cwMnNap1w9xyW+jdBi6WIGY05pBPOKQaQxgX0IFtpu6a1EJvpfbYJa5LB+u5 a1Yg== 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=m16qivLJFrFIpuvrGCGwDSSRFR8gd0jrhSptt5C6UOA=; b=xC6aX/RZXOInAlNiA7oMSh7vf17IFdXcf4tutZCM4dV2gRkxw9wRrSiM4UAtC6aROy 3SVjYul87T2u8AS9jLZxXwOEWkJtmAM/vdzdxHd/5DHMF0NHweRQ/8Nj0TCnNIOYYesQ BMdzFJ6zrnxseKT3B1QejqSF3XxSA6Ae2Zyz5DLJCLoreMRBkgNh4w9eqhxv/VYjBHNw s6O6o6oDWsCR9SfmYd88qqtCrn6dqd3e/s6JVKCT7pOK6YP9oERJ7Yw/msEwfqh/6rhU mxnxo5dWQuyFLRPx04LEyUtt0XlGd2O93Y38eowj1FgZBk5g8rvOIkE6DhtEaMNm3K6A gHHA== 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 e9si950457pgg.199.2019.03.06.01.00.53; Wed, 06 Mar 2019 01:01:08 -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 S1729192AbfCFI4S (ORCPT + 99 others); Wed, 6 Mar 2019 03:56:18 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:20649 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728438AbfCFI4R (ORCPT ); Wed, 6 Mar 2019 03:56:17 -0500 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x268sqWW015101; Wed, 6 Mar 2019 09:55:55 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2qyhgaxr3x-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 06 Mar 2019 09:55:55 +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 A8F353A; Wed, 6 Mar 2019 08:55:53 +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 67E5E2409; Wed, 6 Mar 2019 08:55:53 +0000 (GMT) Received: from localhost (10.75.127.45) by SFHDAG5NODE3.st.com (10.75.127.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 6 Mar 2019 09:55:52 +0100 From: Fabrice Gasnier To: CC: , , , , , , , , , , , Subject: [PATCH 8/8] iio: adc: stm32-dfsdm: claim direct mode for raw read and settings Date: Wed, 6 Mar 2019 09:55:24 +0100 Message-ID: <1551862524-25098-9-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.45] X-ClientProxiedBy: SFHDAG4NODE2.st.com (10.75.127.11) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-06_04:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Claim direct mode to ensure no buffer mode is in use for: - single conversion - sample rate setting (must be set when filter isn't enabled). - oversampling ratio (must be set when filter isn't enabled). Signed-off-by: Fabrice Gasnier --- drivers/iio/adc/stm32-dfsdm-adc.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c index 51688eb..ca42946 100644 --- a/drivers/iio/adc/stm32-dfsdm-adc.c +++ b/drivers/iio/adc/stm32-dfsdm-adc.c @@ -1039,16 +1039,23 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; ret = stm32_dfsdm_set_osrs(fl, 0, val); if (!ret) adc->oversamp = val; - + iio_device_release_direct_mode(indio_dev); return ret; case IIO_CHAN_INFO_SAMP_FREQ: if (!val) return -EINVAL; + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + switch (ch->src) { case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL: spi_freq = adc->dfsdm->spi_master_freq; @@ -1070,9 +1077,11 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, if (ret < 0) { dev_err(&indio_dev->dev, "Not able to find parameter that match!\n"); + iio_device_release_direct_mode(indio_dev); return ret; } adc->sample_freq = val; + iio_device_release_direct_mode(indio_dev); return 0; } @@ -1089,11 +1098,15 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; ret = iio_hw_consumer_enable(adc->hwc); if (ret < 0) { dev_err(&indio_dev->dev, "%s: IIO enable failed (channel %d)\n", __func__, chan->channel); + iio_device_release_direct_mode(indio_dev); return ret; } ret = stm32_dfsdm_single_conv(indio_dev, chan, val); @@ -1102,8 +1115,10 @@ static int stm32_dfsdm_read_raw(struct iio_dev *indio_dev, dev_err(&indio_dev->dev, "%s: Conversion failed (channel %d)\n", __func__, chan->channel); + iio_device_release_direct_mode(indio_dev); return ret; } + iio_device_release_direct_mode(indio_dev); return IIO_VAL_INT; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: -- 2.7.4