Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp962295pxk; Fri, 25 Sep 2020 02:32:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLUAZCgu1XGq2l9iGpZo/VrrwvY5875NpGHPV4zInQG/optYApmNAv5+jVyMV8DxvOMsvg X-Received: by 2002:a17:906:a2d9:: with SMTP id by25mr1851773ejb.326.1601026323263; Fri, 25 Sep 2020 02:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601026323; cv=none; d=google.com; s=arc-20160816; b=AQffLdtS43QCieXOAOSJtHuh78RlfUiFmHgETyXHlChD36LSS65KGC8NlqIiQiHEWr b05y5K8rxBBRZJdZf8fUFFPqQEmDPtFGwxSPt2P+cVR5wHpFwdwVZdkCA68rC6zPut5J 8M/1Ld/NPPz3Q5easE5c4arDTnM29OKV3rWZltar59X//nxd/invogefLi95h2RchDKJ Yde3znWOckcS5IoJz66kJqkOGCWnSI9VENelSOBU6P7TFaCfUBQg3kY6GyBeb6ZJUKqY HssocGySPWrZCQgzorqFFJinWFOOQ8TXUJ8mmFiITY17Dnk7JPhQP3JdyA++MoaEeizr bIVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=njuKnzjM1XbkGHdVLOoKdb5c4Qn0ofNq9S9KwUbkq6w=; b=igwYWjZ9BxTREhBHe7Bnur7E1b1/6ImpSQuMA8SwEqJAcl9ZDzRLItXv6W4msCegq0 aLmzqgrHvNvYXEB8fGeWS2Az4W1C/QDBGJ0LlUjVv4N6wNdYec1567+b4hl+qc3Kofva HADU6P6Yjk0eIlKsXJoHyY/lvWjY1HHqJy6OmgacX/Vp7L9UpxGXezGzQxS9BBcAXTax 9kXU4JC3sS6mLqtRAw/67bk0msujt7QxyX9dH9c+hpUxkPsi5xXDFGmKa89J2XkTa1Dm jGsIQAlPg/abmN47VdyjLrH17lD6t6t3QZt9J+94nhRUkaMW38Mi3P8NMnaD1zaXohWS rz9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="MXqLK/Nj"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l14si1425778eje.378.2020.09.25.02.31.39; Fri, 25 Sep 2020 02:32:03 -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=@gmail.com header.s=20161025 header.b="MXqLK/Nj"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727943AbgIYJaE (ORCPT + 99 others); Fri, 25 Sep 2020 05:30:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727535AbgIYJaE (ORCPT ); Fri, 25 Sep 2020 05:30:04 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07611C0613CE; Fri, 25 Sep 2020 02:30:04 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id k8so2619173pfk.2; Fri, 25 Sep 2020 02:30:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=njuKnzjM1XbkGHdVLOoKdb5c4Qn0ofNq9S9KwUbkq6w=; b=MXqLK/NjBAfx6dPwfwUBsQkW3e5I1SI1Rg34aYxvpU2In+TP/Tk5T+p4w/NCUXbD9Q fwvBexwllzRw/qjVmJzstwLqpgXatja7mEIU6rx5lnDytAcn0mU3AhlXVBZpYf69lN9F 4LbtezU94x33cxITq4VfuWXhihgdGtSPnCRiK/dmQcoVv5ltSN/g1wBd7stCt8q7NLSr 4oKjMm3y58m6hjC9yExBq1himVKM4tRIaYiXyOESiY/NGtZOaWJo2lqKV2w8h3rSHhnI fnyzyq7QlBcOfsw3O/0pmYQWQ2MRBpfw/u6Mxxrc6+oDoNVqQq29QWf/J4/nl436Uj2v igaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=njuKnzjM1XbkGHdVLOoKdb5c4Qn0ofNq9S9KwUbkq6w=; b=nrLpwmS3nRxol0n8vCyGZA0K/k4LCQ48VzSrqqNAQiGBdHKZPkuGoKoMU1kCUaQRMo 3ERRxLpoinDinje8iwvCS5ZHzLPsDebQoaXI/H/2fdvM/ou1H9ahErBfQ8y7JbwXYkBj CI81Qq465io+vLsfMcOETEzuzTIGo7A2Bbxt3a/cRRyHnh+pCD1xLm+ol80PuS6fn3q0 U5BdbiNDgYVUKHZUJ8Gt/er4JbaoLqXtGc0l+iBhMBlRqZzQD0cZXZbHklj5nuKba21Q 831cNXF2yWfZFuTHkXz3tpsJabN0LPvvQnvb+hToWGgwoAnkm0xGyYmwunhoMrnRAtUt fQVQ== X-Gm-Message-State: AOAM532vWtDv7862D5JDkrEpJmwHKpftq6kiETMrfbbTf2QlJUpVml1B kxte5qis7DBLhoJmiew79rxXgjcjEEIkZml3IHg= X-Received: by 2002:a17:902:c14c:b029:d2:4345:5a9 with SMTP id 12-20020a170902c14cb02900d2434505a9mr3519072plj.0.1601026203296; Fri, 25 Sep 2020 02:30:03 -0700 (PDT) MIME-Version: 1.0 References: <20200924192455.2484005-1-j.neuschaefer@gmx.net> <20200924192455.2484005-4-j.neuschaefer@gmx.net> In-Reply-To: <20200924192455.2484005-4-j.neuschaefer@gmx.net> From: Andy Shevchenko Date: Fri, 25 Sep 2020 12:29:45 +0300 Message-ID: Subject: Re: [PATCH v3 3/7] mfd: Add base driver for Netronix embedded controller To: =?UTF-8?Q?Jonathan_Neusch=C3=A4fer?= Cc: Linux Kernel Mailing List , Lee Jones , Rob Herring , Thierry Reding , =?UTF-8?Q?Uwe_Kleine=2DK=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 , linux-pwm@vger.kernel.org, "open list:REAL TIME CLOCK (RTC) SUBSYSTEM" , linux-arm Mailing List , Heiko Stuebner , Josua Mayer , Andreas Kemnade , Arnd Bergmann , Daniel Palmer Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 24, 2020 at 10:26 PM Jonathan Neusch=C3=A4fer wrote: > > 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 and version detection. > > Third-party hardware documentation is available at: > > https://github.com/neuschaefer/linux/wiki/Netronix-MSP430-embedded-cont= roller > > The EC supports interrupts, but the driver doesn't make use of them so > far. ... > +#include This usually goes after linux/*.h (and actually not visible how it's being used, but see below first) > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include ... > +static void ntxec_poweroff(void) > +{ > + int res; > + u8 buf[] =3D { > + NTXEC_REG_POWEROFF, > + (NTXEC_POWEROFF_VALUE >> 8) & 0xff, > + NTXEC_POWEROFF_VALUE & 0xff, '& 0xff' parts are redundant. *u8 implies that. Fix in all cases. Also I would rather see something like buf[0] =3D _POWEROFF; put_unaligned_be16(_VALUE, &buf[1]); to explicitly show the endianess of the register values. > + }; > + struct i2c_msg msgs[] =3D { > + { > + .addr =3D poweroff_restart_client->addr, > + .flags =3D 0, > + .len =3D sizeof(buf), > + .buf =3D buf It's slightly better to keep trailing commas in cases like this. > + } > + }; > + > + res =3D i2c_transfer(poweroff_restart_client->adapter, msgs, ARRA= Y_SIZE(msgs)); > + if (res < 0) > + dev_alert(&poweroff_restart_client->dev, > + "Failed to power off (err =3D %d)\n", res); alert? This needs to be explained. > + /* > + * 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 eno= ugh to > + * safely avoid returning from the poweroff handler. > + */ > + msleep(5000); > +} > + > +static int ntxec_restart(struct notifier_block *nb, > + unsigned long action, void *data) > +{ > + int res; > + /* > + * NOTE: The lower half of the reset value is not sent, because s= ending > + * it causes an error Why? Any root cause? Perhaps you need to send 0xffff ? > + */ > + u8 buf[] =3D { > + NTXEC_REG_RESET, > + (NTXEC_RESET_VALUE >> 8) & 0xff, Here you may still use put_unaligned_be16() but move the comment to be before len hardcoded to sizeof(buf) - 1. > + }; > + 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, ARRA= Y_SIZE(msgs)); > + if (res < 0) > + dev_alert(&poweroff_restart_client->dev, > + "Failed to restart (err =3D %d)\n", res); > + > + return NOTIFY_DONE; > +} ... > +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); This info level may confuse users if followed by an error path. > + /* Bail out if we encounter an unknown firmware version */ > + switch (version) { > + case 0xd726: /* found in Kobo Aura */ > + break; > + default: > + return -ENODEV; > + } > + > + if (of_device_is_system_power_controller(ec->dev->of_node)) { > + /* > + * Set the 'powerkeep' bit. This is necessary on some boa= rds > + * in order to keep the system running. > + */ > + res =3D regmap_write(ec->regmap, NTXEC_REG_POWERKEEP, > + NTXEC_POWERKEEP_VALUE); > + if (res < 0) > + return res; > + WARN_ON(poweroff_restart_client); WARN_ON? All these alerts, WARNs, BUGs must be explained. Screaming to the user is not good if it wasn't justified. > + 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; > + > + 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); > + > + res =3D devm_mfd_add_devices(ec->dev, PLATFORM_DEVID_NONE, ntxec_= subdevices, > + ARRAY_SIZE(ntxec_subdevices), NULL, 0,= NULL); > + if (res) > + dev_warn(ec->dev, "Failed to add subdevices: %d\n", res); 'warn' is inconsistent with 'return err'. Either do not return an error, or mark a message as an error one. And above with the restart handler has the same issue. > + return res; > +} > + > +static int ntxec_remove(struct i2c_client *client) > +{ > + if (client =3D=3D poweroff_restart_client) { When it's not the case? > + poweroff_restart_client =3D NULL; > + pm_power_off =3D NULL; > + unregister_restart_handler(&ntxec_restart_handler); > + } > + > + return 0; > +} ... > +#include > + Missed struct device; struct regmap; here. > +struct ntxec { > + struct device *dev; > + struct regmap *regmap; > +}; > +/* > + * Some registers, such as the battery status register (0x41), are in > + * big-endian, but others only have eight significant bits, which are in= the > + * first byte transmitted over I2C (the MSB of the big-endian value). > + * This convenience function converts an 8-bit value to 16-bit for use i= n the > + * second kind of register. > + */ > +static inline u16 ntxec_reg8(u8 value) > +{ > + return value << 8; > +} I'm wondering why __be16 is not used as returned type. --=20 With Best Regards, Andy Shevchenko