Devicetree
 help / color / mirror / Atom feed
* [PATCH v1 0/2] power: reset: Add Toradex Embedded Controller
@ 2025-04-07 11:49 Francesco Dolcini
  2025-04-07 11:49 ` [PATCH v1 1/2] dt-bindings: firmware: add toradex,smarc-ec Francesco Dolcini
  2025-04-07 11:49 ` [PATCH v1 2/2] power: reset: add Toradex Embedded Controller Francesco Dolcini
  0 siblings, 2 replies; 5+ messages in thread
From: Francesco Dolcini @ 2025-04-07 11:49 UTC (permalink / raw)
  To: Emanuele Ghidoli, Francesco Dolcini, Sebastian Reichel,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: Francesco Dolcini, Emanuele Ghidoli, linux-pm, devicetree,
	linux-kernel

From: Francesco Dolcini <francesco.dolcini@toradex.com>

This series adds support for the Toradex Embedded Controller, currently used on
Toradex SMARC iMX95 and iMX8MP boards.

The EC provides board power-off, reset and GPIO expander functionalities.

We did send an RFC before,
https://lore.kernel.org/all/20250313144331.70591-1-francesco@dolcini.it/, with
reference to the discussion about implementing this as a MFD, we decided to
just have a power/reset driver, given we do not see a need to expand the
functionalities we already have.

Emanuele Ghidoli (2):
  dt-bindings: firmware: add toradex,smarc-ec
  power: reset: add Toradex Embedded Controller

 .../power/reset/toradex,smarc-ec.yaml         |  52 ++++++
 MAINTAINERS                                   |   7 +
 drivers/power/reset/Kconfig                   |  13 ++
 drivers/power/reset/Makefile                  |   1 +
 drivers/power/reset/tdx-ec-poweroff.c         | 150 ++++++++++++++++++
 5 files changed, 223 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/reset/toradex,smarc-ec.yaml
 create mode 100644 drivers/power/reset/tdx-ec-poweroff.c

-- 
2.39.5


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v1 1/2] dt-bindings: firmware: add toradex,smarc-ec
  2025-04-07 11:49 [PATCH v1 0/2] power: reset: Add Toradex Embedded Controller Francesco Dolcini
@ 2025-04-07 11:49 ` Francesco Dolcini
  2025-04-07 16:12   ` Conor Dooley
  2025-04-07 16:14   ` Conor Dooley
  2025-04-07 11:49 ` [PATCH v1 2/2] power: reset: add Toradex Embedded Controller Francesco Dolcini
  1 sibling, 2 replies; 5+ messages in thread
From: Francesco Dolcini @ 2025-04-07 11:49 UTC (permalink / raw)
  To: Emanuele Ghidoli, Francesco Dolcini, Sebastian Reichel,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: Emanuele Ghidoli, Francesco Dolcini, linux-pm, devicetree,
	linux-kernel

From: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>

The Toradex Embedded Controller provides system power-off and restart
functionalities.
The two variants, SMARC iMX95 and SMARC iMX8P, have a compatible
I2C interface.
Besides this, different compatible values are defined to allow for
future implementation differences.

Signed-off-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
---
 .../power/reset/toradex,smarc-ec.yaml         | 52 +++++++++++++++++++
 MAINTAINERS                                   |  6 +++
 2 files changed, 58 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/reset/toradex,smarc-ec.yaml

diff --git a/Documentation/devicetree/bindings/power/reset/toradex,smarc-ec.yaml b/Documentation/devicetree/bindings/power/reset/toradex,smarc-ec.yaml
new file mode 100644
index 000000000000..ffcd5f2c2bf6
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/reset/toradex,smarc-ec.yaml
@@ -0,0 +1,52 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/reset/toradex,smarc-ec.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Toradex Embedded Controller
+
+maintainers:
+  - Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
+  - Francesco Dolcini <francesco.dolcini@toradex.com>
+
+description: |
+  The Toradex Embedded Controller (EC) is used on Toradex SMARC modules,
+  primarily to manage power and reset functionalities.
+
+  The EC provides the following functions:
+    - Reads the SMARC POWER_BTN# and RESET_IN# signals and controls the PMIC accordingly.
+    - Controls the SoC boot mode signals based on the SMARC BOOT_SEL# and FORCE_RECOV# inputs.
+    - Manages the CARRIER_STDBY# signal in response to relevant SoC signals.
+
+  The EC runs a small firmware, factory programmed into its internal flash, and communicates over I2C.
+  It allows software to control power-off and reset functionalities of the module.
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - toradex,smarc-imx95-ec
+          - toradex,smarc-imx8mp-ec
+      - const: toradex,smarc-ec
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        reset-controller@28 {
+            compatible = "toradex,smarc-imx95-ec", "toradex,smarc-ec";
+            reg = <0x28>;
+        };
+    };
diff --git a/MAINTAINERS b/MAINTAINERS
index 96b827049501..e6903d2bb741 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -24406,6 +24406,12 @@ L:	platform-driver-x86@vger.kernel.org
 S:	Maintained
 F:	drivers/platform/x86/topstar-laptop.c
 
+TORADEX EMBEDDED CONTROLLER DRIVER
+M:	Emanuele Ghidoli <ghidoliemanuele@gmail.com>
+M:	Francesco Dolcini <francesco@dolcini.it>
+S:	Maintained
+F:	Documentation/devicetree/bindings/power/reset/toradex,smarc-ec.yaml
+
 TORTURE-TEST MODULES
 M:	Davidlohr Bueso <dave@stgolabs.net>
 M:	"Paul E. McKenney" <paulmck@kernel.org>
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 2/2] power: reset: add Toradex Embedded Controller
  2025-04-07 11:49 [PATCH v1 0/2] power: reset: Add Toradex Embedded Controller Francesco Dolcini
  2025-04-07 11:49 ` [PATCH v1 1/2] dt-bindings: firmware: add toradex,smarc-ec Francesco Dolcini
@ 2025-04-07 11:49 ` Francesco Dolcini
  1 sibling, 0 replies; 5+ messages in thread
From: Francesco Dolcini @ 2025-04-07 11:49 UTC (permalink / raw)
  To: Emanuele Ghidoli, Francesco Dolcini, Sebastian Reichel,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: Emanuele Ghidoli, Francesco Dolcini, linux-pm, devicetree,
	linux-kernel

From: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>

Toradex SMARC iMX8MP and SMARC iMX95 SoM modules use a small Embedded
Controller (EC) to manage power and reset functions and related SMARC
signals.

This driver implements power-off and reboot handlers, communicating with
the EC via I2C to issue the appropriate power management commands.

During probe, the driver logs the Embedded Controller ID (unique ID for
each SMARC board supported) in hex format along with the firmware version.

Signed-off-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
---
 MAINTAINERS                           |   1 +
 drivers/power/reset/Kconfig           |  13 +++
 drivers/power/reset/Makefile          |   1 +
 drivers/power/reset/tdx-ec-poweroff.c | 150 ++++++++++++++++++++++++++
 4 files changed, 165 insertions(+)
 create mode 100644 drivers/power/reset/tdx-ec-poweroff.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e6903d2bb741..c6966ced8cea 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -24411,6 +24411,7 @@ M:	Emanuele Ghidoli <ghidoliemanuele@gmail.com>
 M:	Francesco Dolcini <francesco@dolcini.it>
 S:	Maintained
 F:	Documentation/devicetree/bindings/power/reset/toradex,smarc-ec.yaml
+F:	drivers/power/reset/tdx-ec-poweroff.c
 
 TORTURE-TEST MODULES
 M:	Davidlohr Bueso <dave@stgolabs.net>
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index 60bf0ca64cf3..e71f0af4e378 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -216,6 +216,19 @@ config POWER_RESET_ST
 	help
 	  Reset support for STMicroelectronics boards.
 
+config POWER_RESET_TORADEX_EC
+	tristate "Toradex Embedded Controller power-off and reset driver"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  This driver supports power-off and reset for SMARC Toradex SoMs,
+	  for example the SMARC iMX8MP and SMARC iMX95, using Toradex
+	  Embedded Controller (EC).
+
+	  Say Y here if you have a Toradex SMARC SoM.
+
+	  If unsure, say N.
+
 config POWER_RESET_TPS65086
 	bool "TPS65086 restart driver"
 	depends on MFD_TPS65086
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index 10782d32e1da..1b9b63a1a873 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o
 obj-$(CONFIG_POWER_RESET_REGULATOR) += regulator-poweroff.o
 obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o
 obj-$(CONFIG_POWER_RESET_ST) += st-poweroff.o
+obj-$(CONFIG_POWER_RESET_TORADEX_EC) += tdx-ec-poweroff.o
 obj-$(CONFIG_POWER_RESET_TPS65086) += tps65086-restart.o
 obj-$(CONFIG_POWER_RESET_VERSATILE) += arm-versatile-reboot.o
 obj-$(CONFIG_POWER_RESET_VEXPRESS) += vexpress-poweroff.o
diff --git a/drivers/power/reset/tdx-ec-poweroff.c b/drivers/power/reset/tdx-ec-poweroff.c
new file mode 100644
index 000000000000..3302a127fce5
--- /dev/null
+++ b/drivers/power/reset/tdx-ec-poweroff.c
@@ -0,0 +1,150 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Toradex Embedded Controller driver
+ *
+ * Copyright (C) 2025 Toradex
+ *
+ * Author: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
+ */
+
+#include <linux/array_size.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/reboot.h>
+#include <linux/regmap.h>
+#include <linux/types.h>
+
+#define EC_CHIP_ID_REG                  0x00
+#define EC_CHIP_ID_SMARC_IMX95          0x11
+#define EC_CHIP_ID_SMARC_IMX8MP         0x12
+
+#define EC_VERSION_REG_MAJOR            0x01
+#define EC_VERSION_REG_MINOR            0x02
+#define EC_ID_VERSION_LEN               3
+
+#define EC_CMD_REG                      0xD0
+#define EC_CMD_POWEROFF                 0x01
+#define EC_CMD_RESET                    0x02
+
+#define EC_REG_MAX                      0xD0
+
+static const struct regmap_range volatile_ranges[] = {
+	regmap_reg_range(EC_CMD_REG, EC_CMD_REG),
+};
+
+static const struct regmap_access_table volatile_table = {
+	.yes_ranges	= volatile_ranges,
+	.n_yes_ranges	= ARRAY_SIZE(volatile_ranges),
+};
+
+static const struct regmap_range read_ranges[] = {
+	regmap_reg_range(EC_CHIP_ID_REG, EC_VERSION_REG_MINOR),
+};
+
+static const struct regmap_access_table read_table = {
+	.yes_ranges	= read_ranges,
+	.n_yes_ranges	= ARRAY_SIZE(read_ranges),
+};
+
+static const struct regmap_config regmap_config = {
+	.reg_bits	= 8,
+	.val_bits	= 8,
+	.max_register	= EC_REG_MAX,
+	.cache_type	= REGCACHE_RBTREE,
+	.rd_table	= &read_table,
+	.volatile_table = &volatile_table,
+};
+
+static int tdx_ec_cmd(struct regmap *regmap, u8 cmd)
+{
+	int err = regmap_write(regmap, EC_CMD_REG, cmd);
+
+	if (err)
+		dev_err(regmap_get_device(regmap), "Failed to send command 0x%02X: %d\n", cmd, err);
+
+	return err;
+}
+
+static int tdx_ec_power_off(struct sys_off_data *data)
+{
+	struct regmap *regmap = data->cb_data;
+	int err;
+
+	err = tdx_ec_cmd(regmap, EC_CMD_POWEROFF);
+
+	return err ? NOTIFY_BAD : NOTIFY_DONE;
+}
+
+static int tdx_ec_restart(struct sys_off_data *data)
+{
+	struct regmap *regmap = data->cb_data;
+	int err;
+
+	err = tdx_ec_cmd(regmap, EC_CMD_RESET);
+
+	return err ? NOTIFY_BAD : NOTIFY_DONE;
+}
+
+static int tdx_ec_register_power_off_restart(struct device *dev, struct regmap *regmap)
+{
+	int err;
+
+	err = devm_register_sys_off_handler(dev, SYS_OFF_MODE_RESTART,
+					    SYS_OFF_PRIO_FIRMWARE,
+					    tdx_ec_restart, regmap);
+	if (err)
+		return err;
+
+	return devm_register_sys_off_handler(dev, SYS_OFF_MODE_POWER_OFF,
+					     SYS_OFF_PRIO_FIRMWARE,
+					     tdx_ec_power_off, regmap);
+}
+
+static int tdx_ec_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	u8 reg_val[EC_ID_VERSION_LEN];
+	struct regmap *regmap;
+	int err;
+
+	regmap = devm_regmap_init_i2c(client, &regmap_config);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	err = regmap_bulk_read(regmap, EC_CHIP_ID_REG, &reg_val, EC_ID_VERSION_LEN);
+	if (err)
+		return dev_err_probe(dev, err,
+				     "Cannot read id and version registers\n");
+
+	dev_info(dev, "Toradex Embedded Controller id %x - Firmware %u.%u\n",
+		 reg_val[0], reg_val[1], reg_val[2]);
+
+	err = tdx_ec_register_power_off_restart(dev, regmap);
+	if (err)
+		return dev_err_probe(dev, err,
+				     "Cannot register system restart handler\n");
+
+	return 0;
+}
+
+static const struct of_device_id __maybe_unused of_tdx_ec_match[] = {
+	{ .compatible = "toradex,smarc-ec" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, of_tdx_ec_match);
+
+static struct i2c_driver tdx_ec_driver = {
+	.probe			= tdx_ec_probe,
+	.driver			= {
+		.name		= "toradex-smarc-ec",
+		.of_match_table = of_tdx_ec_match,
+	},
+};
+module_i2c_driver(tdx_ec_driver);
+
+MODULE_AUTHOR("Emanuele Ghidoli <emanuele.ghidoli@toradex.com>");
+MODULE_DESCRIPTION("Toradex SMARC Embedded Controller driver");
+MODULE_LICENSE("GPL");
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/2] dt-bindings: firmware: add toradex,smarc-ec
  2025-04-07 11:49 ` [PATCH v1 1/2] dt-bindings: firmware: add toradex,smarc-ec Francesco Dolcini
@ 2025-04-07 16:12   ` Conor Dooley
  2025-04-07 16:14   ` Conor Dooley
  1 sibling, 0 replies; 5+ messages in thread
From: Conor Dooley @ 2025-04-07 16:12 UTC (permalink / raw)
  To: Francesco Dolcini
  Cc: Emanuele Ghidoli, Sebastian Reichel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Emanuele Ghidoli,
	Francesco Dolcini, linux-pm, devicetree, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 612 bytes --]

On Mon, Apr 07, 2025 at 01:49:46PM +0200, Francesco Dolcini wrote:
> From: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
> 
> The Toradex Embedded Controller provides system power-off and restart
> functionalities.
> The two variants, SMARC iMX95 and SMARC iMX8P, have a compatible
> I2C interface.
> Besides this, different compatible values are defined to allow for
> future implementation differences.
> 
> Signed-off-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
> Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>

Reviewed-by: Conor Dooley <conor.dooley@microchip.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/2] dt-bindings: firmware: add toradex,smarc-ec
  2025-04-07 11:49 ` [PATCH v1 1/2] dt-bindings: firmware: add toradex,smarc-ec Francesco Dolcini
  2025-04-07 16:12   ` Conor Dooley
@ 2025-04-07 16:14   ` Conor Dooley
  1 sibling, 0 replies; 5+ messages in thread
From: Conor Dooley @ 2025-04-07 16:14 UTC (permalink / raw)
  To: Francesco Dolcini
  Cc: Emanuele Ghidoli, Sebastian Reichel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Emanuele Ghidoli,
	Francesco Dolcini, linux-pm, devicetree, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 165 bytes --]



Actually, one minor thing, $subject says "firmware" but the binding is
in the reset directory. I can see why you'd put it in either, but pick
one for both please.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-07 16:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-07 11:49 [PATCH v1 0/2] power: reset: Add Toradex Embedded Controller Francesco Dolcini
2025-04-07 11:49 ` [PATCH v1 1/2] dt-bindings: firmware: add toradex,smarc-ec Francesco Dolcini
2025-04-07 16:12   ` Conor Dooley
2025-04-07 16:14   ` Conor Dooley
2025-04-07 11:49 ` [PATCH v1 2/2] power: reset: add Toradex Embedded Controller Francesco Dolcini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox