Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp715322pxf; Thu, 1 Apr 2021 11:36:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe5Nm3xzxDHYpGHhxXVhmE/M7KVXn4K+rAPkTefd0J39KeCi37silpY0fn6aBDcNBdH33p X-Received: by 2002:aa7:c450:: with SMTP id n16mr11234194edr.16.1617302183408; Thu, 01 Apr 2021 11:36:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617302183; cv=none; d=google.com; s=arc-20160816; b=R8yVOG8/0OM6rNEYRxR0mvIGsDWNhyZZcBAJ50d+MWexqwPSN/LEPpfXDIvClTug+G LzBAyfuvEcUsiz88wTvuG10JbBOpSjVLe8/aHr9/rCkbeot+t4nebpc5Qi6FGixBmXUZ NXLffyCZaJ0PjAOV4VCQEXQ4VptgUQB0L+wg2FQVX1U2nj9STmr6OQIs8axsqB4hUXqG dqDZMwYid+9lWXgEw+OmP01Nm0Jj2fH8cfHcFYDDucpyMoBVhkR+2Bq3m2o/8/7hrkN4 ofl2LcJjdtt69f+qjkiCMSBi0YaZM/kKR1kI3Z9hjvRJLrNGL5qHANNt1j8MBxFpBdVX mM6Q== 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=tT0FEIHy1AZG5V42yfNXqku3bOLvq1PgHkhzVzYTvoM=; b=U+S1WOWjqh0Q1nCM6rZ137QvjPDfqyxL/PvwmIJQGCmm8n6p1K3KWV6E2hs5UsAE/7 Zu2HKdVTdKUHsxDLMIFWzXvksUzm3n6xhpsHLcDambpmSwPR1z5ebMs2z6t9p2PEUVHr rRXzFrbK9OgUxcxSrFJnSLP9gYOAp6OyigMX59yp1EfOc4SlEBLzfdmda75XugYYbPSb DRDHgDhBC5Jdp2xZRRKY6eCgBGLgAJ/Lmkb1eh9cqH1pbVuat+GSRT9GCuieAndsff/F lI2209uCWSdHm0yxmaXcxX/WxcyKaXxQIrKhpQMphvfxzAJ0ZNdjNoTNVMvNG2x5l0D9 keBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pqgruber.com header.s=mail header.b=N1dkgjXA; 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 a19si4476737ejt.403.2021.04.01.11.35.58; Thu, 01 Apr 2021 11:36:23 -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=N1dkgjXA; 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 S240807AbhDASbf (ORCPT + 99 others); Thu, 1 Apr 2021 14:31:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238586AbhDASJj (ORCPT ); Thu, 1 Apr 2021 14:09:39 -0400 Received: from mail.pqgruber.com (mail.pqgruber.com [IPv6:2a05:d014:575:f70b:4f2c:8f1d:40c4:b13e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 557BBC022586; Thu, 1 Apr 2021 08:19:50 -0700 (PDT) Received: from workstation.tuxnet (213-47-165-233.cable.dynamic.surfer.at [213.47.165.233]) by mail.pqgruber.com (Postfix) with ESMTPSA id 7EF5EC72850; Thu, 1 Apr 2021 17:19:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqgruber.com; s=mail; t=1617290382; bh=tT0FEIHy1AZG5V42yfNXqku3bOLvq1PgHkhzVzYTvoM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=N1dkgjXALuojsa/8H3J4tpOlwOsclnmnNwYW4IqBA+2nUaoWknHXtj4UheHJBG0kb obZ4FSYK1lhhuc4DfU0rUy/U+dOZ8yoi2qj2TVyq0yJWGcv6QDahJm5Wg7koSHvOXJ CdpC7TBrm87nec9q3KTXv25F3l0+VxTDMZOHpu00= Date: Thu, 1 Apr 2021 17:19:40 +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 On Thu, Apr 01, 2021 at 03:47:26PM +0200, Thierry Reding wrote: > On Thu, Apr 01, 2021 at 09:50:44AM +0200, Clemens Gruber wrote: > > 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. > > What happens if you enable one of them, it then goes high and then you > enable the next one? Is the second one going to get enabled on the next > period? Or will it start in the middle of the period? The channel configuration is updated at the end of the low cycle of the channel in question and if the counter is already past the ON time, it will start with the next period. So the second one should never start while the first one is high (unless staggering mode is enabled). > To truly enable them atomically, you'd have to ensure they all get > enabled in basically the same write, right? Because otherwise you can > still end up with just a subset enabled and the rest getting enabled > only after the first period. Yes. This could probably be achieved with auto-increment for consecutive channels or with the special ALL channel for all channels. In our usecases this is not required. I'd still like to send a follow up patch in the future that at least implements the register writes per channel with auto increment to not have intermediate states (due to high and low byte being written separately) > > > 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 less problematic because the signal will remain a standard PWM, > it's just shifted by some amount. Technically pwm_apply_state() must > only return when the signal has been enabled, so very strictly speaking > you'd have to wait for a given amount of time to ensure that's correct. > But again, I doubt that any use-case would require you to be that > deterministic. Yes, probably not and if we make it opt-in, it shouldn't be a problem. > > > > 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? > > Yeah, if you use an offset in the PWM specifier, users would have to > manually specify the offset. An interesting "feature" of that would be > that they could configure a subset of PWM channels to run synchronized > (module the atomicity problems discussed above). Not sure if that's > something anyone would ever want to do. Yes and for the common case where you don't care it would be more work for the user. > > Another option would be to add some new flag that specifies that a given > PWM channel may use this mode. In that case users wouldn't have to care > about specifying the exact offset and instead just use the flag and rely > on the driver to pick some offset. Within the driver you could then just > keep the same computation that offsets by channel index, or you could > have any other mechanism that you want. OK, so maybe a PWM_STAGGERING_ALLOWED flag in dt-bindings/pwm/pwm.h, pass it through via a new bool staggering_allowed in struct pwm_args? Thanks, Clemens