Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp848838pxu; Wed, 2 Dec 2020 05:09:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyBwQE1OyGq47acELoYQIimnSYs/F7l3YzbthXvnCJMyEIUPxWHH8arjt1a7xXLpMBLQ/Sa X-Received: by 2002:a05:6402:31a5:: with SMTP id dj5mr2461070edb.325.1606914590735; Wed, 02 Dec 2020 05:09:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606914590; cv=none; d=google.com; s=arc-20160816; b=d1q0y9MjBKCcOTvR+DpgFDBWOVbusHhnu10Fhe6Q1N0NxFnOOU3US5aEF5Q0s435mw fLTN/aAjU2DythTL+Honyo0vvXuaYb65gUQNuhvZRptyikax6zmL8AgNgvwJCP7Hrh6Y qwYk1CRhwe4PcYfG7j1TvP6O7jTwJNL0jGWv12Trw022rpEVoiP0DMPk/R4Wm6wWzi7S rTuNyUN/wYzvXKQUPLePxxGr/nVSNcO6lj+i2nLjY7NJVAOMRzij00u5jo8Oq/wtp4qR 1cFJ544T16+u8wLKPIEPhlzuq1iV8Hfc9xNAfL400iNNhIn/heArg9OkPDY7CeL0SwUL rd/A== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=YF+WlyCt3rq165R9rPhsAR5qsYk6r1RiPW2tzO/YPhE=; b=BwbiVkjgHdA22cXDaJWVvdyYACGcPeCl7r+GC/FrKKO/GqlPD04Ed7TA2U27BFydyH hGd9MczjkI3FY5dTR7h+E5kdT2sDg/KtZ3n9h9Mqh6tfWpwClZTNT8PcgexafbM9KiPe l7vmI3VcTweHoUqB2geZecMlY+CMaAdtfv1ivTOYabzPQWLxFnEQTLmaxOSvwn0utk1T 3DlAZSEpV0MUy6URPBppkOqzMc9g5DIXyFmc1u/XG9zqPXT2wCOsZzDA7jskLDQLDggr QN1f9doZW/XbCBGPy+AKtR6iFUcFM3ECHeg3b4xcxo/n7yP7rW/IRvypTFaIr4N8NWzF BD1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kxX9wrHZ; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x14si1042288edj.87.2020.12.02.05.09.27; Wed, 02 Dec 2020 05:09:50 -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=@linaro.org header.s=google header.b=kxX9wrHZ; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730049AbgLBNGL (ORCPT + 99 others); Wed, 2 Dec 2020 08:06:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727102AbgLBNGK (ORCPT ); Wed, 2 Dec 2020 08:06:10 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81CA1C0613CF for ; Wed, 2 Dec 2020 05:05:24 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id u12so3899914wrt.0 for ; Wed, 02 Dec 2020 05:05:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=YF+WlyCt3rq165R9rPhsAR5qsYk6r1RiPW2tzO/YPhE=; b=kxX9wrHZNwlLIJdTxtKvUwuk/et7M4x5wlpSjhdkxmEz1piNL/IeIIXigGIUl9ipjY dIdTNlI4IAELmPStajXBBI+Klk6ii/r0HMOro78xmzlzKgcDUptC4TlsCbnICCG1LW4D sqnfqrSHnT+1OGJzPA6btCamhetgcJo3iPQvqVq8LVzmPPTMGQLF6VuqcOKjcvYGEL1L KiWHTEX6h8AjrKEAv3Z5D3VNdut9VG0waZ9k1XZTtQSZ14qSl0NGIeiTCBj5Mie7kFY3 8IeGal8nhCIgKtpl50HyJ7RBz+qgk/FWV1+tbFCqgiUa8sVSlrevuMAnmbIkxOKg3Bp5 b0dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=YF+WlyCt3rq165R9rPhsAR5qsYk6r1RiPW2tzO/YPhE=; b=eV0a0708TG723hQ+pFAvL9fIMH60IT5Q1El43Lu0OdHNBFFW1V1DWE83Ej02aP3eQw gldo4wyUztRuFMjcpIR0Pj/HRJFqqI/rnwyZIAWWB4alkTXbYXd4syd/0Un0PFQVyBFn 359ycjBf+UveBnfrMd8/vTAMbCdDm9DEgOCK2JbrJKbWx8J6lGuBs+hQZSkOBInUA8fZ McbX7eZXu6Thnwn1QOrDa71jFRxDswizahld/CEJRNkPRQDFprCx6jtiIPTmGfp9H2Bu Xc3SB/Gsw7lOEe9Ta4AVRHEIP0gDf2iCW47Vtzs5HcQS2Wka6WCNvsNHXD5UF/TL1BO5 aroQ== X-Gm-Message-State: AOAM5315EgCbzqnm9XujYjqIfdUj2thCCbO6utDl14B4xXzuH5QVdd3a UcEV+ykCqB6FLSgLygTJDb8l2A== X-Received: by 2002:a5d:548b:: with SMTP id h11mr3417874wrv.306.1606914323134; Wed, 02 Dec 2020 05:05:23 -0800 (PST) Received: from dell ([91.110.221.235]) by smtp.gmail.com with ESMTPSA id v64sm2059455wme.25.2020.12.02.05.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 05:05:22 -0800 (PST) Date: Wed, 2 Dec 2020 13:05:20 +0000 From: Lee Jones To: Jonathan =?iso-8859-1?Q?Neusch=E4fer?= Cc: linux-kernel@vger.kernel.org, Rob Herring , Thierry Reding , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , 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 , Andy Shevchenko Subject: Re: [PATCH v4 3/7] mfd: Add base driver for Netronix embedded controller Message-ID: <20201202130520.GL4801@dell> References: <20201122222739.1455132-1-j.neuschaefer@gmx.net> <20201122222739.1455132-4-j.neuschaefer@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20201122222739.1455132-4-j.neuschaefer@gmx.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 22 Nov 2020, Jonathan Neuschäfer wrote: > The Netronix embedded controller is a microcontroller found in some > e-book readers designed by the original design manufacturer 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-controller > > The EC supports interrupts, but the driver doesn't make use of them so > far. > > Signed-off-by: Jonathan Neuschäfer > --- > > v4: > - include asm/unaligned.h after linux/* > - Use put_unaligned_be16 instead of open-coded big-endian packing > - Clarify that 0x90=0xff00 causes an error in downstream kernel too > - Add commas after non-sentinel positions > - ntxec.h: declare structs device and regmap > - Replace WARN_ON usage and add comments to explain errors > - Replace dev_alert with dev_warn when the result isn't handled > - Change subdevice registration error message to dev_err > - Declare ntxec_reg8 as returning __be16 > - Restructure version detection code > - Spell out ODM > > v3: > - https://lore.kernel.org/lkml/20200924192455.2484005-4-j.neuschaefer@gmx.net/ > - Add (EC) to CONFIG_MFD_NTXEC prompt > - Relicense as GPLv2 or later > - Add email address to copyright line > - remove empty lines in ntxec_poweroff and ntxec_restart functions > - Split long lines > - Remove 'Install ... handler' comments > - Make naming of struct i2c_client parameter consistent > - Remove struct ntxec_info > - Rework 'depends on' lines in Kconfig, hard-depend on I2C, select REGMAP_I2C and > MFD_CORE > - Register subdevices via mfd_cells > - Move 8-bit register conversion to ntxec.h > > v2: > - https://lore.kernel.org/lkml/20200905133230.1014581-4-j.neuschaefer@gmx.net/ > - Add a description of the device to the patch text > - Unify spelling as 'Netronix embedded controller'. > 'Netronix' is the proper name of the manufacturer, but 'embedded controller' > is just a label that I have assigned to the device. > - Switch to regmap, avoid regmap use in poweroff and reboot handlers. > Inspired by cf84dc0bb40f4 ("mfd: rn5t618: Make restart handler atomic safe") > - Use a list of known-working firmware versions instead of checking for a > known-incompatible version > - Prefix registers with NTXEC_REG_ > - Define register values as constants > - Various style cleanups as suggested by Lee Jones > - Don't align = signs in struct initializers [Uwe Kleine-König] > - Don't use dev_dbg for an error message > - Explain sleep in poweroff handler > - Remove (struct ntxec).client > - Switch to .probe_new in i2c driver > - Add .remove callback > - Make CONFIG_MFD_NTXEC a tristate option > --- > drivers/mfd/Kconfig | 11 ++ > drivers/mfd/Makefile | 1 + > drivers/mfd/ntxec.c | 216 ++++++++++++++++++++++++++++++++++++++ > include/linux/mfd/ntxec.h | 34 ++++++ > 4 files changed, 262 insertions(+) > create mode 100644 drivers/mfd/ntxec.c > create mode 100644 include/linux/mfd/ntxec.h > > diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig > index 8b99a13669bfc..d96751f884dc6 100644 > --- a/drivers/mfd/Kconfig > +++ b/drivers/mfd/Kconfig > @@ -990,6 +990,17 @@ config MFD_VIPERBOARD > You need to select the mfd cell drivers separately. > The drivers do not support all features the board exposes. > > +config MFD_NTXEC > + tristate "Netronix embedded controller (EC)" > + depends on OF || COMPILE_TEST > + depends on I2C > + select REGMAP_I2C > + select MFD_CORE > + help > + Say yes here if you want to support the embedded controller found in > + certain e-book readers designed by the original design manufacturer > + Netronix. > + > config MFD_RETU > tristate "Nokia Retu and Tahvo multi-function device" > select MFD_CORE > diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile > index 1780019d24748..815c99b84019e 100644 > --- a/drivers/mfd/Makefile > +++ b/drivers/mfd/Makefile > @@ -218,6 +218,7 @@ obj-$(CONFIG_MFD_INTEL_MSIC) += intel_msic.o > obj-$(CONFIG_MFD_INTEL_PMC_BXT) += intel_pmc_bxt.o > obj-$(CONFIG_MFD_PALMAS) += palmas.o > obj-$(CONFIG_MFD_VIPERBOARD) += viperboard.o > +obj-$(CONFIG_MFD_NTXEC) += ntxec.o > obj-$(CONFIG_MFD_RC5T583) += rc5t583.o rc5t583-irq.o > obj-$(CONFIG_MFD_RK808) += rk808.o > obj-$(CONFIG_MFD_RN5T618) += rn5t618.o > diff --git a/drivers/mfd/ntxec.c b/drivers/mfd/ntxec.c > new file mode 100644 > index 0000000000000..c1510711d7363 > --- /dev/null > +++ b/drivers/mfd/ntxec.c > @@ -0,0 +1,216 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * The Netronix embedded controller is a microcontroller found in some > + * e-book readers designed by the original design manufacturer Netronix, Inc. > + * It contains RTC, battery monitoring, system power management, and PWM > + * functionality. > + * > + * This driver implements register access, version detection, and system > + * power-off/reset. > + * > + * Copyright 2020 Jonathan Neuschäfer > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define NTXEC_REG_VERSION 0x00 > +#define NTXEC_REG_POWEROFF 0x50 > +#define NTXEC_REG_POWERKEEP 0x70 > +#define NTXEC_REG_RESET 0x90 > + > +#define NTXEC_POWEROFF_VALUE 0x0100 > +#define NTXEC_POWERKEEP_VALUE 0x0800 > +#define NTXEC_RESET_VALUE 0xff00 > + > +static struct i2c_client *poweroff_restart_client; > + > +static void ntxec_poweroff(void) > +{ > + int res; > + u8 buf[3] = { NTXEC_REG_POWEROFF }; > + struct i2c_msg msgs[] = { > + { > + .addr = poweroff_restart_client->addr, > + .flags = 0, > + .len = sizeof(buf), > + .buf = buf, > + }, > + }; > + > + put_unaligned_be16(NTXEC_POWEROFF_VALUE, buf + 1); > + > + res = i2c_transfer(poweroff_restart_client->adapter, msgs, ARRAY_SIZE(msgs)); > + if (res < 0) > + dev_warn(&poweroff_restart_client->dev, > + "Failed to power off (err = %d)\n", res); > + > + /* > + * 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) > +{ > + int res; > + u8 buf[3] = { NTXEC_REG_RESET }; > + /* > + * NOTE: The lower half of the reset value is not sent, because sending > + * it causes an I2C error. (The reset handler in the downstream driver > + * does send the full two-byte value, but doesn't check the result). > + */ > + struct i2c_msg msgs[] = { > + { > + .addr = poweroff_restart_client->addr, > + .flags = 0, > + .len = sizeof(buf) - 1, > + .buf = buf, > + }, > + }; > + > + put_unaligned_be16(NTXEC_RESET_VALUE, buf + 1); > + > + res = i2c_transfer(poweroff_restart_client->adapter, msgs, ARRAY_SIZE(msgs)); > + if (res < 0) > + dev_warn(&poweroff_restart_client->dev, > + "Failed to restart (err = %d)\n", res); > + > + return NOTIFY_DONE; > +} > + > +static struct notifier_block ntxec_restart_handler = { > + .notifier_call = ntxec_restart, > + .priority = 128, > +}; > + > +static const struct regmap_config regmap_config = { > + .name = "ntxec", > + .reg_bits = 8, > + .val_bits = 16, > + .cache_type = REGCACHE_NONE, > + .val_format_endian = REGMAP_ENDIAN_BIG, > +}; > + > +static const struct mfd_cell ntxec_subdevices[] = { > + { .name = "ntxec-rtc" }, > + { .name = "ntxec-pwm" }, > +}; > + > +static int ntxec_probe(struct i2c_client *client) > +{ > + struct ntxec *ec; > + unsigned int version; > + int res; > + > + ec = devm_kmalloc(&client->dev, sizeof(*ec), GFP_KERNEL); > + if (!ec) > + return -ENOMEM; > + > + ec->dev = &client->dev; > + > + ec->regmap = 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 = regmap_read(ec->regmap, NTXEC_REG_VERSION, &version); > + if (res < 0) { > + dev_err(ec->dev, "Failed to read firmware version number\n"); > + return res; > + } > + > + /* Bail out if we encounter an unknown firmware version */ > + switch (version) { > + case 0xd726: /* found in Kobo Aura */ No magic numbers. Please submit a subsequent patch to define this. > + break; > + default: > + dev_err(ec->dev, > + "Netronix embedded controller version %04x is not supported.\n", > + version); > + return -ENODEV; > + } Applied, thanks. -- Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog