From patchwork Wed Aug 3 10:28:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 12935379 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 615C8C19F28 for ; Wed, 3 Aug 2022 10:29:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nHdif3x8sWQVnl260yH3NvvWnBx4a70+Dy9Kiw66Yhk=; b=KByd1O+swHlC7t yjWw4/WABhYHXfy1sIrXqByhswtc1rbwOS/gezNpPcq8dFzWWA7wLTZzPFwskrEE9nQqtcngEa9x2 Tfy+ios9nDmkB5qt/l7ETz+QA6IQyKtQCkjecMBynkyyrryYXmohhrj6vMcyq8/f6Mb6XYg5y5NaQ D0btNHKt0TStQjm2SvhGwyCTGJ56/m6K46jzoLYQHFF28SUxkv+MptyAUB3MLUHPCk+v+qsPwL1yu rJGw14esuoKTZYu/Ok2Gv3LF4DBxbnJUbkuTRCtsYk/6ThMTgqHImlwg4InpO4xkNbJo+M9jk72gU FJzLmFV7AN9M7mryR5Iw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJBbZ-004pwL-PW; Wed, 03 Aug 2022 10:27:58 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJBah-004pJF-65 for linux-arm-kernel@lists.infradead.org; Wed, 03 Aug 2022 10:27:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1659522423; x=1691058423; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vs9ZAQ46uCeJMUwjZs++ilJZjlW5m48lwQpyLCI2ESo=; b=lNnHPs0C1r+EdIxAuGtMsVzG9F34KdCHQ3R1rGPmKKom8haxHt3SOWF1 tlSgcnlwYQipMtHDqZ+jfuAm/eYLUit7yxX9U2hlzk7WxLzg9Ev8oQVPG SZU7AEFbQP8htxdk+u+iTJlh7tsK5freA1f67Xpov1Ezwxv7ZCz9RSOFJ 2ZY4DGgPYFJTtOuR+8l0c/41JHuV87LRX1dbCIdn9xnt6uhUH01gcqeck TKzslnBZ3D5e4OwrgycnYcCv/OIi5+lATRmnIzj1+MPuHoL62Ca4kqkmo guPiLcYxaksXwDweZGcq4xi6FZx/EnO0Jx2To0dhxXpFQWS8dDFgnvfSe g==; X-IronPort-AV: E=Sophos;i="5.93,214,1654585200"; d="scan'208";a="170757307" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 03 Aug 2022 03:26:54 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Wed, 3 Aug 2022 03:26:53 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2375.28 via Frontend Transport; Wed, 3 Aug 2022 03:26:51 -0700 From: Claudiu Beznea To: , , , , , , CC: , , , , Claudiu Beznea Subject: [PATCH v3 05/19] iio: adc: at91-sama5d2_adc: exit from write_raw() when buffers are enabled Date: Wed, 3 Aug 2022 13:28:41 +0300 Message-ID: <20220803102855.2191070-6-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220803102855.2191070-1-claudiu.beznea@microchip.com> References: <20220803102855.2191070-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220803_032703_637893_C2FF6F67 X-CRM114-Status: GOOD ( 12.01 ) 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 When buffers are enabled conversion may start asynchronously thus allowing changes on actual hardware could lead to bad behavior. Thus do not allow changing oversampling ratio and sample frequency when if iio_device_claim_direct_mode() returns with error. Signed-off-by: Claudiu Beznea --- drivers/iio/adc/at91-sama5d2_adc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c index e2c82c5a2fac..64943d8ea869 100644 --- a/drivers/iio/adc/at91-sama5d2_adc.c +++ b/drivers/iio/adc/at91-sama5d2_adc.c @@ -1641,6 +1641,7 @@ static int at91_adc_write_raw(struct iio_dev *indio_dev, int val, int val2, long mask) { struct at91_adc_state *st = iio_priv(indio_dev); + int ret; switch (mask) { case IIO_CHAN_INFO_OVERSAMPLING_RATIO: @@ -1650,20 +1651,29 @@ static int at91_adc_write_raw(struct iio_dev *indio_dev, /* if no change, optimize out */ if (val == st->oversampling_ratio) return 0; + + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; mutex_lock(&st->lock); st->oversampling_ratio = val; /* update ratio */ at91_adc_config_emr(st); mutex_unlock(&st->lock); + iio_device_release_direct_mode(indio_dev); return 0; case IIO_CHAN_INFO_SAMP_FREQ: if (val < st->soc_info.min_sample_rate || val > st->soc_info.max_sample_rate) return -EINVAL; + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; mutex_lock(&st->lock); at91_adc_setup_samp_freq(indio_dev, val); mutex_unlock(&st->lock); + iio_device_release_direct_mode(indio_dev); return 0; default: return -EINVAL;