@@ -10734,6 +10734,7 @@ S: Maintained
F: Documentation/sh/
F: arch/sh/
F: drivers/sh/
+F: drivers/misc/boot-mode-reg/
SUSPEND TO RAM
M: "Rafael J. Wysocki" <rjw@rjwysocki.net>
@@ -816,4 +816,5 @@ source "drivers/misc/mic/Kconfig"
source "drivers/misc/genwqe/Kconfig"
source "drivers/misc/echo/Kconfig"
source "drivers/misc/cxl/Kconfig"
+source "drivers/misc/boot-mode-reg/Kconfig"
endmenu
@@ -57,3 +57,4 @@ obj-$(CONFIG_ECHO) += echo/
obj-$(CONFIG_VEXPRESS_SYSCFG) += vexpress-syscfg.o
obj-$(CONFIG_CXL_BASE) += cxl/
obj-$(CONFIG_PANEL) += panel.o
+obj-$(CONFIG_BOOT_MODE_REG_CORE) += boot-mode-reg/
new file mode 100644
@@ -0,0 +1,11 @@
+#
+# Boot Mode Register Drivers
+#
+
+config BOOT_MODE_REG_CORE
+ tristate "Boot Mode Register Core Driver"
+ default n
+ depends on ARCH_SHMOBILE || ARCH_RENESAS || COMPILE_TEST
+ help
+ Say Y here to allow support for drivers to read boot mode
+ registers and make the value available to other subsystems.
new file mode 100644
@@ -0,0 +1,6 @@
+
+#
+# Makefile for misc devices that really don't fit anywhere else.
+#
+
+obj-$(CONFIG_BOOT_MODE_REG_CORE) += core.o
new file mode 100644
@@ -0,0 +1,78 @@
+/*
+ * Boot Mode Register
+ *
+ * Copyright (C) 2015 Simon Horman
+ *
+ * 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; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <asm/errno.h>
+
+#include <linux/export.h>
+#include <linux/module.h>
+
+#include <misc/boot-mode-reg.h>
+
+static DEFINE_MUTEX(boot_mode_mutex);
+static bool boot_mode_is_set;
+static u32 boot_mode;
+
+/**
+ * boot_mode_reg_get() - retrieve boot mode register value
+ * @mode: implementation-dependent boot mode register value
+ *
+ * Retrieves the boot mode register value previously registered
+ * using boot_mode_reg_set().
+ *
+ * return: 0 on success
+ */
+int boot_mode_reg_get(u32 *mode)
+{
+ int err = -ENOENT;
+
+ mutex_lock(&boot_mode_mutex);
+ if (!boot_mode_is_set)
+ goto err;
+ *mode = boot_mode;
+ err = 0;
+err:
+ mutex_unlock(&boot_mode_mutex);
+ return err;
+}
+EXPORT_SYMBOL_GPL(boot_mode_reg_get);
+
+/**
+ * boot_mode_reg_set() - record boot mode register value
+ * @mode: implementation-dependent boot mode register value
+ *
+ * Records the boot mode register value which may subsequently
+ * be retrieved using boot_mode_reg_get().
+ *
+ * return: 0 on success
+ */
+int boot_mode_reg_set(u32 mode)
+{
+ int err = -EBUSY;
+
+ mutex_lock(&boot_mode_mutex);
+ if (boot_mode_is_set && boot_mode != mode)
+ goto err;
+ boot_mode = mode;
+ boot_mode_is_set = true;
+ err = 0;
+err:
+ mutex_unlock(&boot_mode_mutex);
+ return err;
+}
+EXPORT_SYMBOL_GPL(boot_mode_reg_set);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Simon Horman <horms@verge.net.au>");
+MODULE_DESCRIPTION("Core Boot Mode Register Driver");
new file mode 100644
@@ -0,0 +1,24 @@
+/*
+ * Boot Mode Register
+ *
+ * Copyright (C) 2015 Simon Horman
+ *
+ * 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; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _BOOT_MODE_REG_H
+#define _BOOT_MODE_REG_H
+
+#include <linux/types.h>
+
+int boot_mode_reg_get(u32 *mode);
+int boot_mode_reg_set(u32 mode);
+
+#endif