18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Device Tree support for Rockchip SoCs
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2013 MundoReader S.L.
68c2ecf20Sopenharmony_ci * Author: Heiko Stuebner <heiko@sntech.de>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/kernel.h>
108c2ecf20Sopenharmony_ci#include <linux/init.h>
118c2ecf20Sopenharmony_ci#include <linux/io.h>
128c2ecf20Sopenharmony_ci#include <linux/of_clk.h>
138c2ecf20Sopenharmony_ci#include <linux/of_platform.h>
148c2ecf20Sopenharmony_ci#include <linux/irqchip.h>
158c2ecf20Sopenharmony_ci#include <linux/clocksource.h>
168c2ecf20Sopenharmony_ci#include <linux/mfd/syscon.h>
178c2ecf20Sopenharmony_ci#include <linux/regmap.h>
188c2ecf20Sopenharmony_ci#include <asm/mach/arch.h>
198c2ecf20Sopenharmony_ci#include <asm/mach/map.h>
208c2ecf20Sopenharmony_ci#include <asm/hardware/cache-l2x0.h>
218c2ecf20Sopenharmony_ci#include "core.h"
228c2ecf20Sopenharmony_ci#include "pm.h"
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define RK3288_TIMER6_7_PHYS 0xff810000
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic void __init rockchip_timer_init(void)
278c2ecf20Sopenharmony_ci{
288c2ecf20Sopenharmony_ci	if (of_machine_is_compatible("rockchip,rk3288")) {
298c2ecf20Sopenharmony_ci		void __iomem *reg_base;
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci		/*
328c2ecf20Sopenharmony_ci		 * Most/all uboot versions for rk3288 don't enable timer7
338c2ecf20Sopenharmony_ci		 * which is needed for the architected timer to work.
348c2ecf20Sopenharmony_ci		 * So make sure it is running during early boot.
358c2ecf20Sopenharmony_ci		 */
368c2ecf20Sopenharmony_ci		reg_base = ioremap(RK3288_TIMER6_7_PHYS, SZ_16K);
378c2ecf20Sopenharmony_ci		if (reg_base) {
388c2ecf20Sopenharmony_ci			writel(0, reg_base + 0x30);
398c2ecf20Sopenharmony_ci			writel(0xffffffff, reg_base + 0x20);
408c2ecf20Sopenharmony_ci			writel(0xffffffff, reg_base + 0x24);
418c2ecf20Sopenharmony_ci			writel(1, reg_base + 0x30);
428c2ecf20Sopenharmony_ci			dsb();
438c2ecf20Sopenharmony_ci			iounmap(reg_base);
448c2ecf20Sopenharmony_ci		} else {
458c2ecf20Sopenharmony_ci			pr_err("rockchip: could not map timer7 registers\n");
468c2ecf20Sopenharmony_ci		}
478c2ecf20Sopenharmony_ci	}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	of_clk_init(NULL);
508c2ecf20Sopenharmony_ci	timer_probe();
518c2ecf20Sopenharmony_ci}
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistatic void __init rockchip_dt_init(void)
548c2ecf20Sopenharmony_ci{
558c2ecf20Sopenharmony_ci	rockchip_suspend_init();
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic const char * const rockchip_board_dt_compat[] = {
598c2ecf20Sopenharmony_ci	"rockchip,rk2928",
608c2ecf20Sopenharmony_ci	"rockchip,rk3066a",
618c2ecf20Sopenharmony_ci	"rockchip,rk3066b",
628c2ecf20Sopenharmony_ci	"rockchip,rk3188",
638c2ecf20Sopenharmony_ci	"rockchip,rk3228",
648c2ecf20Sopenharmony_ci	"rockchip,rk3288",
658c2ecf20Sopenharmony_ci	"rockchip,rv1108",
668c2ecf20Sopenharmony_ci	NULL,
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciDT_MACHINE_START(ROCKCHIP_DT, "Rockchip (Device Tree)")
708c2ecf20Sopenharmony_ci	.l2c_aux_val	= 0,
718c2ecf20Sopenharmony_ci	.l2c_aux_mask	= ~0,
728c2ecf20Sopenharmony_ci	.init_time	= rockchip_timer_init,
738c2ecf20Sopenharmony_ci	.dt_compat	= rockchip_board_dt_compat,
748c2ecf20Sopenharmony_ci	.init_machine	= rockchip_dt_init,
758c2ecf20Sopenharmony_ciMACHINE_END
76