From 8ca3551825d75f8703dc18dc753c1623348745c0 Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Tue, 24 Oct 2017 18:11:11 +0900 Subject: [PATCH] misc: tizen-artik-reboot: support the reboot notifier 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 Signed-off-by: Junghoon Kim --- drivers/misc/Kconfig | 7 ++++ drivers/misc/Makefile | 1 + drivers/misc/tizen-artik-reboot.c | 73 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 drivers/misc/tizen-artik-reboot.c diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 4e53338..4ec5bb4 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -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" diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index fee68f9..c23558a 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -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 index 0000000..dd929f6 --- /dev/null +++ b/drivers/misc/tizen-artik-reboot.c @@ -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 +#include +#include + +#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); -- 2.7.4