[03/12] power: reset: Add TI-SCI reboot driver

Message ID 20240131221957.213717-4-afd@ti.com
State New
Headers
Series Add TI-SCI reboot driver |

Commit Message

Andrew Davis Jan. 31, 2024, 10:19 p.m. UTC
  This reboot driver calls into firmware using TI-SCI to reboot the system.
We register the handler with low priority as we want PSCI to remain the
main way these devices are rebooted. This driver acts as a fallback if
PSCI is not able to reboot the system.

Signed-off-by: Andrew Davis <afd@ti.com>
---
 MAINTAINERS                         |  1 +
 drivers/power/reset/Kconfig         |  7 ++++
 drivers/power/reset/Makefile        |  1 +
 drivers/power/reset/ti-sci-reboot.c | 63 +++++++++++++++++++++++++++++
 4 files changed, 72 insertions(+)
 create mode 100644 drivers/power/reset/ti-sci-reboot.c
  

Comments

Nishanth Menon Feb. 1, 2024, 9:15 p.m. UTC | #1
On 16:19-20240131, Andrew Davis wrote:
> This reboot driver calls into firmware using TI-SCI to reboot the system.
> We register the handler with low priority as we want PSCI to remain the
> main way these devices are rebooted. This driver acts as a fallback if
> PSCI is not able to reboot the system.
> 
> Signed-off-by: Andrew Davis <afd@ti.com>
> ---
>  MAINTAINERS                         |  1 +
>  drivers/power/reset/Kconfig         |  7 ++++
>  drivers/power/reset/Makefile        |  1 +
>  drivers/power/reset/ti-sci-reboot.c | 63 +++++++++++++++++++++++++++++
>  4 files changed, 72 insertions(+)
>  create mode 100644 drivers/power/reset/ti-sci-reboot.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 45983bb174fe4..ee67ea497fc56 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -21758,6 +21758,7 @@ F:	drivers/clk/keystone/sci-clk.c
>  F:	drivers/firmware/ti_sci*
>  F:	drivers/irqchip/irq-ti-sci-inta.c
>  F:	drivers/irqchip/irq-ti-sci-intr.c
> +F:	drivers/power/reset/ti-sci-reboot.c
>  F:	drivers/reset/reset-ti-sci.c
>  F:	drivers/soc/ti/ti_sci_inta_msi.c
>  F:	drivers/pmdomain/ti/ti_sci_pm_domains.c
> diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
> index fece990af4a75..d3e91e54cae24 100644
> --- a/drivers/power/reset/Kconfig
> +++ b/drivers/power/reset/Kconfig
> @@ -205,6 +205,13 @@ config POWER_RESET_ST
>  	help
>  	  Reset support for STMicroelectronics boards.
>  
> +config POWER_RESET_TI_SCI
> +	tristate "TI System Control Interface (TI-SCI) reboot driver"
> +	depends on TI_SCI_PROTOCOL
> +	help
> +	  This enables the reboot driver support over TI System Control
> +	  Interface available on some TI's SoCs.
> +
>  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 a95d1bd275d18..881ca58a43b9c 100644
> --- a/drivers/power/reset/Makefile
> +++ b/drivers/power/reset/Makefile
> @@ -23,6 +23,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_TI_SCI) += ti-sci-reboot.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/ti-sci-reboot.c b/drivers/power/reset/ti-sci-reboot.c
> new file mode 100644
> index 0000000000000..400bd5d740f8b
> --- /dev/null
> +++ b/drivers/power/reset/ti-sci-reboot.c
> @@ -0,0 +1,63 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Texas Instrument's System Control Interface (TI-SCI) reboot driver
> + *
> + * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
> + *	Andrew Davis <afd@ti.com>
> + */
> +
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/reboot.h>
> +
> +#include <linux/soc/ti/ti_sci_protocol.h>
> +
> +static int ti_sci_reboot_handler(struct sys_off_data *data)
> +{
> +	const struct ti_sci_handle *sci = data->cb_data;
> +	const struct ti_sci_core_ops *core_ops = &sci->ops.core_ops;
> +
> +	core_ops->reboot_device(sci);
> +
> +	return NOTIFY_DONE;
> +}
> +
> +static int ti_sci_reboot_probe(struct platform_device *pdev)
> +{
> +	const struct ti_sci_handle *sci;
> +	int err;
> +
> +	sci = devm_ti_sci_get_handle(&pdev->dev);
> +	if (IS_ERR(sci))
> +		return PTR_ERR(sci);
> +
> +	err = devm_register_sys_off_handler(&pdev->dev,
> +					    SYS_OFF_MODE_RESTART,
> +					    SYS_OFF_PRIO_LOW,
> +					    ti_sci_reboot_handler,
> +					    (void *)sci);
> +	if (err)
> +		return dev_err_probe(&pdev->dev, err, "Cannot register restart handler\n");
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id ti_sci_reboot_of_match[] = {
> +	{ .compatible = "ti,sci-reboot", },
> +	{ /* sentinel */ },
> +};
> +MODULE_DEVICE_TABLE(of, ti_sci_reboot_of_match);
> +
> +static struct platform_driver ti_sci_reboot_driver = {
> +	.probe = ti_sci_reboot_probe,
> +	.driver = {
> +		.name = "ti-sci-reboot",
> +		.of_match_table = ti_sci_reboot_of_match,
> +	},
> +};
> +module_platform_driver(ti_sci_reboot_driver);
> +
> +MODULE_AUTHOR("Andrew Davis <afd@ti.com>");
> +MODULE_DESCRIPTION("TI System Control Interface (TI SCI) Reboot driver");
> +MODULE_LICENSE("GPL");
> -- 
> 2.39.2

Will assume the patch to go via Sebastien. Will be good for the dts to
go via SoC tree. So hoping Sebastien will just pick the driver and
bindings.

Reviewed-by: Nishanth Menon <nm@ti.com>
  
Sebastian Reichel Feb. 2, 2024, 5:04 p.m. UTC | #2
Hi,

On Thu, Feb 01, 2024 at 03:15:34PM -0600, Nishanth Menon wrote:
> On 16:19-20240131, Andrew Davis wrote:
> > This reboot driver calls into firmware using TI-SCI to reboot the system.
> > We register the handler with low priority as we want PSCI to remain the
> > main way these devices are rebooted. This driver acts as a fallback if
> > PSCI is not able to reboot the system.
> > 
> > Signed-off-by: Andrew Davis <afd@ti.com>
> > ---
> >  MAINTAINERS                         |  1 +
> >  drivers/power/reset/Kconfig         |  7 ++++
> >  drivers/power/reset/Makefile        |  1 +
> >  drivers/power/reset/ti-sci-reboot.c | 63 +++++++++++++++++++++++++++++
> >  4 files changed, 72 insertions(+)
> >  create mode 100644 drivers/power/reset/ti-sci-reboot.c
> > 
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 45983bb174fe4..ee67ea497fc56 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -21758,6 +21758,7 @@ F:	drivers/clk/keystone/sci-clk.c
> >  F:	drivers/firmware/ti_sci*
> >  F:	drivers/irqchip/irq-ti-sci-inta.c
> >  F:	drivers/irqchip/irq-ti-sci-intr.c
> > +F:	drivers/power/reset/ti-sci-reboot.c
> >  F:	drivers/reset/reset-ti-sci.c
> >  F:	drivers/soc/ti/ti_sci_inta_msi.c
> >  F:	drivers/pmdomain/ti/ti_sci_pm_domains.c
> > diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
> > index fece990af4a75..d3e91e54cae24 100644
> > --- a/drivers/power/reset/Kconfig
> > +++ b/drivers/power/reset/Kconfig
> > @@ -205,6 +205,13 @@ config POWER_RESET_ST
> >  	help
> >  	  Reset support for STMicroelectronics boards.
> >  
> > +config POWER_RESET_TI_SCI
> > +	tristate "TI System Control Interface (TI-SCI) reboot driver"
> > +	depends on TI_SCI_PROTOCOL
> > +	help
> > +	  This enables the reboot driver support over TI System Control
> > +	  Interface available on some TI's SoCs.
> > +
> >  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 a95d1bd275d18..881ca58a43b9c 100644
> > --- a/drivers/power/reset/Makefile
> > +++ b/drivers/power/reset/Makefile
> > @@ -23,6 +23,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_TI_SCI) += ti-sci-reboot.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/ti-sci-reboot.c b/drivers/power/reset/ti-sci-reboot.c
> > new file mode 100644
> > index 0000000000000..400bd5d740f8b
> > --- /dev/null
> > +++ b/drivers/power/reset/ti-sci-reboot.c
> > @@ -0,0 +1,63 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * Texas Instrument's System Control Interface (TI-SCI) reboot driver
> > + *
> > + * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
> > + *	Andrew Davis <afd@ti.com>
> > + */
> > +
> > +#include <linux/mod_devicetable.h>
> > +#include <linux/module.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/reboot.h>
> > +
> > +#include <linux/soc/ti/ti_sci_protocol.h>
> > +
> > +static int ti_sci_reboot_handler(struct sys_off_data *data)
> > +{
> > +	const struct ti_sci_handle *sci = data->cb_data;
> > +	const struct ti_sci_core_ops *core_ops = &sci->ops.core_ops;
> > +
> > +	core_ops->reboot_device(sci);
> > +
> > +	return NOTIFY_DONE;
> > +}
> > +
> > +static int ti_sci_reboot_probe(struct platform_device *pdev)
> > +{
> > +	const struct ti_sci_handle *sci;
> > +	int err;
> > +
> > +	sci = devm_ti_sci_get_handle(&pdev->dev);
> > +	if (IS_ERR(sci))
> > +		return PTR_ERR(sci);
> > +
> > +	err = devm_register_sys_off_handler(&pdev->dev,
> > +					    SYS_OFF_MODE_RESTART,
> > +					    SYS_OFF_PRIO_LOW,
> > +					    ti_sci_reboot_handler,
> > +					    (void *)sci);
> > +	if (err)
> > +		return dev_err_probe(&pdev->dev, err, "Cannot register restart handler\n");
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct of_device_id ti_sci_reboot_of_match[] = {
> > +	{ .compatible = "ti,sci-reboot", },
> > +	{ /* sentinel */ },
> > +};
> > +MODULE_DEVICE_TABLE(of, ti_sci_reboot_of_match);
> > +
> > +static struct platform_driver ti_sci_reboot_driver = {
> > +	.probe = ti_sci_reboot_probe,
> > +	.driver = {
> > +		.name = "ti-sci-reboot",
> > +		.of_match_table = ti_sci_reboot_of_match,
> > +	},
> > +};
> > +module_platform_driver(ti_sci_reboot_driver);
> > +
> > +MODULE_AUTHOR("Andrew Davis <afd@ti.com>");
> > +MODULE_DESCRIPTION("TI System Control Interface (TI SCI) Reboot driver");
> > +MODULE_LICENSE("GPL");
> > -- 
> > 2.39.2
> 
> Will assume the patch to go via Sebastien. Will be good for the dts to
> go via SoC tree. So hoping Sebastien will just pick the driver and
> bindings.

I will wait for the DT binding discussion to have settled. The
driver itself LGTM.

-- Sebastian
  

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index 45983bb174fe4..ee67ea497fc56 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -21758,6 +21758,7 @@  F:	drivers/clk/keystone/sci-clk.c
 F:	drivers/firmware/ti_sci*
 F:	drivers/irqchip/irq-ti-sci-inta.c
 F:	drivers/irqchip/irq-ti-sci-intr.c
+F:	drivers/power/reset/ti-sci-reboot.c
 F:	drivers/reset/reset-ti-sci.c
 F:	drivers/soc/ti/ti_sci_inta_msi.c
 F:	drivers/pmdomain/ti/ti_sci_pm_domains.c
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index fece990af4a75..d3e91e54cae24 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -205,6 +205,13 @@  config POWER_RESET_ST
 	help
 	  Reset support for STMicroelectronics boards.
 
+config POWER_RESET_TI_SCI
+	tristate "TI System Control Interface (TI-SCI) reboot driver"
+	depends on TI_SCI_PROTOCOL
+	help
+	  This enables the reboot driver support over TI System Control
+	  Interface available on some TI's SoCs.
+
 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 a95d1bd275d18..881ca58a43b9c 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -23,6 +23,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_TI_SCI) += ti-sci-reboot.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/ti-sci-reboot.c b/drivers/power/reset/ti-sci-reboot.c
new file mode 100644
index 0000000000000..400bd5d740f8b
--- /dev/null
+++ b/drivers/power/reset/ti-sci-reboot.c
@@ -0,0 +1,63 @@ 
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Texas Instrument's System Control Interface (TI-SCI) reboot driver
+ *
+ * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
+ *	Andrew Davis <afd@ti.com>
+ */
+
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/reboot.h>
+
+#include <linux/soc/ti/ti_sci_protocol.h>
+
+static int ti_sci_reboot_handler(struct sys_off_data *data)
+{
+	const struct ti_sci_handle *sci = data->cb_data;
+	const struct ti_sci_core_ops *core_ops = &sci->ops.core_ops;
+
+	core_ops->reboot_device(sci);
+
+	return NOTIFY_DONE;
+}
+
+static int ti_sci_reboot_probe(struct platform_device *pdev)
+{
+	const struct ti_sci_handle *sci;
+	int err;
+
+	sci = devm_ti_sci_get_handle(&pdev->dev);
+	if (IS_ERR(sci))
+		return PTR_ERR(sci);
+
+	err = devm_register_sys_off_handler(&pdev->dev,
+					    SYS_OFF_MODE_RESTART,
+					    SYS_OFF_PRIO_LOW,
+					    ti_sci_reboot_handler,
+					    (void *)sci);
+	if (err)
+		return dev_err_probe(&pdev->dev, err, "Cannot register restart handler\n");
+
+	return 0;
+}
+
+static const struct of_device_id ti_sci_reboot_of_match[] = {
+	{ .compatible = "ti,sci-reboot", },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, ti_sci_reboot_of_match);
+
+static struct platform_driver ti_sci_reboot_driver = {
+	.probe = ti_sci_reboot_probe,
+	.driver = {
+		.name = "ti-sci-reboot",
+		.of_match_table = ti_sci_reboot_of_match,
+	},
+};
+module_platform_driver(ti_sci_reboot_driver);
+
+MODULE_AUTHOR("Andrew Davis <afd@ti.com>");
+MODULE_DESCRIPTION("TI System Control Interface (TI SCI) Reboot driver");
+MODULE_LICENSE("GPL");