From patchwork Mon May 31 04:46:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Beranek X-Patchwork-Id: 12288647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E694FC4708F for ; Mon, 31 May 2021 04:48:49 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 9D8AC61248 for ; Mon, 31 May 2021 04:48:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D8AC61248 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=prusa3d.cz Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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=faH9Q8N7ZeezvNg1r9FNWEZPYL9mdUcmzI8NKd1/UEs=; b=BHdj/6oH/rcZVT KTFBNa9JoN8I/mqml+dh8B689MzraKbHvm3P7l3TRYBy3xfuX9xwR3uxKjgg7dw0YzamhOvPtOehl 8Xl+yKXXmTx+Tc7F6lBIBK5vD9UOtLb7WW8PZ6AnjnCbpGP7lf+GavLzume5K8mNbDEiFPl8rrd1X VlnTFIr2XRSZYcyd89uRChQbVO7FdXXnBEj6cJyBXHRF1/WX/yYMX7l8nHHfKL0xFxq8HCbBvAtqY EPMolXS3teUPSJ+W1CNrCabA5WEKyH6JAHX+gsu0YHhZpeVgco5ukky3aCjDv+x2LiLtLBkoLgf+N MCIHrvhBBGtWOrcIUAaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnZpY-00AjQ9-Pv; Mon, 31 May 2021 04:47:12 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnZoj-00AjHh-SB for linux-arm-kernel@lists.infradead.org; Mon, 31 May 2021 04:46:24 +0000 Received: by mail-ed1-x52d.google.com with SMTP id dg27so2219047edb.12 for ; Sun, 30 May 2021 21:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prusa3d-cz.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=c9TPrVvwOJU1vM2zQOe9sLDjTnXNJ7tTt34i6paI9+g=; b=FKpLtB8Wsq0qoax8vN+Zo33QxMyFfLGW7aozw1rqXPYArZRJ9fsszF5dVm4xQ8jaWf GqUYeTXPzQh63TrU2ZwSVR65vr9YHKc2lKpT8BuQCAJcalmJOdSS3PT1SJ9otVwTHumD 86y7jvp/eNLgNYvxwx/yDk8YfCOth38e1fJ0qJhoAgI+yr+7qnIhc4zjK6JGoTxg22YM Ld+4w0wt3ODRnwbseM8TlIebb7K2hVrtviYoNnnAsGywZu8ObvnwRosoOui+sSDNIEJB 9TA77sPZBDTu7agUuUHMMFINRUSwBnhtjnjyGacDABPQE/GmJVX58TB/FpIDBzn+PUB7 GQ8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=c9TPrVvwOJU1vM2zQOe9sLDjTnXNJ7tTt34i6paI9+g=; b=IEqPhjwrqpQl0cLLQykHwrhX6kRwpLzFZ0WQ4X+u7s20StVvQVTndFXeKFk0j/iDiA OOk1XwyKXRChUNxWaiDTnWbmFQ8OxJwE+Q9qzPoKKM/7IlsMB6hVcbmUjdVZSd47TaZl QpUTSPlLgoD7CZgVIsCsvHUP9hKb3+5eIy3c1m2fAeKKSUZw/ksJMt/zSA6HLh2Me7lR WLWaes/klhbQtgPCTdJ1F7ofs/ktoFulkucMnGhhDt4GKDcDd6zjDV45iKef1R8+IZ0k YuwPayDbiKwbWdcuM2+IxmmiU/O5RipmwkzkhKBdec4zFaY5FEu7H1euYX5Xj0yYzmaT 55rg== X-Gm-Message-State: AOAM531UFbsXS2ipwJg9cUi/n7XSaLjj9sqc74VKSxzbKAdk1xhG6ONC nSIBxRm4kFMpkWzfxKyD6Xorkg== X-Google-Smtp-Source: ABdhPJwm2wapTm/meH0HsCh6lRt8OuethMrV45J+Fj/R8rSSjGe+Cr0iZp+gMcfd3kIV8vbuPdV9tA== X-Received: by 2002:a05:6402:152:: with SMTP id s18mr22918277edu.221.1622436380394; Sun, 30 May 2021 21:46:20 -0700 (PDT) Received: from zen.local (ip-89-103-215-157.net.upcbroadband.cz. [89.103.215.157]) by smtp.gmail.com with ESMTPSA id h9sm6238376edt.18.2021.05.30.21.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 May 2021 21:46:20 -0700 (PDT) From: Roman Beranek X-Google-Original-From: Roman Beranek To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Thierry Reding , Emil Lenngren , Pascal Roeleven , Lee Jones , Maxime Ripard , Chen-Yu Tsai , linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-sunxi@googlegroups.com Subject: [PATCH 3/6] pwm: sun4i: replace spinlock with a mutex Date: Mon, 31 May 2021 06:46:05 +0200 Message-Id: <20210531044608.1006024-4-roman.beranek@prusa3d.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531044608.1006024-1-roman.beranek@prusa3d.com> References: <20210531044608.1006024-1-roman.beranek@prusa3d.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210530_214621_930095_0A1CC816 X-CRM114-Status: GOOD ( 16.63 ) 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 Releasing ctrl_lock for the duration of the delay is not desirable as it allows re-enabling the PWM before the delay is over. Instead, substitute the spinlock with a mutex so that we can sleep while holding it. Signed-off-by: Roman Beranek --- drivers/pwm/pwm-sun4i.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index 2777abe66f79..b3ec59a83d00 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c @@ -16,13 +16,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #define PWM_CTRL_REG 0x0 @@ -87,7 +87,7 @@ struct sun4i_pwm_chip { struct clk *clk; struct reset_control *rst; void __iomem *base; - spinlock_t ctrl_lock; + struct mutex ctrl_lock; const struct sun4i_pwm_data *data; unsigned long next_period[2]; }; @@ -265,7 +265,7 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, return ret; } - spin_lock(&sun4i_pwm->ctrl_lock); + mutex_lock(&sun4i_pwm->ctrl_lock); ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); if (sun4i_pwm->data->has_direct_mod_clk_output) { @@ -273,7 +273,7 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ctrl |= BIT_CH(PWM_BYPASS, pwm->hwpwm); /* We can skip other parameter */ sun4i_pwm_writel(sun4i_pwm, ctrl, PWM_CTRL_REG); - spin_unlock(&sun4i_pwm->ctrl_lock); + mutex_unlock(&sun4i_pwm->ctrl_lock); return 0; } @@ -308,10 +308,10 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, sun4i_pwm_writel(sun4i_pwm, ctrl, PWM_CTRL_REG); - spin_unlock(&sun4i_pwm->ctrl_lock); - - if (state->enabled) + if (state->enabled) { + mutex_unlock(&sun4i_pwm->ctrl_lock); return 0; + } /* We need a full period to elapse before disabling the channel. */ now = jiffies; @@ -324,11 +324,9 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, usleep_range(delay_us, delay_us * 2); } - spin_lock(&sun4i_pwm->ctrl_lock); - ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); ctrl &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm); sun4i_pwm_writel(sun4i_pwm, ctrl, PWM_CTRL_REG); - spin_unlock(&sun4i_pwm->ctrl_lock); + mutex_unlock(&sun4i_pwm->ctrl_lock); clk_disable_unprepare(sun4i_pwm->clk); @@ -471,7 +469,7 @@ static int sun4i_pwm_probe(struct platform_device *pdev) pwm->chip.of_xlate = of_pwm_xlate_with_flags; pwm->chip.of_pwm_n_cells = 3; - spin_lock_init(&pwm->ctrl_lock); + mutex_init(&pwm->ctrl_lock); ret = pwmchip_add(&pwm->chip); if (ret < 0) {