Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp288921pxf; Thu, 1 Apr 2021 00:52:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfwahTznzDlyJJfV2lKBSGq6P2tiDHY+yi4Tui6ne9BZbJuXe3OOHIVXUvVbiitTxSB4oW X-Received: by 2002:a17:906:260a:: with SMTP id h10mr7923418ejc.392.1617263547169; Thu, 01 Apr 2021 00:52:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617263547; cv=none; d=google.com; s=arc-20160816; b=KD6Ub9fbwr50f5PxVMPA4utc1HntvQy2XzNDqkrJ/yhbUv0/NoN50qOOYJ6ByV18Jt aqRucu1AVTajX1KYmPIOzfUdwbsbWf2A+kB3O+59YjVuNrmSpQ25LAExdzkgEyhUrXFL 9gud7UxSyXXxigLoVu9OhD+HWIhJ4S4QW04SbQyzIkp3/h8WXGkZIvckwTG0jl2yHYJQ Mq+0re2tEruHeAfbA2pcp1UvTwoiQdQXxl6hGpe4eKAw9icM0Oi36+JFnU+YuVcnM/mJ B8SOW2qLyHqWNUmZzcyvofY9L+1T1OhTbCIFKR8rtwHrXO6k+xl0ABV7sB8evrya8/Iz e0yA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ODlCl+gxfx826JgxdXLsP1/L3ZuE5RKRNde/2G0M1Js=; b=I3qnh5BVxy8+UDH9rpv2ie1jSL1XCnwHx0QJLmde8NZmxHzk6bLgBh+Z9bnGSW4dGE ehrDO1eJtL49LkKuLc0XaL+GoEFPF7GeoB5UVIN+CQ0486KoCpMW/51bES8Cb5ovh+RF 4VGIOHlpHkh4UdtVoS2WlvAmxXT1ZGNOCB5+oZB2Erwqrit3sDwFgqfVdrIUGV3SpAWg vG1jlBngs/y5MOc7gwe1odtLbwoeF7wSlO8CRWAvDzmmJkCXKuHU3cs3qzPAjlwk2IGN c1rLB13CAsuXtxunehsaAc0Ny3qVqDz1Z9erdC/4935qw8Jtn//1PyFpNWdAIe13QvnC h/sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pqgruber.com header.s=mail header.b=vm+unAxx; 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; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=pqgruber.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt5si3629287edb.506.2021.04.01.00.52.04; Thu, 01 Apr 2021 00:52:27 -0700 (PDT) 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; dkim=pass header.i=@pqgruber.com header.s=mail header.b=vm+unAxx; 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; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=pqgruber.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232585AbhDAHuv (ORCPT + 99 others); Thu, 1 Apr 2021 03:50:51 -0400 Received: from mail.pqgruber.com ([52.59.78.55]:57568 "EHLO mail.pqgruber.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229850AbhDAHuu (ORCPT ); Thu, 1 Apr 2021 03:50:50 -0400 Received: from workstation.tuxnet (213-47-165-233.cable.dynamic.surfer.at [213.47.165.233]) by mail.pqgruber.com (Postfix) with ESMTPSA id A1142C729F1; Thu, 1 Apr 2021 09:50:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqgruber.com; s=mail; t=1617263446; bh=ODlCl+gxfx826JgxdXLsP1/L3ZuE5RKRNde/2G0M1Js=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vm+unAxxzDYDDAcYzcIshqmlQmjx+ANEzg1cgGmBq9xzMCYhIJ/cFBWPtQwro6mc6 fzPSM8dsHHH5a8LZXO4Xpv1VRp0BBUz2QHpolY/yaImPbWenQJkygrhaIsAwKRl4xX ddFCPs1eUdFEati69EG92OOU1ZnE38BTW5cJAgB4= Date: Thu, 1 Apr 2021 09:50:44 +0200 From: Clemens Gruber To: Thierry Reding Cc: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , linux-pwm@vger.kernel.org, Sven Van Asbroeck , linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 4/7] pwm: pca9685: Support staggered output ON times Message-ID: References: <20210329125707.182732-1-clemens.gruber@pqgruber.com> <20210329125707.182732-4-clemens.gruber@pqgruber.com> <20210329170357.par7c3izvtmtovlj@pengutronix.de> <20210329180206.rejl32uajslpvbgi@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Thierry, On Wed, Mar 31, 2021 at 06:21:32PM +0200, Thierry Reding wrote: > On Wed, Mar 31, 2021 at 02:26:14PM +0200, Clemens Gruber wrote: > > On Mon, Mar 29, 2021 at 08:02:06PM +0200, Uwe Kleine-K?nig wrote: > > > On Mon, Mar 29, 2021 at 07:16:38PM +0200, Clemens Gruber wrote: > > > > On Mon, Mar 29, 2021 at 07:03:57PM +0200, Uwe Kleine-K?nig wrote: > > > > > On Mon, Mar 29, 2021 at 02:57:04PM +0200, Clemens Gruber wrote: > > > > > > The PCA9685 supports staggered LED output ON times to minimize current > > > > > > surges and reduce EMI. > > > > > > When this new option is enabled, the ON times of each channel are > > > > > > delayed by channel number x counter range / 16, which avoids asserting > > > > > > all enabled outputs at the same counter value while still maintaining > > > > > > the configured duty cycle of each output. > > > > > > > > > > > > Signed-off-by: Clemens Gruber > > > > > > > > > > Is there a reason to not want this staggered output? If it never hurts I > > > > > suggest to always stagger and drop the dt property. > > > > > > > > There might be applications where you want multiple outputs to assert at > > > > the same time / to be synchronized. > > > > With staggered outputs mode always enabled, this would no longer be > > > > possible as they are spread out according to their channel number. > > > > > > > > Not sure how often that usecase is required, but just enforcing the > > > > staggered mode by default sounds risky to me. > > > > > > There is no such guarantee in the PWM framework, so I don't think we > > > need to fear breaking setups. Thierry? > > > > Still, someone might rely on it? But let's wait for Thierry's opinion. > > There's currently no way to synchronize two PWM channels in the PWM > framework. And given that each PWM channel is handled separately the > programming for two channels will never happen atomically or even > concurrently, so I don't see how you could run two PWMs completely > synchronized to one another. As the PCA9685 has only one prescaler and one counter per chip, by default, all PWMs enabled will go high at the same time. If they also have the same duty cycle configured, they also go low at the same time. > Or did I misunderstand and it's only the start time of the rising edge > that's shifted, but the signal will remain high for a full duty cycle > after that and then go down and remain low for period - duty - offset? Yes, that's how it works. > > That's slightly better than the above in that it likely won't trip up > any consumers. But it might still be worth to make this configurable per > PWM (perhaps by specifying a third specifier cell, in addition to the > period and flags, that defines the offset/phase of the signal). > > In both cases, doing this on a per-PWM basis will allow the consumer to > specify that they're okay with staggered mode and you won't actually > force it onto anyone. This effectively makes this opt-in and there will > be no change for existing consumers. I agree that it should be opt-in, but I am not sure about doing it per-pwm: The reason why you'd want staggered mode is to reduce EMI or current spikes and it is most effective if it is enabled for all PWMs. If it is specified in the DT anyway and you have a consumer that does not support staggered mode (probably rare but can happen), then I'd suggest just disabling it globally by not specifying nxp,staggered-mode; Also it would make the configuration more complicated: You have to do the "staggering" yourself and assign offsets per channel. It's certainly easier to just enable or disable it. What do you think? > > > One reason we might not want staggering is if we have a consumer who > > > cares about config transitions. (This however is moot it the hardware > > > doesn't provide sane transitions even without staggering.) > > > > > > Did I already ask about races in this driver? I assume there is a > > > free running counter and the ON and OFF registers just define where in > > > the period the transitions happen, right? Given that changing ON and OFF > > > needs two register writes probably all kind of strange things can > > > happen, right? (Example thought: for simplicity's sake I assume ON is > > > always 0. Then if you want to change from OFF = 0xaaa to OFF = 0xccc we > > > might see a period with 0xacc. Depending on how the hardware works we > > > might even see 4 edges in a single period then.) > > > > Yes, there is a free running counter from 0 to 4095. > > And it is probably true, that there can be short intermediate states > > with our two register writes. > > > > There is a separate mode "Update on ACK" (MODE2 register, bit 3 "OCH"), > > which is 0 by default (Outputs change on STOP command) but could be set > > to 1 (Outputs change on ACK): > > "Update on ACK requires all 4 PWM channel registers to be loaded before > > outputs will change on the last ACK." > > This sounds like it would allow atomic updates of the PWM settings. > That's probably something that you want to implement to avoid any > glitches. > > > The chip datasheet also states: > > "Because the loading of the LEDn_ON and LEDn_OFF registers is via the > > I2C-bus, and asynchronous to the internal oscillator, we want to ensure > > that we do not see any visual artifacts of changing the ON and OFF > > values. This is achieved by updating the changes at the end of the LOW > > cycle." > > > > We could look into this in a future patch series, however I would like > > to keep the register updating as-is for this series (otherwise I would > > have to do all the tests with the oscilloscope again and the transitions > > were like this since the driver was first implemented). > > Yeah, it sounds fine to implement this at a later point in time. No need > to conflate it with the current series. Sounds good. Thanks, Clemens