From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0718BC433DF for ; Fri, 7 Aug 2020 07:47:24 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C9D17221E5 for ; Fri, 7 Aug 2020 07:47:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TsbtFY0K" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C9D17221E5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=voVwCkRcw4wzO11PxpT1o06dI8j5jkMWXzhl9aw4LYY=; b=TsbtFY0KfmWQtx77uFGZDbZv5 THgp3H4xDxWd4/JSN/oOsk/kjSmqyfvIAwn/ypINVzPtavjn4AoRt3ZeUkn7mz8yTjRvsENLcnn/x nxUfIRoAOzVTE8Y4KixN3Ea3LIKBG65fYMxnXrBNf0RJ2uUQ/GSD81tDLR7AYST47yco5D6DahQKj Xj1BP7f32Zf6Tz0haT3LG3bd4YLoG38o1y/fVZIB0mAiNLA++czD9ekorhbhn16b1Smvv+MBSdXA0 J9aXHX+YYfMhalr52kE3mnLwxrC265ay54PHC4+pop7s0RNF5JmNmvCxyi2/LsLNOPHA1Ea2EpLQu lTLUbgsRQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3x4f-0008Tw-Fy; Fri, 07 Aug 2020 07:45:57 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3x4c-0008TK-Hx for linux-arm-kernel@lists.infradead.org; Fri, 07 Aug 2020 07:45:55 +0000 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 1k3x4V-0001Pr-7L; Fri, 07 Aug 2020 09:45:47 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1k3x4R-000615-Vj; Fri, 07 Aug 2020 09:45:44 +0200 Date: Fri, 7 Aug 2020 09:45:43 +0200 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: Michael Walle Subject: Re: [PATCH v7 06/13] pwm: add support for sl28cpld PWM controller Message-ID: <20200807074543.pfbwlhtegl3oc4zp@pengutronix.de> References: <20200803093559.12289-1-michael@walle.cc> <20200803093559.12289-7-michael@walle.cc> <20200806084000.k3aj5nmqdodmb35v@pengutronix.de> MIME-Version: 1.0 In-Reply-To: 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-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200807_034554_630514_EABDBE3A X-CRM114-Status: GOOD ( 37.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Catalin Marinas , Linus Walleij , Thierry Reding , Pavel Machek , Lee Jones , Jason Cooper , Andy Shevchenko , Marc Zyngier , Bartosz Golaszewski , Guenter Roeck , linux-pwm@vger.kernel.org, Jean Delvare , linux-watchdog@vger.kernel.org, Will Deacon , linux-gpio@vger.kernel.org, Mark Brown , Thomas Gleixner , Wim Van Sebroeck , linux-arm-kernel@lists.infradead.org, linux-hwmon@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Li Yang , Rob Herring , Shawn Guo Content-Type: multipart/mixed; boundary="===============7825577058403979890==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============7825577058403979890== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="6vfvapgawy5623je" Content-Disposition: inline --6vfvapgawy5623je Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 07, 2020 at 09:28:31AM +0200, Michael Walle wrote: > Hi Uwe, Hi Lee, >=20 > Am 2020-08-06 10:40, schrieb Uwe Kleine-K=F6nig: > > On Mon, Aug 03, 2020 at 11:35:52AM +0200, Michael Walle wrote: > > > diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig > > > index 7dbcf6973d33..a0d50d70c3b9 100644 > > > --- a/drivers/pwm/Kconfig > > > +++ b/drivers/pwm/Kconfig > > > @@ -428,6 +428,16 @@ config PWM_SIFIVE > > > To compile this driver as a module, choose M here: the module > > > will be called pwm-sifive. > > >=20 > > > +config PWM_SL28CPLD > > > + tristate "Kontron sl28cpld PWM support" > > > + select MFD_SIMPLE_MFD_I2C > >=20 > > Is it sensible to present this option to everyone? Maybe > >=20 > > depends on SOME_SYMBOL_ONLY_TRUE_ON_SL28CPLD || COMPILE_TEST >=20 > Because there is now no real MFD driver anymore, there is also > no symbol for that. The closest would be ARCH_ARM64 but I don't > think that is a good idea. >=20 > Lee, what do you think about adding a symbol to the MFD, which > selects MFD_SIMPLE_MFD_I2C but doesn't enable any C modules? >=20 > I.e. > config MFD_SL28CPLD > tristate "Kontron sl28cpld" > select MFD_SIMPLE_MFD_I2C > help > Say yes here to add support for the Kontron sl28cpld board > management controller. >=20 > Then all the other device driver could depend on the MFD_SL28CPLD > symbol. >=20 > [..] >=20 > > > +static void sl28cpld_pwm_get_state(struct pwm_chip *chip, > > > + struct pwm_device *pwm, > > > + struct pwm_state *state) > > > +{ > > > + struct sl28cpld_pwm *priv =3D dev_get_drvdata(chip->dev); > > > + unsigned int reg; > > > + int prescaler; > > > + > > > + sl28cpld_pwm_read(priv, SL28CPLD_PWM_CTRL, ®); > > > + > > > + state->enabled =3D reg & SL28CPLD_PWM_CTRL_ENABLE; > > > + > > > + prescaler =3D FIELD_GET(SL28CPLD_PWM_CTRL_PRESCALER_MASK, reg); > > > + state->period =3D SL28CPLD_PWM_PERIOD(prescaler); > > > + > > > + sl28cpld_pwm_read(priv, SL28CPLD_PWM_CYCLE, ®); > > > + state->duty_cycle =3D SL28CPLD_PWM_TO_DUTY_CYCLE(reg); > >=20 > > Should reg be masked to SL28CPLD_PWM_CYCLE_MAX, or is it guaranteed that > > the upper bits are zero? >=20 > Mh, the hardware guarantees that bit7 is zero. So masking with > SL28CPLD_PWM_CYCLE_MAX won't buy us much. But what I could think > could go wrong is this: someone set the prescaler to !=3D 0 and the > duty cycle to a value greater than the max value for this particular > prescaler mode. For the above calculations this would result in a > duty_cycle greater than the period, if I'm not mistaken. >=20 > The behavior of the hardware is undefined in that case (at the moment > it will be always on, I guess). So this isn't a valid setting. > Nevertheless it might happen. So what about the following: >=20 > state->duty_cycle =3D min(state->duty_cycle, state->period); If you care about this: This can also happen (at least shortly) in sl28cpld_pwm_apply() as you write SL28CPLD_PWM_CTRL before SL28CPLD_PWM_CYCLE there. I wonder if we want to sanitize the values returned from driver's =2Eget_state in the core; or scream loud (maybe only if PWM_DEBUG is on). Something like: if (state->enabled && state->duty_cycle > state->period) { if (IS_ENABLED(CONFIG_PWM_DEBUG)) dev_warn(chip->dev, ".get_state() returned invalid setting.\n"); state->duty_cycle =3D state->period; } Do we want to catch state->period =3D 0, too? Do we interpret this as disabled? Best regards Uwe --=20 Pengutronix e.K. | Uwe Kleine-K=F6nig | Industrial Linux Solutions | https://www.pengutronix.de/ | --6vfvapgawy5623je Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEfnIqFpAYrP8+dKQLwfwUeK3K7AkFAl8tBqQACgkQwfwUeK3K 7AkxWAgAoG+PqaPjPFtzNF9JWYONbF6XKaC5Ptr0ArDt6eAhMk/J7dN5fPbk53SY BwI2bQI42oVwcpBcRWuwfW3cRIVw+71KyOcPH5JYyX5BGEKqPOVGpWeHWcE2VCpz wgvROpNxKRAJSkiUCaqPEEGVUyYrYrfYIBVNapbq9BOafMXoyISCClOWpNqMkm77 NH8PRsmlkdbZRXV6r+u7bw859VNc32IAFdITfYJa7iAXe+w8GiS8Ow1iFmdE6pXT v8/RLQsKka7TsakHZ4FgzI4V9nRjaHBlLuY724cyYlScVKHuX3rQiQ6LoU/vTaPD DOycv3Dc1STgW4hmNt9AQcCLCJlL+A== =dkcM -----END PGP SIGNATURE----- --6vfvapgawy5623je-- --===============7825577058403979890== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============7825577058403979890==--