From patchwork Sun Feb 19 20:44:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 13146004 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 BBEE9C636CC for ; Sun, 19 Feb 2023 20:45:41 +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: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:In-Reply-To:References: List-Owner; bh=/BQmYMXnmoLqJq6koM8w3l29QWyvKs6IB1vZzabyB8U=; b=cdfHJ9swSkg5uc g41QUUIXR/3OE1qItIkzKoYWuJwnL40JZ0PQK/jdWx5p23aCBeP46XzxcUliI89TzOQ83+TEnvxDm pbRI+Wld0iHKo2hLnugutEnd9QUCqX8N3Ys9ywAgLocXyAc3ry4bCmWkFotbG/Ya2CLK+si5tfFZa eEdyGjKtY2okE0SA3u+JqarJnZFQ+MYo6otm2Z/pFJfCAeIHqrrTKibG8+rfcGTeKo+7/9A88iqib n4tVYbimVWJtiAC0ECVaHdudg4ixKurTpcQeMGUwoBAOMiN1mmIiTJrBmWsM55OacdZGRHg4V04cn /E3JAF5jNw+VmX6BeFAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pTqYq-002HLw-9U; Sun, 19 Feb 2023 20:45:28 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pTqYd-002HJk-Nl for linux-amlogic@lists.infradead.org; Sun, 19 Feb 2023 20:45:17 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pTqYG-0002Zv-Em; Sun, 19 Feb 2023 21:44:52 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pTqYB-0066oS-9b; Sun, 19 Feb 2023 21:44:48 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pTqYB-004trh-PA; Sun, 19 Feb 2023 21:44:47 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Jonathan Cameron , Martin Blumenstingl Cc: Lars-Peter Clausen , Neil Armstrong , Kevin Hilman , Jerome Brunet , Andy Shevchenko , =?utf-8?q?Nuno_S=C3=A1?= , linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, kernel@pengutronix.de Subject: [PATCH v2] iio: adc: meson_saradc: Better handle BL30 not releaseing the hardware Date: Sun, 19 Feb 2023 21:44:39 +0100 Message-Id: <20230219204439.1641640-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2545; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=UFb/C7xXSmr0LKHXSvPXadmaMrdeCgJrt6qsOgXktPA=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBj8oo0s1jtpBKhA696qEv+cQLED42WqCqwi4fam y48gJ9dgVuJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCY/KKNAAKCRDB/BR4rcrs CeejB/9OmUvOfyvHfDjjyWCsorSUvO1jy2RVvo6aU55Xu8NQspq9ntKSUpz1vwFymaYhjkcADr+ QoiCQMQqfkUtOeECpb0aIO4fuey/2+vUeydRiystje/dPU+xLg1YpAuDFD59SPjwreWOuFkUb6q dvetVwVIEi7SZQgrFPM8nweGWb7hFm/V6iTXT9vE4wzVeQdkINFJvZSvXOTm5Sv81DZEzd3BZ2N HoVxMdH8zMJ92VYp2ny+zCfzdr8eCu0P551TN/gE6uadx1YnuTo23FQadmMNWZKtQvqLhiYf5mD tlO3C+Kn+vCxAxowG7nMk43l3+TzCCpOyQN5mN5RPuE69adL X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230219_124515_776649_662ABAAA X-CRM114-Status: GOOD ( 14.38 ) X-BeenThere: linux-amlogic@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-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org meson_sar_adc_lock() might return an error if BL30 doesn't release its lock on the hardware. Just returning early from .remove() is wrong however as this keeps the clocks and regulators on which is never cleaned up later. Given the BL30 not giving up its lock is a strong hint for broken behaviour, and there is nothing we can do about that: Just clean up ignoring the fact that we're not holding the lock. Signed-off-by: Uwe Kleine-König Reviewed-by: Martin Blumenstingl --- Hello, changes since (implicit) v1: - Ignore failure to get the lock as suggested by Martin. - Adapt a caller for meson_sar_adc_hw_disable() returning void now (which used the return value) drivers/iio/adc/meson_saradc.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) base-commit: 925cf0457d7e62ce08878ffb789189ac08ca8677 diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c index 85b6826cc10c..18937a262af6 100644 --- a/drivers/iio/adc/meson_saradc.c +++ b/drivers/iio/adc/meson_saradc.c @@ -957,14 +957,18 @@ static int meson_sar_adc_hw_enable(struct iio_dev *indio_dev) return ret; } -static int meson_sar_adc_hw_disable(struct iio_dev *indio_dev) +static void meson_sar_adc_hw_disable(struct iio_dev *indio_dev) { struct meson_sar_adc_priv *priv = iio_priv(indio_dev); int ret; + /* + * If taking the lock fails we have to assume that BL30 is broken. The + * best we can do then is to release the resources anyhow. + */ ret = meson_sar_adc_lock(indio_dev); if (ret) - return ret; + dev_err(indio_dev->dev.parent, "Failed to lock ADC (%pE)\n", ERR_PTR(ret)); clk_disable_unprepare(priv->adc_clk); @@ -977,9 +981,8 @@ static int meson_sar_adc_hw_disable(struct iio_dev *indio_dev) regulator_disable(priv->vref); - meson_sar_adc_unlock(indio_dev); - - return 0; + if (!ret) + meson_sar_adc_unlock(indio_dev); } static irqreturn_t meson_sar_adc_irq(int irq, void *data) @@ -1283,14 +1286,18 @@ static int meson_sar_adc_remove(struct platform_device *pdev) iio_device_unregister(indio_dev); - return meson_sar_adc_hw_disable(indio_dev); + meson_sar_adc_hw_disable(indio_dev); + + return 0; } static int meson_sar_adc_suspend(struct device *dev) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - return meson_sar_adc_hw_disable(indio_dev); + meson_sar_adc_hw_disable(indio_dev); + + return 0; } static int meson_sar_adc_resume(struct device *dev)