diff mbox series

[SRU,F:linux-bluefield,v1,3/3] UBUNTU: SAUCE: pwr-mlxbf: support graceful reboot instead of soft reset

Message ID 20231030200547.6517-4-asmaa@nvidia.com
State New
Headers show
Series UBUNTU: SAUCE: pwr-mlxbf: Several bug fixes for focal | expand

Commit Message

Asmaa Mnebhi Oct. 30, 2023, 8:05 p.m. UTC
BugLink: https://bugs.launchpad.net/bugs/2041996

There is a new feature request to replace the soft reset with a
graceful reboot.
We will use acpi events triggered by the irq in the pwr-mlxbf file
to trigger the graceful reboot.

Signed-off-by: Asmaa Mnebhi <asmaa@nvidia.com>
---
 drivers/power/reset/pwr-mlxbf.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/drivers/power/reset/pwr-mlxbf.c b/drivers/power/reset/pwr-mlxbf.c
index 683bf38ba582..813eb98a2b74 100644
--- a/drivers/power/reset/pwr-mlxbf.c
+++ b/drivers/power/reset/pwr-mlxbf.c
@@ -15,14 +15,20 @@ 
 #include <linux/reboot.h>
 #include <linux/types.h>
 
-#define DRV_VERSION "1.1"
+#define DRV_VERSION "1.2"
 
 struct pwr_mlxbf {
-	struct work_struct send_work;
+	struct work_struct reboot_work;
+	struct work_struct shutdown_work;
 	const char *hid;
 };
 
-static void pwr_mlxbf_send_work(struct work_struct *work)
+static void pwr_mlxbf_reboot_work(struct work_struct *work)
+{
+	acpi_bus_generate_netlink_event("button/reboot.*", "Reboot Button", 0x80, 1);
+}
+
+static void pwr_mlxbf_shutdown_work(struct work_struct *work)
 {
 	acpi_bus_generate_netlink_event("button/power.*", "Power Button", 0x80, 1);
 }
@@ -34,16 +40,15 @@  static irqreturn_t pwr_mlxbf_irq(int irq, void *ptr)
 	struct pwr_mlxbf *priv = ptr;
 
 	if (!strncmp(priv->hid, rst_pwr_hid, 8))
-		emergency_restart();
+		schedule_work(&priv->reboot_work);
 
 	if (!strncmp(priv->hid, low_pwr_hid, 8))
-		schedule_work(&priv->send_work);
+		schedule_work(&priv->shutdown_work);
 
 	return IRQ_HANDLED;
 }
 
-static int
-pwr_mlxbf_probe(struct platform_device *pdev)
+static int pwr_mlxbf_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct acpi_device *adev;
@@ -70,7 +75,8 @@  pwr_mlxbf_probe(struct platform_device *pdev)
 		return -EPROBE_DEFER;
 	}
 
-	INIT_WORK(&priv->send_work, pwr_mlxbf_send_work);
+	INIT_WORK(&priv->shutdown_work, pwr_mlxbf_shutdown_work);
+	INIT_WORK(&priv->reboot_work, pwr_mlxbf_reboot_work);
 
 	platform_set_drvdata(pdev, priv);
 
@@ -86,7 +92,8 @@  pwr_mlxbf_remove(struct platform_device *pdev)
 {
 	struct pwr_mlxbf *priv = platform_get_drvdata(pdev);
 
-	flush_work(&priv->send_work);
+	flush_work(&priv->shutdown_work);
+	flush_work(&priv->reboot_work);
 
 	return 0;
 }