From mboxrd@z Thu Jan 1 00:00:00 1970 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= Subject: Re: [PATCH v3 4/7] pwm: sun4i: Add support to output source clock directly Date: Thu, 7 Nov 2019 07:51:18 +0100 Message-ID: <20191107065118.j4s5cghj4ark7sql@pengutronix.de> References: <20191105131456.32400-1-peron.clem@gmail.com> <20191105131456.32400-5-peron.clem@gmail.com> <20191105145659.ffezqntodsys4phn@pengutronix.de> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=m.gmane.org@lists.infradead.org To: =?iso-8859-1?Q?Cl=E9ment_P=E9ron?= Cc: Mark Rutland , linux-pwm@vger.kernel.org, Jernej Skrabec , devicetree , linux-kernel , Maxime Ripard , Rob Herring , Chen-Yu Tsai , Thierry Reding , Philipp Zabel , linux-arm-kernel List-Id: linux-pwm@vger.kernel.org Hello Cl=E9ment, On Wed, Nov 06, 2019 at 10:24:39PM +0100, Cl=E9ment P=E9ron wrote: > On Tue, 5 Nov 2019 at 15:57, Uwe Kleine-K=F6nig > wrote: > > On Tue, Nov 05, 2019 at 02:14:53PM +0100, Cl=E9ment P=E9ron wrote: > > > + bypass =3D state->enabled && > > > + (state->period * clk_rate >=3D NSEC_PER_SEC) && > > > > This is too coarse. With state->period =3D 1000000 this is fulfilled > > (unless the multiplication overflows). > = > Sorry, misunderstood the previous mail > = > What about something like this ? > ((state->period - 1) * clk_rate <=3D NSEC_PER_SEC) && > ((state->period + 1) * clk_rate >=3D NSEC_PER_SEC) && > ((state->duty_cycle - 1) * 2 <=3D state->period) && > ((state->duty_cycle + 1) * 2 >=3D state->period); > = > We are sure that the user is looking for a PWM around the OSC with a > 50% duty cycle ? This again is too strict. The general policy to fulfill a request is: 1) provide the longest possible period not bigger than requested 2) provide the longest possible duty cycle not bigger than requested 3) if possible complete the currently running period before switching and don't return to the user before the new setting is active. Document the behaviour prominently because the code (usually) doesn't allow to understand the hardware's features here. 4) A disabled PWM should output the inactive level And then there is a corner case: If the user requests .duty_cycle =3D 0, .enabled =3D 1 it is ok to provide .enabled =3D 0 iff otherwise 0% isn't possible. So the right check for bypass is: state->period * clk_rate >=3D NSEC_PER_SEC && state->period * clk_rate < whatevercanbereachedwithoutbypass && state->duty_cycle * clk_rate * 2 >=3D NSEC_PER_SEC Best regards Uwe -- = Pengutronix e.K. | Uwe Kleine-K=F6nig | Industrial Linux Solutions | http://www.pengutronix.de/ |