From mboxrd@z Thu Jan 1 00:00:00 1970 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=-3.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 AB02BC43461 for ; Tue, 8 Sep 2020 08:14:11 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 6084A21D20 for ; Tue, 8 Sep 2020 08:14:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="EJXWY1Jm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6084A21D20 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de 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=merlin.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rTXVBXN1Q6DRyH3e/5u79fU1IcQdWOhDiqz9tL8S7G4=; b=EJXWY1JmyILnRt9Mk80AixgHU +H40aQXSPPSidSvTt2c13wPEV/WTC4i8Q3+B/WRCvkbC8E4Nerbt1mCrUtK6EmCtY/erW7lzVfBqb DfYxNpOouO8ePd3R0zMS/NMkxKkT5ZBj/0Anu75OgBB8HUx4F5j4/jp3xE58kdybVykciu8/LuCoQ ocOfciD9Cmlp1xmFTWeTvtMBIjfzKmN37P0VwTyO9ok3iBb03tdhH210xA0JTFUZBq8rNSwVan0Fs En2hjiSARSPzvVxfRsJKpqSI/2Fi7CN/S6soXaeWLZ+wF1hmifd5oKNR80QY10vrwDKUyXAKMDRF4 a6nmjxcaQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFYkI-00023K-0v; Tue, 08 Sep 2020 08:12:54 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFYkE-00022D-Qm for linux-arm-kernel@lists.infradead.org; Tue, 08 Sep 2020 08:12:52 +0000 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kFYk3-0007xo-6w; Tue, 08 Sep 2020 10:12:39 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1kFYjr-0007B6-Ee; Tue, 08 Sep 2020 10:12:27 +0200 Date: Tue, 8 Sep 2020 10:12:27 +0200 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: Michael Walle Subject: Re: [PATCH v9 06/13] pwm: add support for sl28cpld PWM controller Message-ID: <20200908081227.mxumgqipyod6iltr@pengutronix.de> References: <20200907213802.26745-1-michael@walle.cc> <20200907213802.26745-7-michael@walle.cc> MIME-Version: 1.0 In-Reply-To: <20200907213802.26745-7-michael@walle.cc> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 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-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200908_041250_879793_5BAC0C00 X-CRM114-Status: GOOD ( 27.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Catalin Marinas , Linus Walleij , Thierry Reding , Pavel Machek , Lee Jones , Jason Cooper , Andy Shevchenko , Marc Zyngier , Bartosz Golaszewski , Guenter Roeck , linux-pwm@vger.kernel.org, Jean Delvare , linux-watchdog@vger.kernel.org, Will Deacon , linux-gpio@vger.kernel.org, Mark Brown , Thomas Gleixner , Wim Van Sebroeck , linux-arm-kernel@lists.infradead.org, linux-hwmon@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Li Yang , Rob Herring , Shawn Guo Content-Type: multipart/mixed; boundary="===============3846389721332016876==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============3846389721332016876== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mw42m5g6wzbjjufm" Content-Disposition: inline --mw42m5g6wzbjjufm Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, just a bit of nitpicking left. If Lee is going to apply, I can care for a followup patch if need be. On Mon, Sep 07, 2020 at 11:37:55PM +0200, Michael Walle wrote: > [..] > +config PWM_SL28CPLD > + tristate "Kontron sl28cpld PWM support" > + depends on MFD_SL28CPLD || COMPILE_TEST s/ / / (@Lee, maybe fixup during application?) > + help > + Generic PWM framework driver for board management controller > + found on the Kontron sl28 CPLD. > [...] > +#define SL28CPLD_PWM_CLK 32000 /* 32 kHz */ > +#define SL28CPLD_PWM_MAX_DUTY_CYCLE(prescaler) (1 << (7 - (prescaler))) > +#define SL28CPLD_PWM_PERIOD(prescaler) \ > + (NSEC_PER_SEC / SL28CPLD_PWM_CLK * SL28CPLD_PWM_MAX_DUTY_CYCLE(prescale= r)) > + > +/* > + * We calculate the duty cycle like this: > + * duty_cycle_ns =3D pwm_cycle_reg * max_period_ns / max_duty_cycle > + * > + * With > + * max_period_ns =3D 1 << (7 - prescaler) / pwm_clk * NSEC_PER_SEC > + * max_duty_cycle =3D 1 << (7 - prescaler) > + * this then simplifies to: > + * duty_cycle_ns =3D pwm_cycle_reg / pwm_clk * NSEC_PER_SEC > + * > + * NSEC_PER_SEC is a multiple of SL28CPLD_PWM_CLK, therefore we're not l= osing > + * precision by doing the divison first. The division you're talking about is NSEC_PER_SEC / pwm_clk which isn't obvious in the formula in the line above. Maybe: ... this then simplifies to: duty_cycle_ns =3D NSEC_PER_SEC / SL28CPLD_PWM_CLK * pwm_cycle_reg NSEC_PER_SEC is a multiple of SL28CPLD_PWM_CLK, therefor ... to make it easier to understand the comment. > + */ > +#define SL28CPLD_PWM_TO_DUTY_CYCLE(reg) \ > + (NSEC_PER_SEC / SL28CPLD_PWM_CLK * (reg)) > +#define SL28CPLD_PWM_FROM_DUTY_CYCLE(duty_cycle) \ > + (DIV_ROUND_DOWN_ULL((duty_cycle), NSEC_PER_SEC / SL28CPLD_PWM_CLK)) > [...] > + /* > + * To avoid glitches when we switch the prescaler, we have to make sure > + * we have a valid duty cycle for the new mode. > + * > + * Take the current prescaler (or the current period length) into > + * account to decide whether we have to write the duty cycle or the new > + * prescaler first. If the period length is decreasing we have to > + * write the duty cycle first. > + */ > + write_duty_cycle_first =3D pwm->state.period > state->period; > + > + if (write_duty_cycle_first) { > + ret =3D sl28cpld_pwm_write(priv, SL28CPLD_PWM_CYCLE, cycle); > + if (ret) > + return ret; > + } > + > + ret =3D sl28cpld_pwm_write(priv, SL28CPLD_PWM_CTRL, ctrl); > + if (ret) > + return ret; > + > + if (!write_duty_cycle_first) { > + ret =3D sl28cpld_pwm_write(priv, SL28CPLD_PWM_CYCLE, cycle); > + if (ret) > + return ret; > + } Nice! I didn't spend the necessary brain cycles to confirm this algorithm, but it seems you did :-) > + > + return 0; > +} > [...] Best regards Uwe --=20 Pengutronix e.K. | Uwe Kleine-K=F6nig | Industrial Linux Solutions | https://www.pengutronix.de/ | --mw42m5g6wzbjjufm Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAl9XPOgACgkQwfwUeK3K 7AkWZgf9FfNy+2V7VDKBMqCV2TdrX3JZQCu1jkarn2ieFnlW6nZVplR+63wxFR6p D7E4amJzibzIwMgPt79NI+1LtwNNMI4qEbPOG1zdXo4I6ug4EABv32ih3WMkkdb+ fypHJxYyneVC9nIbRAKHkudi2QfoeikSgtmmAYMw4PG8xc/lqWS3JwNeG4YotvSz aGgVJqFA/2KW0YywCw1ZFv3m4SVU32nFccbo9EJOztwgKKYpN2eEqqxa7baO3jVW JgVzGkkGr9dmi5YYl4jZNcs+IhaPE2mFED7AopB+Hw4CD2FLzssJUFYfZiXtv3+4 RuG7iydfC3hp+a3JWDfv66XeBzvaJQ== =i6C4 -----END PGP SIGNATURE----- --mw42m5g6wzbjjufm-- --===============3846389721332016876== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============3846389721332016876==--