From patchwork Mon May 31 04:46:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Beranek X-Patchwork-Id: 12288639 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=-17.1 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,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 098D6C4708F for ; Mon, 31 May 2021 04:47:48 +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 B39B861057 for ; Mon, 31 May 2021 04:47:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B39B861057 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=YgsGAqKzE3vo6hzz/n0HaF8c1PEIxosU/x/GxTC9CTE=; b=JNNPH7pTUyDOKP IQwF6nf56K0OrkBePtq2NYE5clSGkt91XAYZt5Of8cakCt4922Z1Ddc1WCzywU/P/V4DpXiEe81NC EVzDb9q72DHBey/0qOJtZg/jmmB4ZLh2c0bf1TGS9wqlXeqTxmpN01RGSG+e6hQ3VvAc7lRitNHkx LFoJ4kjMNvpfTvQqh28OAmoI5xPLDp/znujxqR8IMLVFGLSx/Xg5oKmmGRApiT2BkmmtLI2v5y0EV lDPLiOvGw4dnciEhIzsWaCOID/ej0Y5GDwGDmRgMjLhZZp1JBmh1+5kon8D6vfpV2hQEitj19RlPV cuIcF1vYCcctsPidP5zQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnZom-00AjJA-Vp; Mon, 31 May 2021 04:46:25 +0000 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnZoj-00AjHa-Cp for linux-arm-kernel@lists.infradead.org; Mon, 31 May 2021 04:46:23 +0000 Received: by mail-ed1-x534.google.com with SMTP id j9so11954033edt.6 for ; Sun, 30 May 2021 21:46:19 -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=ZZgT3an2EYN+ktsS5FyP/IHOGumhn4A6v5jkyh2PmDY=; b=wpY9kpNjSEvT08pGSQrDGw0X81R1U+ELe4rSYN4gAc5EiLySzHZ2+gyidq33uOfqz1 VcwJCkB6Iq4yi+7JOpOk/ANqsTFZKZYvBI0NDRYCYzfE5M1pO2s9DE78P5oQrymB70zG YOjCCdoyci1c+1mvnfRyG5Pyl3SkV48swzf/S8mEDsiLa9Jj+Z0S9lzytTOCC9zhN6Ci vCBWuypX9sjpAGtu3+KiSaui4cV8fdg5AW70nm38du+SLf/UvdZ9d+Mu17S88yGRKiyt V2fnMzLUxwSGPeh5HnnZx0oopltic8yOpy3s31Ml81pX1igjtEGQIVK5qXUED8nYXfwL i/BA== 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=ZZgT3an2EYN+ktsS5FyP/IHOGumhn4A6v5jkyh2PmDY=; b=GpxAJBLn2cRvxhdAN1eYGvtumAxK5/ZZQJnlt+uTi1t2i8kxpc6pb9lQv17sL7t2IY 1PHbUX+yc+ChjnzkYX2XvMoWbX3AspOen14aytfZYhkAoaCXcoMYW5OugF8r6kG8dZg4 chfxeawKJAXaidhCrlLcW6Pt7DlOkRBL03pJL++OAWor8qVferjje9Y0F0Ac/E7TBN5W NGrSvLmEcI28oFX0M/notrdbHJFceDuP5imfPVTqqq0OmmOUo6ZkuYIquFglK72o0RKw ZpcZ2/1QnMV8ycH2pssMgffoZ0RiY1939Y/HDXQUQiPHYwobt8+qSKX8HXeUZne87QdQ +HrQ== X-Gm-Message-State: AOAM5328b58hJH69p91d7RXbGAeNcuIXTb1iisR3uDHoofUHfgdR5It3 AKBeiYTLiMkjjwVdVl4WUaJ13A== X-Google-Smtp-Source: ABdhPJy1X788ZAmo8YDlVmNC0s+UtsAcz2syqXiIwPHdlqPt5f2EkG6qg8LD7Aa9c5iMnmc0Jwxc+w== X-Received: by 2002:a05:6402:3587:: with SMTP id y7mr22761532edc.360.1622436378450; Sun, 30 May 2021 21:46:18 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 May 2021 21:46:18 -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 1/6] pwm: sun4i: enable clk prior to getting its rate Date: Mon, 31 May 2021 06:46:03 +0200 Message-Id: <20210531044608.1006024-2-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_454934_86FC0446 X-CRM114-Status: GOOD ( 11.75 ) 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 Ensure the PWM clock is enabled prior to retrieving its rate, as is already being done in sun4i_pwm_apply. Signed-off-by: Roman Beranek --- drivers/pwm/pwm-sun4i.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index e01becd102c0..3721b9894cf6 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c @@ -117,8 +117,15 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip, u64 clk_rate, tmp; u32 val; unsigned int prescaler; + int ret; + ret = clk_prepare_enable(sun4i_pwm->clk); + if (ret) { + dev_err(chip->dev, "failed to enable PWM clock\n"); + return; + } clk_rate = clk_get_rate(sun4i_pwm->clk); + clk_disable_unprepare(sun4i_pwm->clk); val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); From patchwork Mon May 31 04:46:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Beranek X-Patchwork-Id: 12288641 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=-17.1 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,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 0A36EC47082 for ; Mon, 31 May 2021 04:47:52 +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 C384F61059 for ; Mon, 31 May 2021 04:47:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C384F61059 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=qJJ9OZ2LITdhwqeKPAU6gW6UN0Dt17xw/GUubivqYD8=; b=zYIhgC2UyYyqBC 2cQVniJlGsKwY7qjd4FCP2x10voBO7KWRTh9/K/2oZAXd0AwndJN2iRqeSk3zX/sKsALTon+1afSl WXqVU+5Rbv/Yul5zT+PRILGjUuDdRCCwMIqnQyvQXQxh3sk+G85p5MwM1cgULGh7rpRIXOVCOBDl2 TckZgKYXtV/XDXmeCjIn1jWVBqdu1oVvqvUHAl190DHMm6C42RYanuLYA4jaJ1tKcFgvfQCPRJ1xY F9iB5AN3bv9FxOfgEICmnhdE9NfB5/vG/nPnKqbqEyIUG9VfWSr1uNxGZVv56ttDYs9StUvkZo1JM u3G7mbVkGQdfazDtUzkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnZox-00AjKM-Fd; Mon, 31 May 2021 04:46:35 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnZoj-00AjHc-8w for linux-arm-kernel@lists.infradead.org; Mon, 31 May 2021 04:46:23 +0000 Received: by mail-ed1-x52c.google.com with SMTP id b11so5160681edy.4 for ; Sun, 30 May 2021 21:46:20 -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=0wwG/Rn9um6zlw9r9jL8V2Q6hYDd1uPy7KH4n241Hsg=; b=S5EbIKVLC9/WQtCT+GNBCYreMNg/ZC4D22aFdQse1Mj4FeXxIr7Sq6ZwK2pF+ZJ9Bg GMpya0ctg+rtWwz6rYL5bFz4Q5KvxFtJS9t4aNhle/lGYi5NJTTdRTBWr7r+kjMSZxM5 tnIgQxuWzg++m+kQc6X/6jYjSxxqlLIQOIe0qEQNDI2SLFVvRXiNu6CYquzMTfDa9LAt 8QFh9mYUiYVwuyO2Elc6hpIgQy1T92vDiSG2RGztAc3lKjE7luG4s/G2Xbwbmtc2pfdJ JJdBuUKDQHEMs3gNtDM5ndlPnLbkbpho3X2Xgrgwqhi14jv9DUM7kGJSwDbuzH/Q8JqQ HPsQ== 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=0wwG/Rn9um6zlw9r9jL8V2Q6hYDd1uPy7KH4n241Hsg=; b=XoSDVI7ke84pDKZxmqQwG55I7rS5xPOrRglHwWPapmEkz+2Ddrfe/CAGs/0r2WOVlj 6ul8f5AmvAacdVuNAkUceRm1HmMv/5Z34rmeg8WN+URaiGPdvurt6GHnWdNdLBsk8zcL xIBPO3dZ7K6+VR0TRrXx5fEiNx/nC5lTVTA6W3wK0G3Ook4iZVJ3hKKEUkypssXSxmZb 9sr2/IHMFuQxOcpt6OjTCoDjG9AsI4ulCJzayqnJo/ik3+lEOnXcZZ48o3gy5PtWzd1K cgi+thYQ5GAzl8jbVNAuY08rfEEFw3+RQpSccNY7cKHFRlqTe07VUxtlDBT8Xekoxuw2 lIOg== X-Gm-Message-State: AOAM532eeP3ISiJL7OYjquOgA4UhWyud4nv3OjPAtO2dXQYRdqMXJW2e c2m4kwRLmTkH4JsX4TfvyURMbA== X-Google-Smtp-Source: ABdhPJx1t3/XMRBY9LSzuPp4oCSFKs8ZpLoo0r7Idrq6tIlRFlYlZponr9ZqTFdRcuMqNtwVLlXEiA== X-Received: by 2002:a50:ee02:: with SMTP id g2mr7732330eds.333.1622436379476; Sun, 30 May 2021 21:46:19 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 May 2021 21:46:19 -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 2/6] pwm: sun4i: disable EN bit prior to the delay Date: Mon, 31 May 2021 06:46:04 +0200 Message-Id: <20210531044608.1006024-3-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_449111_5E746AE0 X-CRM114-Status: GOOD ( 12.89 ) 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 The reason why we wait before gating the clock is to allow for the PWM to finish its cycle and stop. But it won't stop unless the EN bit is disabled. Signed-off-by: Roman Beranek --- drivers/pwm/pwm-sun4i.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index 3721b9894cf6..2777abe66f79 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c @@ -303,6 +303,8 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (state->enabled) ctrl |= BIT_CH(PWM_EN, pwm->hwpwm); + else + ctrl &= ~BIT_CH(PWM_EN, pwm->hwpwm); sun4i_pwm_writel(sun4i_pwm, ctrl, PWM_CTRL_REG); @@ -325,7 +327,6 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, spin_lock(&sun4i_pwm->ctrl_lock); ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); ctrl &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm); - ctrl &= ~BIT_CH(PWM_EN, pwm->hwpwm); sun4i_pwm_writel(sun4i_pwm, ctrl, PWM_CTRL_REG); spin_unlock(&sun4i_pwm->ctrl_lock); 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) { From patchwork Mon May 31 04:46:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Beranek X-Patchwork-Id: 12288645 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=-17.1 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,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 95C49C4708F for ; Mon, 31 May 2021 04:48:27 +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 55237610C9 for ; Mon, 31 May 2021 04:48:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 55237610C9 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=r5KpjHvzhoB2lRSeU/X3MgnupsQXSPGcz+hG71seDGk=; b=zut2JauFVPqpNJ 7TexNTwQJ5nQcsvMkdVTxXlQj6VwKKEFNEjPSziVvUWEbXp5AfNBKKe0IpHm0Lyv5WsePIGTpLI2y sNUkgF2MBVx2n7wxYytnO+NbEHj+5RBc5vDB8WI1JH5c9Dy2ICaUjFMMmpeazC+rb/vanLcQCdQWw UESMQtKuhZ5dtwBnef/6RF+mWixbUL3UElscGP3Cj4OUoFJRF2SPsPBWKmIFHa5nayHjLiHVvGwyN PHWLVDtNlgBoDcj+LaObG/9grJWKVQ2i3FbGqYL5WRz3Btkj7e3Ul7ERm2yZSlJ8f4kOKDFCrqRP3 u9KWgC01Wh3M6vEDPSUw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnZpK-00AjMW-RO; Mon, 31 May 2021 04:46:59 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnZok-00AjIH-NW for linux-arm-kernel@lists.infradead.org; Mon, 31 May 2021 04:46:24 +0000 Received: by mail-ed1-x531.google.com with SMTP id s6so11927638edu.10 for ; Sun, 30 May 2021 21:46:22 -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=bJxASN9/VJ7juNYNTX4EX6mmIGaWh5aMZc7qgtuD+IU=; b=oqizCzkWKvZf15jO987l874C6oFmf+PpZfdo0bF1dGwoCiPP+xMcyjRvMa6l7ELvc1 6Cbtz+m9iIJxpaZwVRMK6+ChJ3n5P7sgfdCJ/jvCwyJxa5JoKSRKP+nyWmLcGdlG9cub czyKvHvkeakh/Y25cl4sodc3AQjz4m9oADK5shjPcUtX7OEEwxWTAHX0l7aVfhiEjNoi Mzz2hA59kF31of4IpXdCBnxz0rEBbAkKAFByZVKuffbhNsS/3mk+J33vjT6hDC0WUpec IzCL42VsUCcNozdzaxSgNX7uruW2+PImiG08fYlJJYm6gYqfsmyA0ZXiMki29clDsvzY eftw== 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=bJxASN9/VJ7juNYNTX4EX6mmIGaWh5aMZc7qgtuD+IU=; b=NZf04IjkBp0hUKK1nlXRGGQdL6xAJFaCYF2r63lRE9z3bLBfIlGtI+wm2TDvLqZ+HK 5Bv8Woxd0SmWcqj1kzq7/b3NbS38bWY/MK/YxNxRengvbl98qaKoTpCLJt0LB44QciD0 dOmu9snxdicm+FG9YJvs5UwqHSIRwmJpAwDTG2SvrlngfKAMIhLfUPNR5wwqi0itMheh zHK1RaTOsz2+Ebakb6L4PzwtprfjPlqhZhSp9GEn9AlnIX8qQ5PAg8yv71+8T9YG5znX y1faRiIQo0qRck28FASB1Ip5iz3+JQRwhoknSzksYOaEOl2iJrus0NAROncCwcKNtAYP 2uDQ== X-Gm-Message-State: AOAM530mNJ+TicG8aSrUiOn7wOcQGP+DCOQBxzozTr9J/uia/Ig/jVMP ibEGsgtOg7NwQY0ck/5i0gaQGg== X-Google-Smtp-Source: ABdhPJw2frB/ZmhM9tgloeFhP25YeHOi7cT5JP2v2UeqpuGbPnO2vr6JcP4Q185T9pvonWQGT/hPiA== X-Received: by 2002:aa7:cdd8:: with SMTP id h24mr23142258edw.276.1622436381298; Sun, 30 May 2021 21:46:21 -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.20 (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 4/6] pwm: sun4i: simplify calculation of the delay time Date: Mon, 31 May 2021 06:46:06 +0200 Message-Id: <20210531044608.1006024-5-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_214622_785919_1F195D93 X-CRM114-Status: GOOD ( 15.97 ) 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 There's no reason to expect a single jiffy has passed since writing the CTRL register except if a preemption has occured in the meantime. Avoid introducing unnecessary complexity and simply wait for the whole period. Signed-off-by: Roman Beranek --- drivers/pwm/pwm-sun4i.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index b3ec59a83d00..8218173ce3f6 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -89,7 +88,6 @@ struct sun4i_pwm_chip { void __iomem *base; struct mutex ctrl_lock; const struct sun4i_pwm_data *data; - unsigned long next_period[2]; }; static inline struct sun4i_pwm_chip *to_sun4i_pwm_chip(struct pwm_chip *chip) @@ -242,8 +240,7 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state cstate; u32 ctrl, duty = 0, period = 0, val; int ret; - unsigned int delay_us, prescaler = 0; - unsigned long now; + unsigned int prescaler = 0; bool bypass; pwm_get_state(pwm, &cstate); @@ -291,8 +288,6 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, val = (duty & PWM_DTY_MASK) | PWM_PRD(period); sun4i_pwm_writel(sun4i_pwm, val, PWM_CH_PRD(pwm->hwpwm)); - sun4i_pwm->next_period[pwm->hwpwm] = jiffies + - nsecs_to_jiffies(cstate.period + 1000); if (state->polarity != PWM_POLARITY_NORMAL) ctrl &= ~BIT_CH(PWM_ACT_STATE, pwm->hwpwm); @@ -314,15 +309,7 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, } /* We need a full period to elapse before disabling the channel. */ - now = jiffies; - if (time_before(now, sun4i_pwm->next_period[pwm->hwpwm])) { - delay_us = jiffies_to_usecs(sun4i_pwm->next_period[pwm->hwpwm] - - now); - if ((delay_us / 500) > MAX_UDELAY_MS) - msleep(delay_us / 1000 + 1); - else - usleep_range(delay_us, delay_us * 2); - } + fsleep(cstate.period / NSEC_PER_USEC + 1); ctrl &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm); sun4i_pwm_writel(sun4i_pwm, ctrl, PWM_CTRL_REG); From patchwork Mon May 31 04:46:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Beranek X-Patchwork-Id: 12288649 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=-17.1 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,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 9D44FC47082 for ; Mon, 31 May 2021 04:49:01 +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 676C561057 for ; Mon, 31 May 2021 04:49:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 676C561057 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=MAHVTaGsGDmG/PR6ULpBRvFbDDEPHsHEuEEHlRiQnbg=; b=CvJ+x1WW9xjQVd 1Vs3n5M0A2A5z/+4wrp/CNt0hvwvOO7DyckgluP11FoY74tM1gwpkbhX8HRIPU23lwqw+A2GApFaE 4QwlvmyFmH3XKlv8LI2AAreiLs1Y6AGtovk0SeqopGKEfMBs83lfDkTd8lj+3xot3tzFeXXEwvPWh KWYE8wOp+bndb/UwyskzDPrmVjSbaAkDAkjdzkOMkVBHRhQTbCUVL5JcLVrEEG/wAjvSkpBdnJS0n f4efmm/C6klwk7lnqunyMvSy/T1znWQ1i4Pc1PYvN+RngJPUIwcbwWs2Lrs/6HGeZoRG5zzMsIyU3 Bp5kN7/uFLX32vd06dpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnZpm-00AjUo-PP; Mon, 31 May 2021 04:47:27 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnZol-00AjIg-N5 for linux-arm-kernel@lists.infradead.org; Mon, 31 May 2021 04:46:25 +0000 Received: by mail-ej1-x62a.google.com with SMTP id ss26so14705697ejb.5 for ; Sun, 30 May 2021 21:46:23 -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=fJYRnusoQB7v01vB94DLoFvMzQbtJxQf7oLDrp3sR/0=; b=FMd6BeryGHKKpxN5QOVSyPCqIvtCJyOTMORpcMaEXYT5wWvQ3NTvUrKcv11vnadh7C wS+r+KqMBW4/6bcn/+OjRR504oiqx40olVjku7Tn64iYsURlZ30CpC7jRVW/iXhhAOAR QyXNl8W3dS6vm2BaEVKCP555IR+zadYXGPWziSLDNZDSCNr/tiNuomLUMZ4qSIiDDGei 6UjLzw+CXbDd2F5n6i/u1XAkeIoRIAO77PdKxXSZh5tsrkXUbIGIUhH105yszPPbgpZu 39wpI+b4x+a2qNf5rQk7IMEDj/Ch7oNcW1ksKSatPTWC0/S5660jS2vRmyHnAcyTm9PO IJRQ== 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=fJYRnusoQB7v01vB94DLoFvMzQbtJxQf7oLDrp3sR/0=; b=cOurQWsgmNQqdo2qhFdindQRoE/2qB3GtL438M/yU49Ejhr6IyfigGPrGA1JBeSGhu jOUJzsKk/O88Q+FCbelOgO1wkO+LnBPrNVWHPd8JCEk5mfRBW3OC67JaDULbB6+VbUxJ Q4AFJt61LluYaHjMYbm+n9ZxRR3BtozAVbYxXV1+iXWy1zYxt304M6A3FMvNSWgqPJkR 2KjvzaJDSq5Cvq29UcpCgSR6Quo3LDiAgWcWnQnT9sOCRKFUpwU2pEwu5IdIQibaAo6j ie9WUUuDgdoiXzFtlhOP1S40d7V/J3MCN6djw4BHg/2z9UBYqpWEpekuk3QGN8enP7mN wLmw== X-Gm-Message-State: AOAM532rk9P79JYvSAMceowjnXmbIJCSzK7qYFUNnurB0ZEWjwWvr2qr CeMLFgaQs8usu+4/NpA21/28jQ== X-Google-Smtp-Source: ABdhPJwnNcUhh9/i2h+P0NXuh0zKWYK3ypvfLCnGLZXmGNlLWMEocpsVW7VpGv5Tk4UpwtbuS5L5gg== X-Received: by 2002:a17:906:4a19:: with SMTP id w25mr20708659eju.500.1622436382237; Sun, 30 May 2021 21:46:22 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 May 2021 21:46:21 -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 5/6] pwm: sun4i: shorten the delay to 2 cycles Date: Mon, 31 May 2021 06:46:07 +0200 Message-Id: <20210531044608.1006024-6-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_214623_778974_AB6BE444 X-CRM114-Status: GOOD ( 16.62 ) 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 As Emil Lenngren has previously shown, actually only 1-2 cycles of the prescaler-divided clock are necessary to pass before the PWM turns off (instead of a full period). I was able to reproduce his observation on a A64 using a logic analyzer. Suggested-by: Emil Lenngren Suggested-by: Pascal Roeleven Signed-off-by: Roman Beranek --- drivers/pwm/pwm-sun4i.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index 8218173ce3f6..6ab06b9749d0 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c @@ -71,7 +71,7 @@ static const u32 prescaler_table[] = { 72000, 0, 0, - 0, /* Actually 1 but tested separately */ + 1, /* Tested separately */ }; struct sun4i_pwm_data { @@ -240,7 +240,7 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state cstate; u32 ctrl, duty = 0, period = 0, val; int ret; - unsigned int prescaler = 0; + unsigned int cycle_ns, current_prescaler, prescaler = 0; bool bypass; pwm_get_state(pwm, &cstate); @@ -277,7 +277,8 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ctrl &= ~BIT_CH(PWM_BYPASS, pwm->hwpwm); } - if (PWM_REG_PRESCAL(ctrl, pwm->hwpwm) != prescaler) { + current_prescaler = PWM_REG_PRESCAL(ctrl, pwm->hwpwm); + if (current_prescaler != prescaler) { /* Prescaler changed, the clock has to be gated */ ctrl &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm); sun4i_pwm_writel(sun4i_pwm, ctrl, PWM_CTRL_REG); @@ -308,8 +309,10 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, return 0; } - /* We need a full period to elapse before disabling the channel. */ - fsleep(cstate.period / NSEC_PER_USEC + 1); + /* We need to wait 1-2 cycles before disabling the channel. */ + cycle_ns = DIV_ROUND_UP(NSEC_PER_SEC, clk_get_rate(sun4i_pwm->clk)) + * prescaler_table[current_prescaler]; + fsleep(DIV_ROUND_UP(cycle_ns * 2, NSEC_PER_USEC)); ctrl &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm); sun4i_pwm_writel(sun4i_pwm, ctrl, PWM_CTRL_REG); From patchwork Mon May 31 04:46:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Beranek X-Patchwork-Id: 12288651 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=-17.1 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,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 A00FDC47082 for ; Mon, 31 May 2021 04:49:18 +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 630436100A for ; Mon, 31 May 2021 04:49:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 630436100A 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=G9j4g/Vz8cv8bhnbsqun7T99Yg1DeUflScXA6/48Lw4=; b=CvCb0F1W4wXqc4 GdFTxDYXEycoSoSowvr8yuI/KMgSv1NYGXg4eNanj3GrRkiW/J5fOdvbLUid/amg7j0uxsYmuNFPi GIj0LeDEaXadinlyKxHqVXwF20iSI6n57rx4iO3OZIYZHfTgM8bLuUDJUfiz88nF/wWjB88RrM+nx QN1DEAPXjiVh0nokXHwWZKyHj20C3mrLBJmAfS1pK3N8YEw9cGwo7YJgsVtfb0z6yLHrz9du2Fvcw Q+tbbXA7ti6cSkWUCN30jns7IwXJa6yDLoLRcJtUWzUV5P7uFV3i2XtNNdK9Idazl0Yx9MEVxVm4Y IH61N+HYONzKUc/5BK1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnZq9-00AjdY-1E; Mon, 31 May 2021 04:47:49 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnZom-00AjJ8-8B for linux-arm-kernel@lists.infradead.org; Mon, 31 May 2021 04:46:25 +0000 Received: by mail-ed1-x530.google.com with SMTP id b17so12025928ede.0 for ; Sun, 30 May 2021 21:46:24 -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=QVg7Hdl4/ZVFOwC3zdm+BtLAL/F8bdjWGF9QT4YTdO4=; b=OD5S65QZS3iZyC4Zwlx2TkaDHQa6IzCi9DD8krUyi0osNRlwD/CF+7Q22MY+oOnnJa lvo3pxndm9A+HqC/jvsLwMOrRpROf7oKOXPOzzcmmbdUG0asCnUy9LRmZXj+W3vcreqM fqERsSCercBb8Dk0Y3aU/PfdrqFGpLFWS/VHgzV+IrcZGrDXL0YpQnPw2+kN2gTYRuPK IAjoRdliJBA64SgjMWpXknEfJZ5nkL4Mw3h1pxIhAyc8jRYY3cHnzh8HccH7csXR543C RseTB3a3ChOqipdWlv40xL5tFgkjznFX+XTnqDeELDLrqNmzKpN2C0zXeuSnAbRoeScb /JMg== 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=QVg7Hdl4/ZVFOwC3zdm+BtLAL/F8bdjWGF9QT4YTdO4=; b=fJcY5oVxq60VodC1ZKDTnzsNHI88898hJXGceZWKBkk+uZRJLxFYy+WwU3SYzKv/az SAjXLQC8CkRRt588PiIedLx6aBc9EP8DjQ8Opqs0R1872S+nkGn5QuyzZ+1lf6FwPMfH 6ndGws98XBoO11hOzT0fltg6OIURKCA/jMnm/E5OEIvhUaLT+t1WM1lyxDO/ynBLN57X 0F9kf7aHe82tqepJLzc6aP8p9LFl7m+WnCEPlpQ2JSWlmNAZpef7oLT09tJqU4gIK4Ha FWq3ZRG+zCAT4yaiGJYGETIOFF8+ipOkbLCgMStKJngiZPzmpW2a1sgfDyRikwBv+3E2 2RUQ== X-Gm-Message-State: AOAM5324dikis/i8La0LB5SAgwFYSI2IxY37gbp/iJ55Z7ShZw4iA24I J5sastP/MOm+RhB3Dht2qTDDvw== X-Google-Smtp-Source: ABdhPJxsQ+/nHjpVQtyAxvH1LPlS/MyEUURoxZBF/XAqcXhXjL3TGweCjrGnBsD78Gk8GZai/gBaIg== X-Received: by 2002:a05:6402:b8c:: with SMTP id cf12mr23173772edb.61.1622436383155; Sun, 30 May 2021 21:46:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 May 2021 21:46:22 -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 6/6] pwm: sun4i: don't delay if the PWM is already off Date: Mon, 31 May 2021 06:46:08 +0200 Message-Id: <20210531044608.1006024-7-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_214624_311722_C7763E7B X-CRM114-Status: GOOD ( 13.20 ) 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 Signed-off-by: Roman Beranek --- drivers/pwm/pwm-sun4i.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index 6ab06b9749d0..88bd90498d1f 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c @@ -304,7 +304,7 @@ static int sun4i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, sun4i_pwm_writel(sun4i_pwm, ctrl, PWM_CTRL_REG); - if (state->enabled) { + if (state->enabled || !cstate.enabled) { mutex_unlock(&sun4i_pwm->ctrl_lock); return 0; }