power: reset: Add reboot driver for brcmstb
authorMarc Carino <marc.ceeeee@gmail.com>
Tue, 22 Jul 2014 23:48:03 +0000 (16:48 -0700)
committerSebastian Reichel <sre@kernel.org>
Wed, 23 Jul 2014 11:49:23 +0000 (13:49 +0200)
Add support for reboot functionality on boards with ARM-based
Broadcom STB chipsets. Make it built-in by default for ARCH_BRCMSTB,
but allow it to be configurable under COMPILE_TEST.

Signed-off-by: Marc Carino <marc.ceeeee@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
drivers/power/reset/Kconfig
drivers/power/reset/Makefile
drivers/power/reset/brcmstb-reboot.c [new file with mode: 0644]

index bdcf5173e377f55ce1c6dc27cce7ff513b49edd8..f2ac54df496f1e3b0ea597315a41a1e24f09af76 100644 (file)
@@ -20,6 +20,17 @@ config POWER_RESET_AXXIA
 
          Say Y if you have an Axxia family SoC.
 
+config POWER_RESET_BRCMSTB
+       bool "Broadcom STB reset driver" if COMPILE_TEST
+       depends on POWER_RESET && ARM
+       default ARCH_BRCMSTB
+       help
+         This driver provides restart support for ARM-based Broadcom STB
+         boards.
+
+         Say Y here if you have an ARM-based Broadcom STB board and you wish
+         to have restart support.
+
 config POWER_RESET_GPIO
        bool "GPIO power-off driver"
        depends on OF_GPIO && POWER_RESET
index dde2e8bbac53bca4229c810ab37037c0f5fbb02f..7379818ca69d097f47ba7a3f8d4790755b67f8ff 100644 (file)
@@ -1,5 +1,6 @@
 obj-$(CONFIG_POWER_RESET_AS3722) += as3722-poweroff.o
 obj-$(CONFIG_POWER_RESET_AXXIA) += axxia-reset.o
+obj-$(CONFIG_POWER_RESET_BRCMSTB) += brcmstb-reboot.o
 obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
 obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o
 obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o
diff --git a/drivers/power/reset/brcmstb-reboot.c b/drivers/power/reset/brcmstb-reboot.c
new file mode 100644 (file)
index 0000000..3f23692
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2013 Broadcom Corporation
+ *
+ * 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.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/jiffies.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/printk.h>
+#include <linux/reboot.h>
+#include <linux/regmap.h>
+#include <linux/smp.h>
+#include <linux/mfd/syscon.h>
+
+#include <asm/system_misc.h>
+
+#define RESET_SOURCE_ENABLE_REG 1
+#define SW_MASTER_RESET_REG 2
+
+static struct regmap *regmap;
+static u32 rst_src_en;
+static u32 sw_mstr_rst;
+
+static void brcmstb_reboot(enum reboot_mode mode, const char *cmd)
+{
+       int rc;
+       u32 tmp;
+
+       rc = regmap_write(regmap, rst_src_en, 1);
+       if (rc) {
+               pr_err("failed to write rst_src_en (%d)\n", rc);
+               return;
+       }
+
+       rc = regmap_read(regmap, rst_src_en, &tmp);
+       if (rc) {
+               pr_err("failed to read rst_src_en (%d)\n", rc);
+               return;
+       }
+
+       rc = regmap_write(regmap, sw_mstr_rst, 1);
+       if (rc) {
+               pr_err("failed to write sw_mstr_rst (%d)\n", rc);
+               return;
+       }
+
+       rc = regmap_read(regmap, sw_mstr_rst, &tmp);
+       if (rc) {
+               pr_err("failed to read sw_mstr_rst (%d)\n", rc);
+               return;
+       }
+
+       while (1)
+               ;
+}
+
+static int brcmstb_reboot_probe(struct platform_device *pdev)
+{
+       int rc;
+       struct device_node *np = pdev->dev.of_node;
+
+       regmap = syscon_regmap_lookup_by_phandle(np, "syscon");
+       if (IS_ERR(regmap)) {
+               pr_err("failed to get syscon phandle\n");
+               return -EINVAL;
+       }
+
+       rc = of_property_read_u32_index(np, "syscon", RESET_SOURCE_ENABLE_REG,
+                                       &rst_src_en);
+       if (rc) {
+               pr_err("can't get rst_src_en offset (%d)\n", rc);
+               return -EINVAL;
+       }
+
+       rc = of_property_read_u32_index(np, "syscon", SW_MASTER_RESET_REG,
+                                       &sw_mstr_rst);
+       if (rc) {
+               pr_err("can't get sw_mstr_rst offset (%d)\n", rc);
+               return -EINVAL;
+       }
+
+       arm_pm_restart = brcmstb_reboot;
+
+       return 0;
+}
+
+static const struct of_device_id of_match[] = {
+       { .compatible = "brcm,brcmstb-reboot", },
+       {},
+};
+
+static struct platform_driver brcmstb_reboot_driver = {
+       .probe = brcmstb_reboot_probe,
+       .driver = {
+               .name = "brcmstb-reboot",
+               .owner = THIS_MODULE,
+               .of_match_table = of_match,
+       },
+};
+
+static int __init brcmstb_reboot_init(void)
+{
+       return platform_driver_probe(&brcmstb_reboot_driver,
+                                       brcmstb_reboot_probe);
+}
+subsys_initcall(brcmstb_reboot_init);