From nobody Sun Feb 8 17:48:35 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D0716FB0 for ; Fri, 19 Apr 2024 08:31:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713515490; cv=none; b=R9R8spSPFXPaNX/bffhjjCC+Akqj7/Zj2DQSBXYO3JZ89iEsc+JGIna6DK3TcZLh0nq233FT9cesmg2TmJQtf69PPoiqRHWP5ZFsoNJLsGMWre0pb9NWiWVdvMkALDOxTL9HiP89GHV3Q2pYCy+Q3eFYfAbASzfsdKDiPUO400o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713515490; c=relaxed/simple; bh=qxoD5g4buTdC/BH/OQ7LEfEn3adg8fa4/j3TGO7/xjg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iF4JWjumpBO4hhcDwIqDK46oQ1egYAWxWedSgnC+IZj8y5w7Y/xChkI3bZooRWZZMi0NBCNEXLWVhgOHNJOoKenlGFMfqVMbfprrd16B2xtE8rad8QvsocQY4of+rQUKTxEniZU+Jq8FJ/I3fwWG7WsmctgWZPJdPlazPbYqW6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rxjeQ-0006i8-Rf; Fri, 19 Apr 2024 10:31:18 +0200 Received: from [2a0a:edc0:0:1101:1d::39] (helo=dude03.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rxjeQ-00D7hB-FI; Fri, 19 Apr 2024 10:31:18 +0200 Received: from has by dude03.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rxjeQ-00DyIN-15; Fri, 19 Apr 2024 10:31:18 +0200 From: Holger Assmann To: lgirdwood@gmail.com, broonie@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, yibin.gong@nxp.com Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Holger Assmann Subject: [PATCH 1/2] regulator: pca9450: enable restart handler for I2C operation Date: Fri, 19 Apr 2024 10:31:03 +0200 Message-Id: <20240419083104.3329252-2-h.assmann@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240419083104.3329252-1-h.assmann@pengutronix.de> References: <20240419083104.3329252-1-h.assmann@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: has@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The NXP PCA9450 can perform various kinds of power cycles when triggered by I2C-command. We therefore make this functionality accessible by introducing a respective restart handler. It will be used after a priority has been defined within the devicetree. Signed-off-by: Holger Assmann --- drivers/regulator/pca9450-regulator.c | 54 +++++++++++++++++++++++++++ include/linux/regulator/pca9450.h | 7 ++++ 2 files changed, 61 insertions(+) diff --git a/drivers/regulator/pca9450-regulator.c b/drivers/regulator/pca9= 450-regulator.c index 2ab365d2749f9..e623323599964 100644 --- a/drivers/regulator/pca9450-regulator.c +++ b/drivers/regulator/pca9450-regulator.c @@ -16,6 +16,7 @@ #include #include #include +#include =20 struct pc9450_dvs_config { unsigned int run_reg; /* dvs0 */ @@ -33,6 +34,7 @@ struct pca9450 { struct device *dev; struct regmap *regmap; struct gpio_desc *sd_vsel_gpio; + struct notifier_block restart_handler; enum pca9450_chip_type type; unsigned int rcnt; int irq; @@ -700,6 +702,34 @@ static irqreturn_t pca9450_irq_handler(int irq, void *= data) return IRQ_HANDLED; } =20 +static int pca9450_restart(struct notifier_block *nb, + unsigned long mode, void *cmd) +{ + struct pca9450 *pmic =3D container_of(nb, struct pca9450, + restart_handler); + struct i2c_client *client =3D container_of(pmic->dev, + struct i2c_client, dev); + int ret =3D 0; + u32 rtype; + + switch (mode) { + case REBOOT_WARM: + /* Warm reset (Toggle POR_B for 20 ms) */ + rtype =3D 0x35; + break; + default: + /* Cold reset (Power recycle all regulators) */ + rtype =3D 0x64; + } + + ret =3D i2c_smbus_write_byte_data(client, PCA9450_REG_SWRST, rtype); + if (ret < 0) + dev_alert(pmic->dev, "Failed to shutdown (err =3D %d)\n", ret); + + mdelay(500); + return NOTIFY_DONE; +} + static int pca9450_i2c_probe(struct i2c_client *i2c) { enum pca9450_chip_type type =3D (unsigned int)(uintptr_t) @@ -845,12 +875,35 @@ static int pca9450_i2c_probe(struct i2c_client *i2c) return PTR_ERR(pca9450->sd_vsel_gpio); } =20 + /* Register I2C restart handler if one is defined by device tree */ + if (!of_property_read_u32(i2c->dev.of_node, "priority", + &pca9450->restart_handler.priority)) { + pca9450->restart_handler.notifier_call =3D pca9450_restart; + + ret =3D register_restart_handler(&pca9450->restart_handler); + if (ret) + return dev_err_probe(&i2c->dev, ret, + "cannot register restart handler.\n"); + else + dev_info(&i2c->dev, + "registered restart handler with priority %d.\n", + pca9450->restart_handler.priority); + } + dev_info(&i2c->dev, "%s probed.\n", type =3D=3D PCA9450_TYPE_PCA9450A ? "pca9450a" : "pca9450bc"); =20 return 0; } =20 +static void pca9450_i2c_remove(struct i2c_client *i2c) +{ + struct pca9450 *pca9450 =3D dev_get_drvdata(&i2c->dev); + + if (pca9450->restart_handler.notifier_call) + unregister_restart_handler(&pca9450->restart_handler); +} + static const struct of_device_id pca9450_of_match[] =3D { { .compatible =3D "nxp,pca9450a", @@ -875,6 +928,7 @@ static struct i2c_driver pca9450_i2c_driver =3D { .of_match_table =3D pca9450_of_match, }, .probe =3D pca9450_i2c_probe, + .remove =3D pca9450_i2c_remove, }; =20 module_i2c_driver(pca9450_i2c_driver); diff --git a/include/linux/regulator/pca9450.h b/include/linux/regulator/pc= a9450.h index 505c908dbb817..2ee38bab23402 100644 --- a/include/linux/regulator/pca9450.h +++ b/include/linux/regulator/pca9450.h @@ -226,6 +226,13 @@ enum { #define WDOG_B_CFG_COLD_LDO12 0x80 #define WDOG_B_CFG_COLD 0xC0 =20 +/* PCA9450_REG_SWRST bits */ +#define SW_RST_NONE 0x00 +#define SW_RST_DEFAULTS 0x05 +#define SW_RST_COLD_LDO12_CLK32 0x14 +#define SW_RST_WARM 0x35 +#define SW_RST_COLD 0x64 + /* PCA9450_REG_CONFIG2 bits */ #define I2C_LT_MASK 0x03 #define I2C_LT_FORCE_DISABLE 0x00 --=20 2.39.2 From nobody Sun Feb 8 17:48:35 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D0A0F507 for ; Fri, 19 Apr 2024 08:31:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713515490; cv=none; b=HJ/ayUW/A1JIVm8JJp4C/PXBFGr90O46kODSo/Dz1LJ9nmRMkXPmdSEZl0mh77OzRxSeVGYf9rcxi0MtteOMFeYwx9eEutqAIZnitIG7i5rNV4Qxk9mcoPRyBCkYE+OtEoPt7VnEEsrgqUqzgPqZbGOkrUTFwIFRqAbRLCmQ0PI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713515490; c=relaxed/simple; bh=aLCYOY9uDoJrqIV3AUBSqW/EEWxfcdmxTZoQdRkDNR4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JaeBY/2vgYb17hieHTrfe3UlWL1qIhtDddFIbQkMXv+oJy01Q8aelzhPlxt5HH07GdFabmitJEQWkmkzZVQIN1P5DYn3h/irRcx3phXONsdi3yVvbTeZbKQQZP79Q+A81ltfvoo9TriFeHDl+0uHc2fp5PW+0BA9wXkyWg1IB+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rxjeR-0006iN-HF; Fri, 19 Apr 2024 10:31:19 +0200 Received: from [2a0a:edc0:0:1101:1d::39] (helo=dude03.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rxjeR-00D7hF-43; Fri, 19 Apr 2024 10:31:19 +0200 Received: from has by dude03.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rxjeQ-00DyIU-3B; Fri, 19 Apr 2024 10:31:19 +0200 From: Holger Assmann To: lgirdwood@gmail.com, broonie@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, yibin.gong@nxp.com Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Holger Assmann Subject: [PATCH 2/2] dt-bindings: regulator: pca9450: add restart handler priority Date: Fri, 19 Apr 2024 10:31:04 +0200 Message-Id: <20240419083104.3329252-3-h.assmann@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240419083104.3329252-1-h.assmann@pengutronix.de> References: <20240419083104.3329252-1-h.assmann@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: has@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This is an optional property. If set, the pca9450 will be registered as a reset device with the chosen priority level. Signed-off-by: Holger Assmann --- .../devicetree/bindings/regulator/nxp,pca9450-regulator.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/regulator/nxp,pca9450-regula= tor.yaml b/Documentation/devicetree/bindings/regulator/nxp,pca9450-regulato= r.yaml index 3d469b8e97748..7cc2d6636cf52 100644 --- a/Documentation/devicetree/bindings/regulator/nxp,pca9450-regulator.yaml +++ b/Documentation/devicetree/bindings/regulator/nxp,pca9450-regulator.yaml @@ -35,6 +35,9 @@ properties: interrupts: maxItems: 1 =20 + priority: + $ref: /schemas/power/reset/restart-handler.yaml# + regulators: type: object description: | --=20 2.39.2