Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2963310pxu; Sun, 29 Nov 2020 10:17:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwME80xuqWhH20F6rlT+8m0K4nL94ThiMkXB9iT43mPA7QB8NY+3IXdt7KGhdnabtFBJRzI X-Received: by 2002:a17:906:454c:: with SMTP id s12mr1301464ejq.277.1606673825012; Sun, 29 Nov 2020 10:17:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606673825; cv=none; d=google.com; s=arc-20160816; b=xJe+isboJ95nQGE3XPFadXRbnPaK6ppbnhBc1zfOW4A9lzFbfM+pZqVyeg2G6OntnS /x3xtUwAIJ5EIRXHIelhGmS7YAb/4F6av5Vl9BksLb7whUq+Y8IRCm9I+7e6e1h4XAAh aIwGS4KORw4ck506PtoVotzrlLNSL7tDLAlYsR6wlqXw6Rfa148XqU4pgPshp8+Bc6mX dxqInGfAv/jddBgclye76EL9JZqX23+7bsLhDTkDTekSw2jH+k1Xbv9qMjXPgRkQ1IeV RbTz9YMxPXfqhk2rm0TwUgmOtr+aBxZovI1PFX6PC9L1lRYWK1vPSXYmLLt8NM+i5bap /ljg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=MoC7d5dlR3Lc7jHhtkAfXn7TVUvz/mEnzTvo3QexidY=; b=CqGsFOCaMX0gLPeSK8otIJJgoxYO1AcTpjrNtkvcxqekwAVeg+py4fJcR2ulR5tF7y kvzj9SJ1ELAs+RuorFUcNKy5NjFC67XB+bmNstBIzfVUu2qdMNyd2DznSTc1lW7Cw5jP Iej7Cz3Uei8JO0whqD4DKKRjevVQZ7phAZ2GbsjQaZtHaC8Q9hQ0JrV+9bAK1uluNpM/ BUDSkwOhe8HCVlXZrNd1mP+U5hwmV6MTatU/RN99odwTmR4GjUyTlRomsq5/PF0mw20m ZlF8alOQm9yPMPm8zuHHPBKA9r5khL1Ez8/7XK5L56iYtrRByaxYY22gHxZZ4wVOeeSF WnyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n8si3207584ejr.420.2020.11.29.10.16.40; Sun, 29 Nov 2020 10:17:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728173AbgK2SLn (ORCPT + 99 others); Sun, 29 Nov 2020 13:11:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728114AbgK2SLm (ORCPT ); Sun, 29 Nov 2020 13:11:42 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C636C0613D3 for ; Sun, 29 Nov 2020 10:11:02 -0800 (PST) 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 1kjR9z-0001or-Hl; Sun, 29 Nov 2020 19:10:55 +0100 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1kjR9y-0004rr-Ee; Sun, 29 Nov 2020 19:10:54 +0100 Date: Sun, 29 Nov 2020 19:10:50 +0100 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: Lino Sanfilippo Cc: thierry.reding@gmail.com, lee.jones@linaro.org, nsaenzjulienne@suse.de, f.fainelli@gmail.com, rjui@broadcom.com, sbranden@broadcom.com, bcm-kernel-feedback-list@broadcom.com, linux-pwm@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] pwm: bcm2835: Support apply function for atomic configuration Message-ID: <20201129181050.p6rkif5vjoumvafm@pengutronix.de> References: <202011281128.54eLfMWr-lkp@intel.com> <1606564926-19555-1-git-send-email-LinoSanfilippo@gmx.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="5swyij2tuuhknhdb" Content-Disposition: inline In-Reply-To: <1606564926-19555-1-git-send-email-LinoSanfilippo@gmx.de> 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-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --5swyij2tuuhknhdb Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Nov 28, 2020 at 01:02:06PM +0100, Lino Sanfilippo wrote: > Use the newer apply function of pwm_ops instead of config, enable, disable > and set_polarity. >=20 > This guarantees atomic changes of the pwm controller configuration. It al= so > reduces the size of the driver. >=20 > This has been tested on a Raspberry PI 4. >=20 > v2: Fixed compiler error Changelog between review rounds go to below the tripple-dash below. > Signed-off-by: Lino Sanfilippo > --- > drivers/pwm/pwm-bcm2835.c | 64 ++++++++++++++++-------------------------= ------ > 1 file changed, 21 insertions(+), 43 deletions(-) >=20 > diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c > index 6841dcf..dad7443 100644 > --- a/drivers/pwm/pwm-bcm2835.c > +++ b/drivers/pwm/pwm-bcm2835.c > @@ -58,13 +58,14 @@ static void bcm2835_pwm_free(struct pwm_chip *chip, s= truct pwm_device *pwm) > writel(value, pc->base + PWM_CONTROL); > } > =20 > -static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *= pwm, > - int duty_ns, int period_ns) > +static int bcm2835_pwm_apply(struct pwm_chip *chip, struct pwm_device *p= wm, > + const struct pwm_state *state) > { > + > struct bcm2835_pwm *pc =3D to_bcm2835_pwm(chip); > unsigned long rate =3D clk_get_rate(pc->clk); > unsigned long scaler; > - u32 period; > + u32 value; > =20 > if (!rate) { > dev_err(pc->dev, "failed to get clock rate\n"); > @@ -72,65 +73,42 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, = struct pwm_device *pwm, > } > =20 > scaler =3D DIV_ROUND_CLOSEST(NSEC_PER_SEC, rate); > - period =3D DIV_ROUND_CLOSEST(period_ns, scaler); > + /* set period */ > + value =3D DIV_ROUND_CLOSEST_ULL(state->period, scaler); You're storing an unsigned long long (i.e. 64 bits) in an u32. If you are sure that this won't discard relevant bits, please explain this in a comment for the cursory reader. Also note that round_closed is probably wrong, as .apply() is supposed to round down the period to the next achievable period. (But fixing this has to do done in a separate patch.) Best regards Uwe --=20 Pengutronix e.K. | Uwe Kleine-K=F6nig | Industrial Linux Solutions | https://www.pengutronix.de/ | --5swyij2tuuhknhdb Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAl/D5CcACgkQwfwUeK3K 7AnJDwf9E/ryrmjtun7VJxEEtA3dKXzqCwdvNxUnoWdwundHkyX78y8CpI5guv/w 1LQrUnpqqVGCuLPihnF5cpjtcxprC2SbShCgZBErumoVoC0n4ZYb3j+z0ld/p9d6 ff4VlBmYjf5Wpzoq347N5d0tTsq6M0+GknYOtc4SIuEDkOqoUhROg/+MkYvdMZES wBS/9vWTD6SX0OnXa7DPRon8P0INQmcCYcJkOHrIsQeUiTQJfh+Ux/McwmI9yxFv zXBL0vsViZ79V3U08p9XMQ+E7LCJMqfcqFQKlmuP1ARgo1Z5hxpnDQREaU9+rEaj 5vJPYJlb7qFzisCGSkEpgY+Fjhw5KA== =T3ed -----END PGP SIGNATURE----- --5swyij2tuuhknhdb--