]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
soc: renesas: Add R-Car RST driver
authorGeert Uytterhoeven <geert+renesas@glider.be>
Fri, 27 May 2016 09:56:53 +0000 (11:56 +0200)
committerGeert Uytterhoeven <geert+renesas@glider.be>
Wed, 2 Nov 2016 19:43:07 +0000 (20:43 +0100)
Add a driver for the Renesas R-Car Gen1 RESET/WDT and R-Car Gen2/Gen3
and RZ/G RST module.

For now this driver just provides an API to obtain the state of the mode
pins, as latched at reset time.  As this is typically called from the
probe function of a clock driver, which can run much earlier than any
initcall, calling rcar_rst_read_mode_pins() just forces an early
initialization of the driver.

Despite the current simple and almost identical handling for all
supported SoCs, the driver matches against SoC-specific compatible
values, as the features provided by the hardware module differ a lot
across the various SoC families and members.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Dirk Behme <dirk.behme@de.bosch.com>
drivers/soc/renesas/Makefile
drivers/soc/renesas/rcar-rst.c [new file with mode: 0644]
include/linux/soc/renesas/rcar-rst.h [new file with mode: 0644]

index 623039c3514cdc347d77f4d6ab7a3d5d0af469c5..86cc78cd1962701aca7c8d8cd838d17659254674 100644 (file)
@@ -1,3 +1,8 @@
+obj-$(CONFIG_ARCH_RCAR_GEN1)   += rcar-rst.o
+obj-$(CONFIG_ARCH_RCAR_GEN2)   += rcar-rst.o
+obj-$(CONFIG_ARCH_R8A7795)     += rcar-rst.o
+obj-$(CONFIG_ARCH_R8A7796)     += rcar-rst.o
+
 obj-$(CONFIG_ARCH_R8A7779)     += rcar-sysc.o r8a7779-sysc.o
 obj-$(CONFIG_ARCH_R8A7790)     += rcar-sysc.o r8a7790-sysc.o
 obj-$(CONFIG_ARCH_R8A7791)     += rcar-sysc.o r8a7791-sysc.o
diff --git a/drivers/soc/renesas/rcar-rst.c b/drivers/soc/renesas/rcar-rst.c
new file mode 100644 (file)
index 0000000..a6d1c26
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * R-Car Gen1 RESET/WDT, R-Car Gen2, Gen3, and RZ/G RST Driver
+ *
+ * Copyright (C) 2016 Glider bvba
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/of_address.h>
+#include <linux/soc/renesas/rcar-rst.h>
+
+struct rst_config {
+       unsigned int modemr;    /* Mode Monitoring Register Offset */
+};
+
+static const struct rst_config rcar_rst_gen1 __initconst = {
+       .modemr = 0x20,
+};
+
+static const struct rst_config rcar_rst_gen2 __initconst = {
+       .modemr = 0x60,
+};
+
+static const struct of_device_id rcar_rst_matches[] __initconst = {
+       /* RZ/G is handled like R-Car Gen2 */
+       { .compatible = "renesas,r8a7743-rst", .data = &rcar_rst_gen2 },
+       { .compatible = "renesas,r8a7745-rst", .data = &rcar_rst_gen2 },
+       /* R-Car Gen1 */
+       { .compatible = "renesas,r8a7778-reset-wdt", .data = &rcar_rst_gen1 },
+       { .compatible = "renesas,r8a7779-reset-wdt", .data = &rcar_rst_gen1 },
+       /* R-Car Gen2 */
+       { .compatible = "renesas,r8a7790-rst", .data = &rcar_rst_gen2 },
+       { .compatible = "renesas,r8a7791-rst", .data = &rcar_rst_gen2 },
+       { .compatible = "renesas,r8a7792-rst", .data = &rcar_rst_gen2 },
+       { .compatible = "renesas,r8a7793-rst", .data = &rcar_rst_gen2 },
+       { .compatible = "renesas,r8a7794-rst", .data = &rcar_rst_gen2 },
+       /* R-Car Gen3 is handled like R-Car Gen2 */
+       { .compatible = "renesas,r8a7795-rst", .data = &rcar_rst_gen2 },
+       { .compatible = "renesas,r8a7796-rst", .data = &rcar_rst_gen2 },
+       { /* sentinel */ }
+};
+
+static void __iomem *rcar_rst_base __initdata;
+static u32 saved_mode __initdata;
+
+static int __init rcar_rst_init(void)
+{
+       const struct of_device_id *match;
+       const struct rst_config *cfg;
+       struct device_node *np;
+       void __iomem *base;
+       int error = 0;
+
+       np = of_find_matching_node_and_match(NULL, rcar_rst_matches, &match);
+       if (!np)
+               return -ENODEV;
+
+       base = of_iomap(np, 0);
+       if (!base) {
+               pr_warn("%s: Cannot map regs\n", np->full_name);
+               error = -ENOMEM;
+               goto out_put;
+       }
+
+       rcar_rst_base = base;
+       cfg = match->data;
+       saved_mode = ioread32(base + cfg->modemr);
+
+       pr_debug("%s: MODE = 0x%08x\n", np->full_name, saved_mode);
+
+out_put:
+       of_node_put(np);
+       return error;
+}
+
+int __init rcar_rst_read_mode_pins(u32 *mode)
+{
+       int error;
+
+       if (!rcar_rst_base) {
+               error = rcar_rst_init();
+               if (error)
+                       return error;
+       }
+
+       *mode = saved_mode;
+       return 0;
+}
diff --git a/include/linux/soc/renesas/rcar-rst.h b/include/linux/soc/renesas/rcar-rst.h
new file mode 100644 (file)
index 0000000..a18e078
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __LINUX_SOC_RENESAS_RCAR_RST_H__
+#define __LINUX_SOC_RENESAS_RCAR_RST_H__
+
+int rcar_rst_read_mode_pins(u32 *mode);
+
+#endif /* __LINUX_SOC_RENESAS_RCAR_RST_H__ */