Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp291431imn; Wed, 3 Aug 2022 04:08:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tTVfGF2blGJnZkCUOlSCzFPayNTp14C3EuHnQwQxDy+R7ijJ6iGZYkiFlFYR7LyMH5yoBN X-Received: by 2002:a05:6402:e0f:b0:43c:f9f9:37c4 with SMTP id h15-20020a0564020e0f00b0043cf9f937c4mr25349657edh.196.1659524893828; Wed, 03 Aug 2022 04:08:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659524893; cv=none; d=google.com; s=arc-20160816; b=1HwPuyTxhzhbIDBLJF38REQyZTXV4yMuaIojecyqOth+4c4xdoQaLES5cDBYyplaUT FS6Boa3OauoTcfBb0kl1X4jrOx3/JmQMvDoLxpc+lyTqyb222XZs67aIbiR3leS/q/7Y t9KS396T+M4zJo1Qt96u9fUnyZJNUNfudMAgLv4CwaXwJlX4boekJWPhkCfn28+0uUaF gM3Dj2SriGcBWq715yWvRN+pBNqV5Ah/oNzgTBwgwYhv7zCnrW+nRM/NkzuQsbzq29P+ 7R6e9VvkszmSpAig6D0JvEf70na17FgKpiFNDuUvl18IvkDE5+F6EJnZyu26oL08GJFJ GiMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0Giv/O20i+r7hqZOaQuzZNd5Ux97TN67lmAUast1qmM=; b=tUneQ25AQf9gQZxyzKduoFCNtflg9o53dT7OiOJGNURqjvUBzRbJ7fwSzJZt+9da58 DXw4J6ol2NlFuMrXc1pOOKxiFPeLMp7Smxi+mLVX4lK8ZFeHLHa4hM+JkRjy6I8aBLqZ iv5p/ItMBZEgzxC7HT5e8lo3zJVjqN1kd3SfPaw4JKp+V3aPLhbx+rA/0MQzBUPzNtTn essGrS9lpVqEwl2lIuuM9SAVPmte/16FgSrx1Bsp+jCtloQaam45Kiv3eBCnajuvj+k6 l4Eu7Zfta7KmqhCZX5a1EL6up7QIvB2ZOnQWALCN/RK5X//2Va47e/OXBNi0w3lkeu2z eUww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=gdO1r3Lg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lb22-20020a170907785600b00711f646bb8csi1114865ejc.916.2022.08.03.04.07.34; Wed, 03 Aug 2022 04:08:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=gdO1r3Lg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237558AbiHCK3M (ORCPT + 99 others); Wed, 3 Aug 2022 06:29:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233563AbiHCK2f (ORCPT ); Wed, 3 Aug 2022 06:28:35 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F0DB5A3D8; Wed, 3 Aug 2022 03:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1659522451; x=1691058451; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iMXefC0igDeFJ27vYADoWV+7/A1ovx1XLwyBSs3RDMY=; b=gdO1r3LgwHXdIEz/KjCDYYzzP6PAV37x6F6iBvAIxpjA4UNwIk5iP/rj re+8EHKkm8u/uG0O2cJJarbqDE2uvXVEeRYiy3YN767wVjafA2enyvtlA Pufonp800b3BJlpOvI9Jy6DD0T1nHxZmSrHcgAJRTIRQ+tr83wIGfTSmT P6zyPatL4IHa4qmjz1q4+ie1oGQWMvZ/U/AQkDZSSFqgSAPHGTy6fhRgp pVw5BsPMtZ55Lys9gpWMFWCWP54kJZ5UB9OzxOJXYFacYl9HXk6TNZ+Ad rAhB1Ip3aOwenQiIjcnJ7tTgi76hBJhIOb1HFlIiZBmsXcFD4AoJ2uS47 w==; X-IronPort-AV: E=Sophos;i="5.93,214,1654585200"; d="scan'208";a="174882796" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 03 Aug 2022 03:27:30 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex02.mchp-main.com (10.10.85.144) 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:27:25 -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:27:23 -0700 From: Claudiu Beznea To: , , , , , , CC: , , , , Claudiu Beznea Subject: [PATCH v3 15/19] iio: adc: at91-sama5d2_adc: lock around at91_adc_read_info_raw() Date: Wed, 3 Aug 2022 13:28:51 +0300 Message-ID: <20220803102855.2191070-16-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 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remove iio_device_{claim, release}_direct_mode() and lock/unlock to &st->lock from at91_adc_read_info_raw(). Instead add a wrapper around at91_adc_read_info_raw() and do there the lock/unlock. This will allow using the at91_adc_read_info_raw() in patch that add support for temperature sensor. Signed-off-by: Claudiu Beznea --- drivers/iio/adc/at91-sama5d2_adc.c | 39 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c index fd02da9b26b2..1a72e304fc3a 100644 --- a/drivers/iio/adc/at91-sama5d2_adc.c +++ b/drivers/iio/adc/at91-sama5d2_adc.c @@ -1582,6 +1582,7 @@ static irqreturn_t at91_adc_interrupt(int irq, void *private) return IRQ_HANDLED; } +/* This needs to be called with direct mode claimed and st->lock locked. */ static int at91_adc_read_info_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { @@ -1594,45 +1595,26 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev, * if external trigger is enabled */ if (chan->type == IIO_POSITIONRELATIVE) { - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; - mutex_lock(&st->lock); - ret = at91_adc_read_position(st, chan->channel, &tmp_val); *val = tmp_val; if (ret > 0) ret = at91_adc_adjust_val_osr(st, val); - mutex_unlock(&st->lock); - iio_device_release_direct_mode(indio_dev); return ret; } if (chan->type == IIO_PRESSURE) { - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; - mutex_lock(&st->lock); - ret = at91_adc_read_pressure(st, chan->channel, &tmp_val); *val = tmp_val; if (ret > 0) ret = at91_adc_adjust_val_osr(st, val); - mutex_unlock(&st->lock); - iio_device_release_direct_mode(indio_dev); return ret; } /* in this case we have a voltage channel */ - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; - mutex_lock(&st->lock); - st->chan = chan; at91_adc_cor(st, chan); @@ -1661,9 +1643,25 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev, /* Needed to ACK the DRDY interruption */ at91_adc_readl(st, LCDR); + return ret; +} + +static int at91_adc_read_info_locked(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val) +{ + struct at91_adc_state *st = iio_priv(indio_dev); + int ret; + + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + + mutex_lock(&st->lock); + ret = at91_adc_read_info_raw(indio_dev, chan, val); mutex_unlock(&st->lock); iio_device_release_direct_mode(indio_dev); + return ret; } @@ -1675,7 +1673,8 @@ static int at91_adc_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - return at91_adc_read_info_raw(indio_dev, chan, val); + return at91_adc_read_info_locked(indio_dev, chan, val); + case IIO_CHAN_INFO_SCALE: *val = st->vref_uv / 1000; if (chan->differential) -- 2.34.1