Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp639054rdb; Tue, 31 Oct 2023 19:23:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+vR3gaebCLd+9e2/OjJo+28BC6ySMLYga9pJdOqvOR63zbayxQi84l0XrtaUgz3lj9Woh X-Received: by 2002:a05:6a20:c19a:b0:16b:ff2c:c42c with SMTP id bg26-20020a056a20c19a00b0016bff2cc42cmr11958385pzb.62.1698805401429; Tue, 31 Oct 2023 19:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698805401; cv=none; d=google.com; s=arc-20160816; b=jpIWKu3IwMtvYMzLafYUooXdmKpNP6w/iH+/hyw8YqjvO6OwPQMC26WNsmB2A74xAU FJPE120htchO9RCwQZEJW11LNVrNdjvY8hDrgNbsV6UJqns6c4DRfQcfNfD19xb7OvD/ jXCZd4nONgIyLrsto+kjKMd+kbWUp/RBGXzQyrnYtISqoZUqa2Rcrd46W7ggYBmCD8zf g8DwMiwarZGSbjJ/uU2uV8WWB5n7SXZh/YA0vMIQkR3PVbAMdCm5xS9It55nfuav6LAh umi1LiFjb4LaXSoApPnP7nmHjO1diJnpit+LHmRrcweoxYLb7rvqnSsC1eXtdPuPsAOA 1AwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=g9rwgHt67+4PjXlaHSq1MfzkpHcG1FE5phHtu0VAAeg=; fh=Rpf6snj2sYjYwjj0Br6Z7z/bxVEA8ThtOmysHlDOG5Q=; b=CCJ6JM8eoNdj/dYG7iwNYE9XumoguGZvpSsyF8iCzFdjk+xnHH2Y9qURhHClCf5ms/ +uAyMsTiGkhuylnZo+qXjgLtmeZL+170boZroazcBBEsWPxQMgtRcm0gMlClwb+j2esP QalWQzg+Z2LJKwiT0UN+9/lmeZhQOLFF4/Y19R4W+mSj75K9l8XNKx9n4ibycfeWz4jJ 3mQQIm5uVwQZ77ISVRl3anx5nbBs20k7VmPd9xhrQDBByUuHM8JCjjrW7ANu5jn+YXGg 0sqHY+fEHk4zD15Hbh2Gd7pvkfEIIho7O4YGvbbq2mkvg0H4btVnyLMXu7Z8x3aKxrHl 2YxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id e7-20020a170902cf4700b001cc259278a5si1958358plg.647.2023.10.31.19.23.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 19:23:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D9FFF8023921; Tue, 31 Oct 2023 19:23:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232401AbjKACXE convert rfc822-to-8bit (ORCPT + 99 others); Tue, 31 Oct 2023 22:23:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231197AbjKACXD (ORCPT ); Tue, 31 Oct 2023 22:23:03 -0400 Received: from fd01.gateway.ufhost.com (fd01.gateway.ufhost.com [61.152.239.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEE33101; Tue, 31 Oct 2023 19:22:57 -0700 (PDT) Received: from EXMBX166.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX166", Issuer "EXMBX166" (not verified)) by fd01.gateway.ufhost.com (Postfix) with ESMTP id A24B58139; Wed, 1 Nov 2023 10:22:47 +0800 (CST) Received: from EXMBX168.cuchost.com (172.16.6.78) by EXMBX166.cuchost.com (172.16.6.76) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 1 Nov 2023 10:22:47 +0800 Received: from [192.168.120.47] (171.223.208.138) by EXMBX168.cuchost.com (172.16.6.78) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 1 Nov 2023 10:22:46 +0800 Message-ID: <7d64ea1d-b573-4a69-ba0c-4cbfab638c5e@starfivetech.com> Date: Wed, 1 Nov 2023 10:22:44 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 2/4] pwm: opencores: Add PWM driver support To: =?UTF-8?Q?Uwe_Kleine-K=C3=B6nig?= CC: , , , , "Emil Renner Berthing" , Rob Herring , Thierry Reding , Philipp Zabel , "Krzysztof Kozlowski" , Conor Dooley , Hal Feng , Paul Walmsley , Palmer Dabbelt , Albert Ou References: <20231020103741.557735-1-william.qiu@starfivetech.com> <20231020103741.557735-3-william.qiu@starfivetech.com> <20231020112539.gctx5uj2rrhryulo@pengutronix.de> Content-Language: en-US From: William Qiu In-Reply-To: <20231020112539.gctx5uj2rrhryulo@pengutronix.de> Content-Type: text/plain; charset="UTF-8" X-Originating-IP: [171.223.208.138] X-ClientProxiedBy: EXCAS066.cuchost.com (172.16.6.26) To EXMBX168.cuchost.com (172.16.6.78) X-YovoleRuleAgent: yovoleflag Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 31 Oct 2023 19:23:15 -0700 (PDT) On 2023/10/20 19:25, Uwe Kleine-König wrote: >> + void __iomem *base = pwm->data->get_ch_base ? >> + pwm->data->get_ch_base(pwm->regs, dev->hwpwm) : pwm->regs; >> + u32 period_data, duty_data, ctrl_data; >> + >> + period_data = readl(REG_OCPWM_LRC(base)); >> + duty_data = readl(REG_OCPWM_HRC(base)); >> + ctrl_data = readl(REG_OCPWM_CTRL(base)); >> + >> + state->period = DIV_ROUND_CLOSEST_ULL((u64)period_data * NSEC_PER_SEC, pwm->clk_rate); >> + state->duty_cycle = DIV_ROUND_CLOSEST_ULL((u64)duty_data * NSEC_PER_SEC, pwm->clk_rate); > > Please test your driver with PWM_DEBUG enabled. The rounding is wrong > here. > Hi Uwe, The conclusion after checking is: when the period or duty_cycle value set by the user is not divisible (1000000000/49.5M), there will be an error. This error is due to hardware accuracy. So why is rounding is wrong? rockchip also has a similar implementation drivers/pwm/ pwm-rockchip.c Best regards, William