2018-09-07 10:04:19 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-05-27 17:56:53 +08:00
|
|
|
/*
|
|
|
|
* R-Car Gen1 RESET/WDT, R-Car Gen2, Gen3, and RZ/G RST Driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Glider bvba
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/soc/renesas/rcar-rst.h>
|
|
|
|
|
2018-02-13 21:02:44 +08:00
|
|
|
#define WDTRSTCR_RESET 0xA55A0002
|
|
|
|
#define WDTRSTCR 0x0054
|
|
|
|
|
2021-10-22 20:21:01 +08:00
|
|
|
#define CR7BAR 0x0070
|
|
|
|
#define CR7BAREN BIT(4)
|
|
|
|
#define CR7BAR_MASK 0xFFFC0000
|
|
|
|
|
|
|
|
static void __iomem *rcar_rst_base;
|
|
|
|
static u32 saved_mode __initdata;
|
|
|
|
static int (*rcar_rst_set_rproc_boot_addr_func)(u64 boot_addr);
|
|
|
|
|
2018-02-13 21:02:44 +08:00
|
|
|
static int rcar_rst_enable_wdt_reset(void __iomem *base)
|
|
|
|
{
|
|
|
|
iowrite32(WDTRSTCR_RESET, base + WDTRSTCR);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-22 20:21:01 +08:00
|
|
|
/*
|
|
|
|
* Most of the R-Car Gen3 SoCs have an ARM Realtime Core.
|
|
|
|
* Firmware boot address has to be set in CR7BAR before
|
|
|
|
* starting the realtime core.
|
|
|
|
* Boot address must be aligned on a 256k boundary.
|
|
|
|
*/
|
|
|
|
static int rcar_rst_set_gen3_rproc_boot_addr(u64 boot_addr)
|
|
|
|
{
|
|
|
|
if (boot_addr & ~(u64)CR7BAR_MASK) {
|
|
|
|
pr_err("Invalid boot address got %llx\n", boot_addr);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iowrite32(boot_addr, rcar_rst_base + CR7BAR);
|
|
|
|
iowrite32(boot_addr | CR7BAREN, rcar_rst_base + CR7BAR);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-27 17:56:53 +08:00
|
|
|
struct rst_config {
|
2018-02-13 21:02:44 +08:00
|
|
|
unsigned int modemr; /* Mode Monitoring Register Offset */
|
2019-12-18 21:52:30 +08:00
|
|
|
int (*configure)(void __iomem *base); /* Platform specific config */
|
2021-10-22 20:21:01 +08:00
|
|
|
int (*set_rproc_boot_addr)(u64 boot_addr);
|
2016-05-27 17:56:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct rst_config rcar_rst_gen1 __initconst = {
|
|
|
|
.modemr = 0x20,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct rst_config rcar_rst_gen2 __initconst = {
|
|
|
|
.modemr = 0x60,
|
2018-02-13 21:02:44 +08:00
|
|
|
.configure = rcar_rst_enable_wdt_reset,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct rst_config rcar_rst_gen3 __initconst = {
|
|
|
|
.modemr = 0x60,
|
2021-10-22 20:21:01 +08:00
|
|
|
.set_rproc_boot_addr = rcar_rst_set_gen3_rproc_boot_addr,
|
2016-05-27 17:56:53 +08:00
|
|
|
};
|
|
|
|
|
2021-12-01 15:33:04 +08:00
|
|
|
static const struct rst_config rcar_rst_gen4 __initconst = {
|
2020-09-07 17:19:47 +08:00
|
|
|
.modemr = 0x00, /* MODEMR0 and it has CPG related bits */
|
|
|
|
};
|
|
|
|
|
2016-05-27 17:56:53 +08:00
|
|
|
static const struct of_device_id rcar_rst_matches[] __initconst = {
|
2018-08-02 22:55:04 +08:00
|
|
|
/* RZ/G1 is handled like R-Car Gen2 */
|
2020-04-24 05:40:45 +08:00
|
|
|
{ .compatible = "renesas,r8a7742-rst", .data = &rcar_rst_gen2 },
|
2016-05-27 17:56:53 +08:00
|
|
|
{ .compatible = "renesas,r8a7743-rst", .data = &rcar_rst_gen2 },
|
2018-09-11 18:12:46 +08:00
|
|
|
{ .compatible = "renesas,r8a7744-rst", .data = &rcar_rst_gen2 },
|
2016-05-27 17:56:53 +08:00
|
|
|
{ .compatible = "renesas,r8a7745-rst", .data = &rcar_rst_gen2 },
|
2018-03-27 22:37:14 +08:00
|
|
|
{ .compatible = "renesas,r8a77470-rst", .data = &rcar_rst_gen2 },
|
2018-08-02 22:55:04 +08:00
|
|
|
/* RZ/G2 is handled like R-Car Gen3 */
|
|
|
|
{ .compatible = "renesas,r8a774a1-rst", .data = &rcar_rst_gen3 },
|
2019-09-19 16:17:12 +08:00
|
|
|
{ .compatible = "renesas,r8a774b1-rst", .data = &rcar_rst_gen3 },
|
2018-09-10 23:09:41 +08:00
|
|
|
{ .compatible = "renesas,r8a774c0-rst", .data = &rcar_rst_gen3 },
|
2020-07-08 00:18:07 +08:00
|
|
|
{ .compatible = "renesas,r8a774e1-rst", .data = &rcar_rst_gen3 },
|
2016-05-27 17:56:53 +08:00
|
|
|
/* 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 },
|
2018-02-13 21:02:44 +08:00
|
|
|
/* R-Car Gen3 */
|
|
|
|
{ .compatible = "renesas,r8a7795-rst", .data = &rcar_rst_gen3 },
|
|
|
|
{ .compatible = "renesas,r8a7796-rst", .data = &rcar_rst_gen3 },
|
2019-10-23 20:33:36 +08:00
|
|
|
{ .compatible = "renesas,r8a77961-rst", .data = &rcar_rst_gen3 },
|
2018-02-20 23:12:04 +08:00
|
|
|
{ .compatible = "renesas,r8a77965-rst", .data = &rcar_rst_gen3 },
|
2018-02-13 21:02:44 +08:00
|
|
|
{ .compatible = "renesas,r8a77970-rst", .data = &rcar_rst_gen3 },
|
|
|
|
{ .compatible = "renesas,r8a77980-rst", .data = &rcar_rst_gen3 },
|
2018-04-11 17:36:26 +08:00
|
|
|
{ .compatible = "renesas,r8a77990-rst", .data = &rcar_rst_gen3 },
|
2018-02-13 21:02:44 +08:00
|
|
|
{ .compatible = "renesas,r8a77995-rst", .data = &rcar_rst_gen3 },
|
2021-12-01 15:33:04 +08:00
|
|
|
/* R-Car Gen4 */
|
|
|
|
{ .compatible = "renesas,r8a779a0-rst", .data = &rcar_rst_gen4 },
|
|
|
|
{ .compatible = "renesas,r8a779f0-rst", .data = &rcar_rst_gen4 },
|
2022-04-20 16:42:51 +08:00
|
|
|
{ .compatible = "renesas,r8a779g0-rst", .data = &rcar_rst_gen4 },
|
2016-05-27 17:56:53 +08:00
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
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) {
|
2017-07-19 05:43:29 +08:00
|
|
|
pr_warn("%pOF: Cannot map regs\n", np);
|
2016-05-27 17:56:53 +08:00
|
|
|
error = -ENOMEM;
|
|
|
|
goto out_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
rcar_rst_base = base;
|
|
|
|
cfg = match->data;
|
2021-10-22 20:21:01 +08:00
|
|
|
rcar_rst_set_rproc_boot_addr_func = cfg->set_rproc_boot_addr;
|
|
|
|
|
2016-05-27 17:56:53 +08:00
|
|
|
saved_mode = ioread32(base + cfg->modemr);
|
2018-02-13 21:02:44 +08:00
|
|
|
if (cfg->configure) {
|
|
|
|
error = cfg->configure(base);
|
|
|
|
if (error) {
|
|
|
|
pr_warn("%pOF: Cannot run SoC specific configuration\n",
|
|
|
|
np);
|
|
|
|
goto out_put;
|
|
|
|
}
|
|
|
|
}
|
2016-05-27 17:56:53 +08:00
|
|
|
|
2017-07-19 05:43:29 +08:00
|
|
|
pr_debug("%pOF: MODE = 0x%08x\n", np, saved_mode);
|
2016-05-27 17:56:53 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2021-10-22 20:21:01 +08:00
|
|
|
|
|
|
|
int rcar_rst_set_rproc_boot_addr(u64 boot_addr)
|
|
|
|
{
|
|
|
|
if (!rcar_rst_set_rproc_boot_addr_func)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return rcar_rst_set_rproc_boot_addr_func(boot_addr);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(rcar_rst_set_rproc_boot_addr);
|