Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1022151pxk; Thu, 10 Sep 2020 05:13:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvV4Tkmq1YSShjngv1mdvWIAytFcM0v6hdLc/A7HjSgV7vWTKmTEjoQHfMTaXm5WMpIqEq X-Received: by 2002:a17:907:432b:: with SMTP id ob19mr8474100ejb.400.1599739992482; Thu, 10 Sep 2020 05:13:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599739992; cv=none; d=google.com; s=arc-20160816; b=t+VuXAbnp3mNsDypogds6Y1LHPxamfJ+q9copIm9vgbWbxHEJENYJ11EX4IfV8FpaT VzsoTUwm8WzenGvJ046tjJtQBeqTa+aaMHfX42d3VbXzwJWL3d42Z8pV4/hwJXsZ6rxO MGUygX9lGE/DohdmFo6wQJxe4uPaBYFXrN+CnTn+1MVYfjG6ZFqfwmCrWHUWIEPrUFoM FjeGAWNeJ5X0amOglxTEgKW8gCrh8KkzKk+IZN493lWlTFyt6urtPUXLrgbzjCiezzXB D/4KCdR3hje/BDgixr7mj1fZEiLD4pr73WthapHPvwfl6PgkacrfsHWhatlfHlClO3wI 4kIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=qICE4gszz8AorcJmZwNU0/DmDlZZLYZRrRtrpUBNX6g=; b=cdXnwisgLIJ1fAimZyjt2w4BEkPtFEkvlND2+/Vzgu9423cz33GnjViQs04xAPWcfC sXD3o+xSba2X3PAPkctZVXa/gKpC2TK8Ux1X0owaM8kPejhAcsqC2ct10eL9NXGS8iwC PQSYhUSpSBiyAUyPAiJhpa1nY3Tz1eDtHxmn/B5c8sOUtpbsyW7Zb/pXModkoYCejkMe 92dtNepp/qtVMMs7rYplVzlw+FAOh5Tn/bTSlHXN8MsTcbAeYN2qLRft9C0/lL1nfKmV wSttXNFjKiyVRB+RGhAzAUXCZcKYURax+l/jVA1OrqNAbMoAjGauqdsjHBZvKj12vqGZ i+aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=L5I+NtBQ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s3si3290663ejz.129.2020.09.10.05.12.48; Thu, 10 Sep 2020 05:13:12 -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=@gmx.net header.s=badeba3b8450 header.b=L5I+NtBQ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728526AbgIJMLZ (ORCPT + 99 others); Thu, 10 Sep 2020 08:11:25 -0400 Received: from mout.gmx.net ([212.227.15.19]:44215 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728350AbgIJMFy (ORCPT ); Thu, 10 Sep 2020 08:05:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1599739483; bh=qzVY6yzsPrrf2h1jDkFWfRG1ddzeALKdqUvY8f8kxa0=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=L5I+NtBQ4gZ/XaRxgukenzKpoKqHPEZpN2IFx04psb175gIZasjOoEKDhYR7RKWsM UVvVc1MqYmbY2N6StTu3oFTQEulC0QsY8hdw8hi2XpQwAIfVZTEQsY2U0vP1RhrNI9 IIyg8IOPGtDPT16OLfLCR4nKBf2Fw71QrbN4ADdY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from longitude ([5.146.195.151]) by mail.gmx.com (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MuUnA-1kXb1F1EZO-00rWJE; Thu, 10 Sep 2020 14:04:43 +0200 Date: Thu, 10 Sep 2020 14:04:28 +0200 From: Jonathan =?utf-8?Q?Neusch=C3=A4fer?= To: Lee Jones Cc: Jonathan =?utf-8?Q?Neusch=C3=A4fer?= , linux-kernel@vger.kernel.org, Rob Herring , Thierry Reding , Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= , Alessandro Zummo , Alexandre Belloni , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Sam Ravnborg , Linus Walleij , Heiko Stuebner , Stephan Gerhold , Lubomir Rintel , Mark Brown , allen , Mauro Carvalho Chehab , "David S. Miller" , devicetree@vger.kernel.org, linux-pwm@vger.kernel.org, linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Heiko Stuebner , Josua Mayer , Andreas Kemnade , Arnd Bergmann , Daniel Palmer Subject: Re: [PATCH v2 03/10] mfd: Add base driver for Netronix embedded controller Message-ID: <20200910120428.GA3306@latitude> References: <20200905133230.1014581-1-j.neuschaefer@gmx.net> <20200905133230.1014581-4-j.neuschaefer@gmx.net> <20200908132934.GT4400@dell> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="wRRV7LY7NUeQGEoC" Content-Disposition: inline In-Reply-To: <20200908132934.GT4400@dell> X-Provags-ID: V03:K1:x4RJpktdT7JqtxxiLTo52FsNglQaWRz741nH+QILas+w8FVRcxR 27KV3AYLrQ49I1+1TR+bS9tBtkWHrt+q8ONM5fw4l6U1A/Z3e4g4EHu58UuKkwp5JRwwl+O 2zn7mGlCAtYpOxJJuGOChMvjvJeNk4XH6elgua7y9AbMuiNAGJv+Gpj2bqY/AhM1Ld4atm5 0sSPE/ntwg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bO4PK4r8aU6ZthJP7DWF2oS688d50i3eFO 8JZfTrGzj6X7cFqajzIJcRZsGaCZSrIQKPGx7Y2JxJQ2w8GxAxxqBHSWOEYg9II1jPK8pAZ7+ wk7kMg1NDLJ5OWN0TvAaMu/JchcU2P3NsU6YIikneTbwOjycTi84X7p/7ndhAjk+KYttjltz2 icKLjgh2PJEjNhHkodas3whdkWo8WTbH4MQ1SH8g7nE+94TGgy/SqjOZivI/6DjEluHCtRm6t o9Zv+D5ye67W+TloUPhX9sievjMfqdCVS6k2ksQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --wRRV7LY7NUeQGEoC Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Sep 08, 2020 at 02:29:34PM +0100, Lee Jones wrote: > On Sat, 05 Sep 2020, Jonathan Neusch=C3=A4fer wrote: [...] > > +config MFD_NTXEC > > + tristate "Netronix embedded controller" >=20 > Nit: "Embedded Controller (EC)" I intentionally left it lowercase, because the term 'embedded controller' is not used in code coming from Netronix. It's just a label that I found fitting to assign to the device. (In the vendor kernels it's either called 'msp430', named after the TI MSP430 microcontroller family, or 'uc', presumably for 'microcontroller') Adding '(EC)' seems somewhat useful. >=20 > > + depends on I2C && OF >=20 > depends on (I2C && OF) || COMPILE_TEST Okay > > +++ b/drivers/mfd/ntxec.c > > @@ -0,0 +1,217 @@ > > +// SPDX-License-Identifier: GPL-2.0-only >=20 > Why 2 only? No particular reason. If you prefer 2-or-later, I'll change it. > > +/* > > + * The Netronix embedded controller is a microcontroller found in some > > + * e-book readers designed by the ODM Netronix, Inc. It contains RTC, > > + * battery monitoring, system power management, and PWM functionality. > > + * > > + * This driver implements register access, version detection, and syst= em > > + * power-off/reset. > > + * > > + * Copyright 2020 Jonathan Neusch=C3=A4fer >=20 > Email? Alright, I'll add it > > +static void ntxec_poweroff(void) > > +{ > > + int res; > > + >=20 > Remove this line please. >=20 > > + u8 buf[] =3D { > > + NTXEC_REG_POWEROFF, > > + (NTXEC_POWEROFF_VALUE >> 8) & 0xff, > > + NTXEC_POWEROFF_VALUE & 0xff, > > + }; > > + >=20 > And this one. >=20 > > + struct i2c_msg msgs[] =3D { > > + { > > + .addr =3D poweroff_restart_client->addr, > > + .flags =3D 0, > > + .len =3D sizeof(buf), > > + .buf =3D buf > > + } > > + }; > > + > > + res =3D i2c_transfer(poweroff_restart_client->adapter, msgs, ARRAY_SI= ZE(msgs)); > > + >=20 > And this one. Okay >=20 > > + if (res < 0) > > + dev_alert(&poweroff_restart_client->dev, "Failed to power off (err = =3D %d)\n", res); >=20 > This looks way over 80 chars. Okay, I'll break it up. > Did you run checkpatch.pl? Yes, but it didn't complain about this line. - propabably because the line length threshold in checkpatch has recently been increased to 100. > > + /* > > + * The time from the register write until the host CPU is powered off > > + * has been observed to be about 2.5 to 3 seconds. Sleep long enough = to > > + * safely avoid returning from the poweroff handler. > > + */ > > + msleep(5000); > > +} > > + > > +static int ntxec_restart(struct notifier_block *nb, > > + unsigned long action, void *data) [...] >=20 > All as above for this function. Alright >=20 > > +static struct notifier_block ntxec_restart_handler =3D { > > + .notifier_call =3D ntxec_restart, > > + .priority =3D 128 > > +}; > > + > > +static const struct regmap_config regmap_config =3D { > > + .name =3D "ntxec", > > + .reg_bits =3D 8, > > + .val_bits =3D 16, > > + .cache_type =3D REGCACHE_NONE, > > + .val_format_endian =3D REGMAP_ENDIAN_BIG, > > +}; > > + > > +static const struct ntxec_info ntxec_known_versions[] =3D { > > + { 0xd726 }, /* found in Kobo Aura */ > > +}; > > + > > +static const struct ntxec_info *ntxec_lookup_info(u16 version) > > +{ > > + int i; > > + > > + for (i =3D 0; i < ARRAY_SIZE(ntxec_known_versions); i++) { > > + const struct ntxec_info *info =3D &ntxec_known_versions[i]; > > + > > + if (info->version =3D=3D version) > > + return info; > > + } > > + > > + return NULL; > > +} >=20 > Wait, what? This is over-engineered. I thought it would be useful when we want to attach additional information to specific versions.... okay, it is over-engineered. > Just have a look-up table (switch) of supported devices. Will do. >=20 > > +static int ntxec_probe(struct i2c_client *client) > > +{ > > + struct ntxec *ec; > > + unsigned int version; > > + int res; > > + > > + ec =3D devm_kmalloc(&client->dev, sizeof(*ec), GFP_KERNEL); > > + if (!ec) > > + return -ENOMEM; > > + > > + ec->dev =3D &client->dev; > > + > > + ec->regmap =3D devm_regmap_init_i2c(client, ®map_config); > > + if (IS_ERR(ec->regmap)) { > > + dev_err(ec->dev, "Failed to set up regmap for device\n"); > > + return res; > > + } > > + > > + /* Determine the firmware version */ > > + res =3D regmap_read(ec->regmap, NTXEC_REG_VERSION, &version); > > + if (res < 0) { > > + dev_err(ec->dev, "Failed to read firmware version number\n"); > > + return res; > > + } > > + dev_info(ec->dev, > > + "Netronix embedded controller version %04x detected.\n", > > + version); > > + > > + /* Bail out if we encounter an unknown firmware version */ > > + ec->info =3D ntxec_lookup_info(version); > > + if (!ec->info) > > + return -EOPNOTSUPP; >=20 > #define EOPNOTSUPP 95 /* Operation not supported on transport e= ndpoint */ >=20 > I think you want: >=20 > #define ENODEV 19 /* No such device */ Indeed, EOPNOTSUPP seems quite wrong here. I think I used ENOTSUPP at some earlier point but moved away from it because it's one of the internal error codes (=E2=89=A5512). ENODEV makes sense when I read it as "Not a device that this driver can deal with". >=20 > > + if (of_device_is_system_power_controller(ec->dev->of_node)) { > > + /* > > + * Set the 'powerkeep' bit. This is necessary on some boards > > + * in order to keep the system running. > > + */ > > + res =3D regmap_write(ec->regmap, NTXEC_REG_POWERKEEP, > > + NTXEC_POWERKEEP_VALUE); > > + if (res < 0) > > + return res; > > + > > + /* Install poweroff handler */ >=20 > Don't think this comment is required. >=20 > > + WARN_ON(poweroff_restart_client); > > + poweroff_restart_client =3D client; > > + if (pm_power_off) > > + dev_err(ec->dev, "pm_power_off already assigned\n"); > > + else > > + pm_power_off =3D ntxec_poweroff; > > + > > + /* Install board reset handler */ >=20 > Nor this. Alright, I'll remove them. > > + res =3D register_restart_handler(&ntxec_restart_handler); > > + if (res) > > + dev_err(ec->dev, > > + "Failed to register restart handler: %d\n", res); > > + } > > + > > + i2c_set_clientdata(client, ec); > > + > > + return devm_of_platform_populate(ec->dev); > > +} > > + > > +static int ntxec_remove(struct i2c_client *i2c) >=20 > Why do you call it 'client' in .probe, but 'i2c' in .remove? No particular reason. I'll make them consistent. > > +struct ntxec_info { > > + u16 version; > > +}; > > + > > +struct ntxec { > > + struct device *dev; > > + struct regmap *regmap; >=20 > > + const struct ntxec_info *info; >=20 > What is this used for? At this point, nothing. I'll remove it. Thanks, Jonathan Neusch=C3=A4fer --wRRV7LY7NUeQGEoC Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEvHAHGBBjQPVy+qvDCDBEmo7zX9sFAl9aFjsACgkQCDBEmo7z X9tAGQ//SrW5PtjGv5XZfjK/Y51oKvi2VtoRlg6p03T3vUyB9j7OPeoadeFgsJae RFlyDcecCt3TFA8hG9L16YBQ34+xA/W0Sa+fN9QM9JBtGpCitFNHYEyar6ONOmAl tfWwjnj6s5ddT9/7+Vq8I0PN5hU5IlpsNSmQQr1W/NtcWrywctorAn4S4RVyMKPs 9invE5HDBx7DZEOOHf0F0zOnIw3ilayCe5aAAhjMo0Q/rbDtrX54M1yr7KkyZxyh 6Kn4gQPLvw3rneXDKmsvMj4bPi/NNrs4WWqwLFsaLkCX9sXwdOssKoLRNO2zj6AJ wUJB2BEZa/DCbCP/oOGrZzpf80sOW+ELpCc4lKkasywI3FEOOC0DhythD342SYwz GBC7MOiwHd3fXn2owynnyj+3QUWd3hg+Rbl6ueaLMXY0Mb1ojmi8GfYHZTORlcpZ 3iXS9CazhgPD2ZTDka3B0H8C2IzpUV5ku7r8jVNxeUHCrV200asvpwZNojewXF// lCGucwAB8tSwVNPlPLuVUnqQLSm1RJoY0zsWb9YGJj4WtQK9crmK2GEfFPTSEetK n0JfMJYlbO1oa69tVDnw1guPNFPYRiKzpE3rS8KVVgaF7LtjouAJX+Fj+0414/Z6 iQiwfoMawFirtow8DvdHt0Y+OSazNz4Y3wn1UkI1V1ikYTRi86c= =ckCY -----END PGP SIGNATURE----- --wRRV7LY7NUeQGEoC--