Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1131099rdg; Fri, 13 Oct 2023 11:05:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBXST8pYL+6xQCsIyyUAggy4B5+uspaHpJ2Mp7D4xwnz6szHzru//mcn9Q9VxsHHGPfRky X-Received: by 2002:a05:6a21:32a0:b0:15e:9923:3e35 with SMTP id yt32-20020a056a2132a000b0015e99233e35mr1185581pzb.19.1697220314946; Fri, 13 Oct 2023 11:05:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697220314; cv=none; d=google.com; s=arc-20160816; b=M+EsWf2081YIWsLjXA5FE0Ulzm+Iscl0iXWtqDP3V/uy19rOBggsRLUlH8yNv2Cg/R eSbNZIFbhU07yO2yPldwh+25stabomGmo0fGzFaGLbozD3klJYZIzRnShLOEzEErYrlS uULUzMSP4koLS4UPxVSgunCY8s01sPnJkyunamjeHlIlxzUMDWniR3AMzaK39b1oibsY QmF5EzUFkv6s5+HqxxSazljwbmL7FPZ9eeSEtUIxlY6erwY3X+A1vGT7VLZW7y1ftq5K /PiQqO1tRJ2QDyN9cq5TaF52vqPBBfdHqTYYy2U+JS10IuTS2owZktL9xbSXszbVC3/o +RLw== 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=LC+ORVQ2qJUsQZls/mlQHjuop107+0j3zPTeRAETHDA=; fh=ylAsP/YE//jkOAd39Ml64xWL7HgVfRabZBbp1XINrWo=; b=ZzvmJF4as46qtGmCiglQRyEuusHqDNxtjb/snhg/RbkfqEpOoy4+sc8teNFTFeDvhl bnWj8qybk++LEpV7aYi6mO/V00zQ0ypoOZ5csTrvYxkW9KD6VcRXbitvGwnYIR7V6+6C H4oV6UR3ZhwOzlD5VR3Ex6DsxfHBRA73Er466Th+uTRqpXsrT0EkfdxN1ftDoKfz5Ui7 UCEcgsZgL+mIBNaMpYGGycOC3doq2x87He49Yqpnc8svShrZ2690+Qs3Ny8YwlJOOAXF hPwiP5rsT3NsWwCWMPkgC7xaVRmT7mdCduu2JdABoLao3q3GzBu2jaOzdRl6g1k+drhy UM6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id k2-20020a635a42000000b00578d1b590b0si4792127pgm.699.2023.10.13.11.05.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 11:05:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 40D8482D2B58; Fri, 13 Oct 2023 11:05:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230347AbjJMSE5 (ORCPT + 99 others); Fri, 13 Oct 2023 14:04:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjJMSE4 (ORCPT ); Fri, 13 Oct 2023 14:04:56 -0400 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D01A983 for ; Fri, 13 Oct 2023 11:04:54 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qrMWo-00083i-4x; Fri, 13 Oct 2023 20:04:50 +0200 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qrMWn-001Rlc-Hm; Fri, 13 Oct 2023 20:04:49 +0200 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1qrMWn-00FjD1-8T; Fri, 13 Oct 2023 20:04:49 +0200 Date: Fri, 13 Oct 2023 20:04:49 +0200 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: Thierry Reding Cc: Sean Young , linux-media@vger.kernel.org, Ivaylo Dimitrov , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] pwm: make it possible to apply pwm changes in atomic context Message-ID: <20231013180449.mcdmklbsz2rlymzz@pengutronix.de> References: <9c0f1616fca5b218336b9321bfefe7abb7e1749f.1697193646.git.sean@mess.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="vcxtukqygxnpby24" Content-Disposition: inline In-Reply-To: X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 13 Oct 2023 11:05:12 -0700 (PDT) --vcxtukqygxnpby24 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, On Fri, Oct 13, 2023 at 05:34:34PM +0200, Thierry Reding wrote: > On Fri, Oct 13, 2023 at 03:58:30PM +0100, Sean Young wrote: > > On Fri, Oct 13, 2023 at 01:51:40PM +0200, Thierry Reding wrote: > > > On Fri, Oct 13, 2023 at 11:46:14AM +0100, Sean Young wrote: > > > [...] > > > > diff --git a/include/linux/pwm.h b/include/linux/pwm.h > > > > index d2f9f690a9c1..93f166ab03c1 100644 > > > > --- a/include/linux/pwm.h > > > > +++ b/include/linux/pwm.h > > > > @@ -267,6 +267,7 @@ struct pwm_capture { > > > > * @get_state: get the current PWM state. This function is only > > > > * called once per PWM device when the PWM chip is > > > > * registered. > > > > + * @atomic: can the driver execute pwm_apply_state in atomic conte= xt > > > > * @owner: helps prevent removal of modules exporting active PWMs > > > > */ > > > > struct pwm_ops { > > > > @@ -278,6 +279,7 @@ struct pwm_ops { > > > > const struct pwm_state *state); > > > > int (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm, > > > > struct pwm_state *state); > > > > + bool atomic; > > > > struct module *owner; > > > > }; > > >=20 > > > As I mentioned earlier, this really belongs in struct pwm_chip rather > > > than struct pwm_ops. I know that Uwe said this is unlikely to happen, > > > and that may be true, but at the same time it's not like I'm asking > > > much. Whether you put this in struct pwm_ops or struct pwm_chip is > > > about the same amount of code, and putting it into pwm_chip is much > > > more flexible, so it's really a no-brainer. > >=20 > > Happy to change this of course. I changed it and then changed it back a= fter > > Uwe's comment, I'll fix this in the next version. > >=20 > > One tiny advantage is that pwm_ops is static const while pwm_chip is > > allocated per-pwm, so will need instructions for setting the value. Hav= ing > > said that, the difference is tiny, it's a single bool. >=20 > Yeah, it's typically a single assignment, so from a code point of view > it should be pretty much the same. I suppose from an instruction level > point of view, yes, this might add a teeny-tiny bit of overhead. >=20 > On the other hand it lets us do interesting things like initialize > chip->atomic =3D !regmap_might_sleep() for those drivers that use regmap > and then not worry about it any longer. >=20 > Given that, I'm also wondering if we should try to keep the terminology > a bit more consistent. "Atomic" is somewhat overloaded because ->apply() > and ->get_state() are part of the "atomic" PWM API (in the sense that > applying changes are done as a single, atomic operation, rather than in > the sense of "non-sleeping" operation). >=20 > So pwm_apply_state_atomic() is then doubly atomic, which is a bit weird. > On the other hand it's a bit tedious to convert all existing users to > pwm_apply_state_might_sleep(). >=20 > Perhaps as a compromise we can add pwm_apply_state_might_sleep() and > make pwm_apply_state() a (deprecated) alias for that, so that existing > drivers can be converted one by one. To throw in my green for our bike shed: I'd pick pwm_apply_state_cansleep() to match what gpio does (with gpiod_set_value_cansleep()). (Though I have to admit that semantically Thierry's might_sleep is nicer as it matches might_sleep().) If we don't want to have an explicit indicator for the atomic/fast variant (again similar to the gpio framework), maybe we can drop "_state" which I think is somehow redundant and go for: pwm_apply (fast) pwm_apply_cansleep (sleeping) pwm_apply_state (compat alias for pwm_apply_cansleep()) (maybe replace cansleep with might_sleep). Similar for pwm_get_state() we could use the opportunity and make pwm_get() actually call ->get_state() and introduce pwm_get_lastapplied() with the semantic of todays pwm_get_state(). Do we need a pwm_get_cansleep/might_sleep()? Best regards Uwe --=20 Pengutronix e.K. | Uwe Kleine-K=F6nig | Industrial Linux Solutions | https://www.pengutronix.de/ | --vcxtukqygxnpby24 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEP4GsaTp6HlmJrf7Tj4D7WH0S/k4FAmUphsAACgkQj4D7WH0S /k6Exgf/SslgJkq9wxqIrotIrMj9NqpF1D4hMBxPW0FePgl21tJ23I4t2YyHT2MW x5S8hPckkkhVD+rKMbdTLO2J5ixU/ems11N+Cz5ScrA6JM9lX1UvXcm8VEppCbuf upnqeEPb+lzyBgtD1/dBz72xJOQXkpCtfOTHjQatE4Uo05tf8ntYLmByvHmMnoIb MkfKcDXQwmLJheS3pqG0RpBTtdWXhm+6BqCHR+fwHeHhpsUoFYzQCxVmWh+FX7LC P1Yup1ajVGxDIJtM/+Q1HBAUw+OYq1YgQQnPy7zAljwh0mRA+r7t/6heFdZP1+9f EdMtfXZAsOjYFAYqHoHd5FUBTynyfA== =t7Yp -----END PGP SIGNATURE----- --vcxtukqygxnpby24--