misc: tizen-artik-reboot: support the reboot notifier
authorJaehoon Chung <jh80.chung@samsung.com>
Tue, 24 Oct 2017 09:11:11 +0000 (18:11 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 29 Jan 2019 02:25:34 +0000 (11:25 +0900)
Tizen platform needs to provide the reboot parameter.
This file is for supporting reboot notifier on Tizen platform.

Note: ALIVESCRATCH7 register should maintain the value upon rebooting.
      (ALIVESCRATCH 0~5 are already used.)

Change-Id: I512e6b2ca26c355a847435f20910be85cbf28fb2
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Junghoon Kim <jhoon20.kim@samsung.com>
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/tizen-artik-reboot.c [new file with mode: 0644]

index 4e53338..4ec5bb4 100644 (file)
@@ -556,6 +556,13 @@ config ARTIK_S3T9MF
         help
           This driver allows you can control s3t9mf for artik board.
 
+config ARTIK_TIZEN_REBOOT
+       tristate "ARTIK Tizen reboot handler"
+       depends on ARCH_S5P4418
+       default y
+       help
+         This handler sets the reboot parameter for artik Tizen.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
index fee68f9..c23558a 100644 (file)
@@ -61,3 +61,4 @@ obj-$(CONFIG_NX_SCALER)               += nx-scaler.o
 obj-$(CONFIG_ARTIK_ZB_POWER)   += artik_zb_power.o
 obj-$(CONFIG_ARTIK_S3T9MF)     += s3t9mf.o
 obj-$(CONFIG_ARTIK_TRUSTZONE_DRIVER)    += artiktee/
+obj-$(CONFIG_ARTIK_TIZEN_REBOOT)       += tizen-artik-reboot.o
diff --git a/drivers/misc/tizen-artik-reboot.c b/drivers/misc/tizen-artik-reboot.c
new file mode 100644 (file)
index 0000000..dd929f6
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Reboot Notifier for Tizen ARTIK
+ *
+ * Copyright (C) 2017, Samsung Electronics Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/io.h>
+#include <linux/notifier.h>
+#include <linux/reboot.h>
+
+#define ALIVE_BASE_ADDR        0xC0010800
+#define SCRATCHRSTREG7 0xF4
+#define SCRATCHSETREG7 0xF8
+#define SCRATCHREADREG7        0XFC
+
+#define REBOOT_MODE_PREFIX     0x12345670
+#define REBOOT_MODE_NONE       0
+#define REBOOT_MODE_DOWNLOAD   1
+#define REBOOT_MODE_RECOVERY   2
+#define REBOOT_MODE_FOTA       3
+
+static int tizen_artik_reboot_notify(struct notifier_block *this,
+               unsigned long code, void *unused)
+{
+       char *cmd = (char *)unused;
+       static void __iomem *base;
+       u32 val = REBOOT_MODE_PREFIX;
+
+       base = ioremap(ALIVE_BASE_ADDR, 0x100);
+       if (unlikely(!base))
+               return NOTIFY_BAD;
+
+       /*
+        * In order to maintain the reboot value written in SCRATCH7 register,
+        * set all bits of RST register as 1 before setting the reboot value.
+        */
+       __raw_writel(0xFFFFFFFF, base + SCRATCHRSTREG7);
+
+       if (cmd && !strncmp(cmd, "download", 8))
+               val |= REBOOT_MODE_DOWNLOAD;
+       else if (cmd && !strncmp(cmd, "recovery", 8))
+               val |= REBOOT_MODE_RECOVERY;
+       else if (cmd && !strncmp(cmd, "fota", 4))
+               val |= REBOOT_MODE_FOTA;
+       else
+               val |= REBOOT_MODE_NONE;
+
+       __raw_writel(val, base + SCRATCHSETREG7);
+
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block tizen_artik_reboot_handler = {
+       .notifier_call = tizen_artik_reboot_notify,
+       .priority = 128,
+};
+
+static int __init tizen_artik_reboot_init(void)
+{
+       int ret;
+
+       ret = register_reboot_notifier(&tizen_artik_reboot_handler);
+       if (ret)
+               printk("%s is failed = %d\n",__func__, ret);
+
+       return ret;
+}
+subsys_initcall(tizen_artik_reboot_init);