Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp410684pxu; Tue, 1 Dec 2020 14:35:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJyb9Y7PD7TXi9Vu+ownDKEy+X/QqhPMrxBkEfddyLcYthdB2kPyCsyZnTtA2byKaoUhBlKH X-Received: by 2002:a17:906:3114:: with SMTP id 20mr5289890ejx.460.1606862139020; Tue, 01 Dec 2020 14:35:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606862139; cv=none; d=google.com; s=arc-20160816; b=niZys4vl1sgsjVaUg/+1pdOChgWNMTmzLgHEoHJHlGUZup77zm0CfImb8mXu+5CF3Y raS0ial/sLJTmOb3D6WZcfbtx78mxckvh8PMmkpu2wqOO5uawxndful/B5i/He2of/LZ pyHOhlVkud8KE5TPa7IJmJ/SspM7tMlM3BTW430/gxIn5HRrA0BG3diTcuz0AlnIntXh BxZedegD++b+PjaIoKEcuWcKpBOllqH/Tly/kpOE3FDHsRSHR/H+sqjIFI3LLJC+eQxv AHxsc07RSMGXVYcGY8IWMkWQ1567MoXm7/TUQPr+s1KxI47k6k2ifnTx4QUZi79Q21Zj zmSA== 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:dkim-signature; bh=R6LsTrw1Tvr+/hlXHOGrUkvxwGk11SCcUFKptZRkv6M=; b=kBSw56RXLbPnEgzZ4q31T4XEAkC7jSkc7U6TaV765SIYIoCLlelNCfbHkM3acWvUZo EeBZx6AbVKH7mRh21TkcPVDDGk81nKPQZEmlBgWKTIdSAtmI1j7W9zONVjPIl/Uq7b1w ScjID+3htSxyYf/Bt+3R2ym2GpGZDhwaFoL4JGDe4S/Hpe3QXd0LCcYaBI2WzLxHPTTq dZsYF35nVEIQE8I9+dI9/hj7xfPeH2rJFze7eq8bP59XMpP2t9qmkF/aA6FPnK+bhBHD HCplW7k9mLlFweUEHnZMRR+dK3js9yz8fjezHIQaDod9EUAWZoLLVmqUAFJom2yntEQ7 Q/QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=Zwd0VIYY; 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=NONE sp=NONE dis=NONE) header.from=gmx.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m17si825596ejq.464.2020.12.01.14.35.16; Tue, 01 Dec 2020 14:35:39 -0800 (PST) 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=@gmx.net header.s=badeba3b8450 header.b=Zwd0VIYY; 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=NONE sp=NONE dis=NONE) header.from=gmx.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388325AbgLANYv (ORCPT + 99 others); Tue, 1 Dec 2020 08:24:51 -0500 Received: from mout.gmx.net ([212.227.15.15]:39937 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726630AbgLANYu (ORCPT ); Tue, 1 Dec 2020 08:24:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606828950; bh=i99VwzJVGDFj3yDrUcbTJd0SNy2PldxWlO3kTHGKLXw=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=Zwd0VIYYnGXiDuOA6FLSux2St/gVHc1ZCYSj+oXFYP+92QdH/VOHnd2luK+POgYee I7P1tEsKF4VIfntD3Synfo54JVpV7XV5EBDlFZa5T+R9LtTfRudySMYUIWvjdIQlGY N/D6qOQeCOso+G9rZSALz8OvtwQyRuCIOYF/Njrg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from longitude ([37.201.214.162]) by mail.gmx.com (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MVNAr-1kZslF2XSh-00SSVC; Tue, 01 Dec 2020 14:22:30 +0100 Date: Tue, 1 Dec 2020 14:22:14 +0100 From: Jonathan =?utf-8?Q?Neusch=C3=A4fer?= To: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= Cc: Jonathan =?utf-8?Q?Neusch=C3=A4fer?= , linux-kernel@vger.kernel.org, Alexandre Belloni , Heiko Stuebner , linux-pwm@vger.kernel.org, Linus Walleij , Thierry Reding , Fabio Estevam , linux-rtc@vger.kernel.org, Arnd Bergmann , Mauro Carvalho Chehab , Sam Ravnborg , Daniel Palmer , Andy Shevchenko , Andreas Kemnade , NXP Linux Team , devicetree@vger.kernel.org, Stephan Gerhold , allen , Sascha Hauer , Lubomir Rintel , Rob Herring , Lee Jones , linux-arm-kernel@lists.infradead.org, Alessandro Zummo , Mark Brown , Pengutronix Kernel Team , Heiko Stuebner , Josua Mayer , Shawn Guo , "David S. Miller" Subject: Re: [PATCH v5 4/7] pwm: ntxec: Add driver for PWM function in Netronix EC Message-ID: <20201201132214.GI456020@latitude> References: <20201201011513.1627028-1-j.neuschaefer@gmx.net> <20201201011513.1627028-5-j.neuschaefer@gmx.net> <20201201072026.a736ikf3k4udpvfv@pengutronix.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="tT3UgwmDxwvOMqfu" Content-Disposition: inline In-Reply-To: <20201201072026.a736ikf3k4udpvfv@pengutronix.de> X-Provags-ID: V03:K1:3pVRVbCHusToiK9w2c2SDTiGjXj/Tj+6gQjSAUb5JekWayHQDXA wcasTbzJCVBBO6njymdHIgFtmDPU9chbDh/Fk4bLj603l8LoqWDSRe0Yc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jOBOzw== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --tT3UgwmDxwvOMqfu Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Dec 01, 2020 at 08:20:26AM +0100, Uwe Kleine-K=C3=B6nig wrote: > Hello Jonathan, >=20 > very nice driver, just a few minor comments below. >=20 > On Tue, Dec 01, 2020 at 02:15:10AM +0100, Jonathan Neusch=C3=A4fer wrote: > > +static struct ntxec_pwm *pwmchip_to_priv(struct pwm_chip *chip) >=20 > a function prefix would be great here, I'd pick ntxec_pwm_from_chip as > name. Good point, will do. >=20 > > +{ > > + return container_of(chip, struct ntxec_pwm, chip); > > +} > > + > > +[...] > > +static int ntxec_pwm_apply(struct pwm_chip *chip, struct pwm_device *p= wm_dev, > > + const struct pwm_state *state) > > +{ > > + struct ntxec_pwm *priv =3D pwmchip_to_priv(pwm_dev->chip); > > + unsigned int period, duty; > > + struct reg_sequence regs[] =3D { > > + { NTXEC_REG_PERIOD_HIGH }, > > + { NTXEC_REG_PERIOD_LOW }, > > + { NTXEC_REG_DUTY_HIGH }, > > + { NTXEC_REG_DUTY_LOW } > > + }; > > + int res; > > + > > + if (state->polarity !=3D PWM_POLARITY_NORMAL) > > + return -EINVAL; > > + > > + period =3D min_t(u64, state->period, MAX_PERIOD_NS); > > + duty =3D min_t(u64, state->duty_cycle, period); >=20 > I'm not a big fan of aligning =3D. (As if you have to add a longer > variable you have to realign all otherwise unrelated lines.) But that's > subjective and it's up to you if you want to change this. In this case, I thought it helps the readability, because the lines are quite similar. > > + period /=3D TIME_BASE_NS; > > + duty /=3D TIME_BASE_NS; Here, I did it because I had already aligned the previous two lines. > > + > > + /* > > + * Changes to the period and duty cycle take effect as soon as the > > + * corresponding low byte is written, so the hardware may be configur= ed > > + * to an inconsistent state after the period is written and before the > > + * duty cycle is fully written. If, in such a case, the old duty cycle > > + * is longer than the new period, the EC may output 100% for a moment. > > + */ > > + > > + regs[0].def =3D ntxec_reg8(period >> 8); > > + regs[1].def =3D ntxec_reg8(period); > > + regs[2].def =3D ntxec_reg8(duty >> 8); > > + regs[3].def =3D ntxec_reg8(duty); >=20 > You could even minimize the window by changing the order here to >=20 > NTXEC_REG_PERIOD_HIGH > NTXEC_REG_DUTY_HIGH > NTXEC_REG_PERIOD_LOW > NTXEC_REG_DUTY_LOW Good idea, but I'm not sure if the EC handles this kind of interleaving correctly. > but it gets less readable. Maybe move that to a function to have the > reg_sequence and the actual write nearer together? Indeed, a separate function would keep register names and values together (without resorting to declarations-after-statements). > Or somehow name the indexes to make it more obvious? Too much unnecessary complexity, IMHO. > > + res =3D regmap_multi_reg_write(priv->ec->regmap, regs, ARRAY_SIZE(reg= s)); > > + if (res) > > + return res; > > + > > + /* > > + * Writing a duty cycle of zero puts the device into a state where > > + * writing a higher duty cycle doesn't result in the brightness that = it > > + * usually results in. This can be fixed by cycling the ENABLE regist= er. > > + * > > + * As a workaround, write ENABLE=3D0 when the duty cycle is zero. >=20 > If the device already has duty_cycle =3D 0 but ENABLE =3D 1, you might get > a failure. But I guess this doesn't need addressing in the code. But > maybe point it out in a comment? Good point. I'll add something to the comment. > > + */ > > + if (state->enabled && duty !=3D 0) { > > + res =3D regmap_write(priv->ec->regmap, NTXEC_REG_ENABLE, ntxec_reg8(= 1)); > > + if (res) > > + return res; > > + > > + /* Disable the auto-off timer */ > > + res =3D regmap_write(priv->ec->regmap, NTXEC_REG_AUTO_OFF_HI, ntxec_= reg8(0xff)); > > + if (res) > > + return res; > > + > > + return regmap_write(priv->ec->regmap, NTXEC_REG_AUTO_OFF_LO, ntxec_r= eg8(0xff)); >=20 > Given that you cannot read back period and duty anyhow: Does it make > sense to write these only if (state->enabled && duty !=3D 0)? I think it does. Thanks, Jonathan --tT3UgwmDxwvOMqfu Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEvHAHGBBjQPVy+qvDCDBEmo7zX9sFAl/GQ3EACgkQCDBEmo7z X9usHg/9FsmfCpoU+cy2Zt6dY0RcesbvapgYo5C8a/EuXIF22fNiiOlU+ONMCdjG FDKzKhXmkstFv2VaBM41mUYHPiic4Yf58OS96UJdb7r+fhrFsQajX4h96ILbUkhH bhGOzgHwwc3HRKb2YYlTGLcVhT6a5BFLIZW5bjfgs5x+ucKjD5VjInHU56WNHzO2 1QH3Qrg/essPZ5+ftewe0aFDKinyby4b1sd3gEA6n4NlUIi2COH84Mn5C8vJY6cG uts9NJD80+DqpKyaLNh9a0IDwNWRX1cueizPLF9OghbyFhR7pFNxCDPkC5PkxkvW 0namUmrwk/SyZ5KM77xGCKwqZql6KvIBHtPtszuHXiaqd89tNM/CpxEoF9VQkY5g BZdo0lCR1tEVBzy5ZsM6bQ/0uUB5+0N2hmkjcZ/W08HYUKa47jqNBCtV2dbYsF4m 3O4spfB6F7jM5+UBIfeslyXDnixDhegAAblkCYs8k9AQ/VlMVHtHaXikbi+Dx3d3 i+7AT+lfODFxSmvqWoYK6r0fjoLClTHDgoYC3huLFomaAKDeG1LAxDWosESJz5Lx FGRjFN2kSCI/26KJ6FcLzF6viBC2yd/W7ht0x8+pMMU+L16mGB3bJGZSIAHvSPPh CsVIC2HZIlMdpt57QCMq2Ocw0at9xwbhyFP3xr9kWKKMLjpQSxc= =qsyh -----END PGP SIGNATURE----- --tT3UgwmDxwvOMqfu--