From patchwork Fri Dec 23 15:38:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 36297 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp384196wrn; Fri, 23 Dec 2022 07:40:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXsXiE/kouXUh997GpdkI6OJmuwYzeY0+0hclcfJAJH4T+VpUs3MTV3WuWfIfM0gdgp6SCUt X-Received: by 2002:a05:6402:e0f:b0:468:58d4:a0f2 with SMTP id h15-20020a0564020e0f00b0046858d4a0f2mr9546406edh.23.1671810037015; Fri, 23 Dec 2022 07:40:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671810036; cv=none; d=google.com; s=arc-20160816; b=OpRcxm3i1kenC5Vf5oCznc9FwdY87mgCoknOBFCw9MZ3Vc/NQxLpvF9qK/lIG16534 rrIKtu1I7JvV2uj6fzap8qZtzC0OKfAYUYILOagkr6Gs84Tx7+dH9pc1ivSEochGEw10 1YbmzIzUhozWshPICusmN1/P44iJVnvRuAGqYm+L1VuDQAsrsp9nhPVioIUw4H/J4vxT rQF43vNASENXgK0yDSOIlOOy0aqIZGtmOpx2SHvb+yS9na3Gi9JlZ0kGljEFDLIaU2pf HgW44T10fj0P4f5BqKYmKonO09Km2anNSQlGc0aaIVtCyb72NbTDUSohUQ6UYRNgwwAK dCZQ== 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=phcPBaGxOFAemR9YFsCDrE8yrlHvz+AvjsJ/jn+/KmI=; b=k6cbmvIzCcOdOX3m3kYGiK2Hi7kQO2tpnSpu+yQHSRdq19smFsAlwP2WyaLuYqGA81 ST0HC46sZZCPlcDVzlsZngYKkmYUZGiijjHeiEga3ojvUTPiDlA8Je3H8QuPs56yJNxE OdiJ1r72oNdkvjN29nClcJxRWH7BJlGJFyuWbQAnqeLUpitHc5DaflV7PVX35whA3qnK bdt/2r6J9Ntu9Ze0412MtI3QvLxqnKOw5t5pgXe6SSHE60Y0GDETnaznwUx+mWqOZjDf piGi/8bLAH2sISDOxLjVMPZSkD6AoRlD6g1HJTDba8HJvBS1bZ42sMfRQTLqiezEgFxn ZdhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=c1dW6fsw; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y92-20020a50bb65000000b0046965a49126si3101803ede.528.2022.12.23.07.40.13; Fri, 23 Dec 2022 07:40:36 -0800 (PST) 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=@sifive.com header.s=google header.b=c1dW6fsw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236577AbiLWPjA (ORCPT + 99 others); Fri, 23 Dec 2022 10:39:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236510AbiLWPif (ORCPT ); Fri, 23 Dec 2022 10:38:35 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6D3344978 for ; Fri, 23 Dec 2022 07:38:31 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id a17so4878839wrt.11 for ; Fri, 23 Dec 2022 07:38:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=phcPBaGxOFAemR9YFsCDrE8yrlHvz+AvjsJ/jn+/KmI=; b=c1dW6fswqOk88Gf/Gfe0CipTkkN7B8IgXCJ91XtahUgCbDvyINz+s60nE+cNPvGYiq KuaO3sKmR8RlS5sCFXVEr7+A3xmEY0eaqV9GRw2b9laGJtkk6VHoPkf3PXvdqLfGjZES ttN7plU8rbZEuEpD/z6iJY3jvhjWytKe/6BFI8XJKvxJ4mDSzmu4OgJO5N3KFh4LzjS0 hcnRtrDynE39dGiK1w5CnOCaqpjPMseXNoKrEftJzI0xb5+vT4cceaoOGoi2m3HtRXsi HLw5whmCyx3Yp8wR1CRUvUeVSHmHl0psYouf1sGi8H8KLe1mNPUiAAEcdQMIXcReFrGV GIUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=phcPBaGxOFAemR9YFsCDrE8yrlHvz+AvjsJ/jn+/KmI=; b=32/0sC4OszdUyf43hq4FHmMIqsCEpT/upLJ/hBnfhm95pWCcOW9gL993/bSfrbNwq9 FHlRCP0hfWtTR2NUxtgMTZy2P5JEyXTs9SyZjxthwAf7K6uSkO4yJT2m+sVz0yALh18y GeTTxnDjc49M1PcDKyUqPRT2lt/d8yetpzCYbJH3PQ/6jzuolo8RWDId3omRbnnEOw24 L+KlkNrjqG/J9A2+y+zYlu6dMCyxqHg+g+KXCSk3ELnswH0ssONVCH3tV4fQ65WJ+A7s FhL27nssGBu9zEX0Lp19WLk1JTTktR1sjOr4VJmH0i3R4TpW1ryczMbFcby3dBRSfPrZ Wf1Q== X-Gm-Message-State: AFqh2ko1LSpQHJvjqJNdCFmCSR76MCie3OogOu+jPZKgSMp70atFp9BQ C9t+v8PZ/cl60wE0KUEniFJUEQ== X-Received: by 2002:a5d:4d8c:0:b0:241:fb7d:2f15 with SMTP id b12-20020a5d4d8c000000b00241fb7d2f15mr5331850wru.29.1671809911556; Fri, 23 Dec 2022 07:38:31 -0800 (PST) Received: from rainbowdash.. (cpc152649-stkp13-2-0-cust121.10-2.cable.virginm.net. [86.15.83.122]) by smtp.gmail.com with ESMTPSA id m5-20020adfc585000000b00236488f62d6sm3491610wrg.79.2022.12.23.07.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Dec 2022 07:38:31 -0800 (PST) From: Ben Dooks To: linux-pwm@vger.kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Lee Jones , u.kleine-koenig@pengutronix.de, Thierry Reding , Krzysztof Kozlowski , Greentime Hu , jarkko.nikula@linux.intel.com, William Salmon , Jude Onyenegecha , Ben Dooks Subject: [PATCH v7 09/10] pwm: dwc: add PWM bit unset in get_state call Date: Fri, 23 Dec 2022 15:38:19 +0000 Message-Id: <20221223153820.404565-10-ben.dooks@sifive.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221223153820.404565-1-ben.dooks@sifive.com> References: <20221223153820.404565-1-ben.dooks@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753019881116684932?= X-GMAIL-MSGID: =?utf-8?q?1753019881116684932?= If we are not in PWM mode, then the output is technically a 50% output based on a single timer instead of the high-low based on the two counters. Add a check for the PWM mode in dwc_pwm_get_state() and if DWC_TIM_CTRL_PWM is not set, then return a 50% cycle. This may only be an issue on initialisation, as the rest of the code currently assumes we're always going to have the extended PWM mode using two counters. Signed-off-by: Ben Dooks --- v4: - fixed review comment on mulit-line calculations --- drivers/pwm/pwm-dwc.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/pwm/pwm-dwc.c b/drivers/pwm/pwm-dwc.c index 1251620ab771..5ef0fe7ea3e9 100644 --- a/drivers/pwm/pwm-dwc.c +++ b/drivers/pwm/pwm-dwc.c @@ -121,23 +121,30 @@ static void dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, { struct dwc_pwm *dwc = to_dwc_pwm(chip); u64 duty, period; + u32 ctrl, ld, ld2; pm_runtime_get_sync(chip->dev); - state->enabled = !!(dwc_pwm_readl(dwc, - DWC_TIM_CTRL(pwm->hwpwm)) & DWC_TIM_CTRL_EN); + ctrl = dwc_pwm_readl(dwc, DWC_TIM_CTRL(pwm->hwpwm)); + ld = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT(pwm->hwpwm)); + ld2 = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT2(pwm->hwpwm)); - duty = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT(pwm->hwpwm)); - duty += 1; - duty *= dwc->clk_ns; - state->duty_cycle = duty; + state->enabled = !!(ctrl & DWC_TIM_CTRL_EN); - period = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT2(pwm->hwpwm)); - period += 1; - period *= dwc->clk_ns; - period += duty; - state->period = period; + /* If we're not in PWM, technically the output is a 50-50 + * based on the timer load-count only. + */ + if (ctrl & DWC_TIM_CTRL_PWM) { + duty = (ld + 1) * dwc->clk_ns; + period = (ld2 + 1) * dwc->clk_ns; + period += duty; + } else { + duty = (ld + 1) * dwc->clk_ns; + period = duty * 2; + } + state->period = period; + state->duty_cycle = duty; state->polarity = PWM_POLARITY_INVERSED; pm_runtime_put_sync(chip->dev);