18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Renesas R-Car H3 System Controller
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2016-2017 Glider bvba
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/bits.h>
98c2ecf20Sopenharmony_ci#include <linux/kernel.h>
108c2ecf20Sopenharmony_ci#include <linux/sys_soc.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <dt-bindings/power/r8a7795-sysc.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include "rcar-sysc.h"
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistatic struct rcar_sysc_area r8a7795_areas[] __initdata = {
178c2ecf20Sopenharmony_ci	{ "always-on",	    0, 0, R8A7795_PD_ALWAYS_ON,	-1, PD_ALWAYS_ON },
188c2ecf20Sopenharmony_ci	{ "ca57-scu",	0x1c0, 0, R8A7795_PD_CA57_SCU,	R8A7795_PD_ALWAYS_ON,
198c2ecf20Sopenharmony_ci	  PD_SCU },
208c2ecf20Sopenharmony_ci	{ "ca57-cpu0",	 0x80, 0, R8A7795_PD_CA57_CPU0,	R8A7795_PD_CA57_SCU,
218c2ecf20Sopenharmony_ci	  PD_CPU_NOCR },
228c2ecf20Sopenharmony_ci	{ "ca57-cpu1",	 0x80, 1, R8A7795_PD_CA57_CPU1,	R8A7795_PD_CA57_SCU,
238c2ecf20Sopenharmony_ci	  PD_CPU_NOCR },
248c2ecf20Sopenharmony_ci	{ "ca57-cpu2",	 0x80, 2, R8A7795_PD_CA57_CPU2,	R8A7795_PD_CA57_SCU,
258c2ecf20Sopenharmony_ci	  PD_CPU_NOCR },
268c2ecf20Sopenharmony_ci	{ "ca57-cpu3",	 0x80, 3, R8A7795_PD_CA57_CPU3,	R8A7795_PD_CA57_SCU,
278c2ecf20Sopenharmony_ci	  PD_CPU_NOCR },
288c2ecf20Sopenharmony_ci	{ "ca53-scu",	0x140, 0, R8A7795_PD_CA53_SCU,	R8A7795_PD_ALWAYS_ON,
298c2ecf20Sopenharmony_ci	  PD_SCU },
308c2ecf20Sopenharmony_ci	{ "ca53-cpu0",	0x200, 0, R8A7795_PD_CA53_CPU0,	R8A7795_PD_CA53_SCU,
318c2ecf20Sopenharmony_ci	  PD_CPU_NOCR },
328c2ecf20Sopenharmony_ci	{ "ca53-cpu1",	0x200, 1, R8A7795_PD_CA53_CPU1,	R8A7795_PD_CA53_SCU,
338c2ecf20Sopenharmony_ci	  PD_CPU_NOCR },
348c2ecf20Sopenharmony_ci	{ "ca53-cpu2",	0x200, 2, R8A7795_PD_CA53_CPU2,	R8A7795_PD_CA53_SCU,
358c2ecf20Sopenharmony_ci	  PD_CPU_NOCR },
368c2ecf20Sopenharmony_ci	{ "ca53-cpu3",	0x200, 3, R8A7795_PD_CA53_CPU3,	R8A7795_PD_CA53_SCU,
378c2ecf20Sopenharmony_ci	  PD_CPU_NOCR },
388c2ecf20Sopenharmony_ci	{ "a3vp",	0x340, 0, R8A7795_PD_A3VP,	R8A7795_PD_ALWAYS_ON },
398c2ecf20Sopenharmony_ci	{ "cr7",	0x240, 0, R8A7795_PD_CR7,	R8A7795_PD_ALWAYS_ON },
408c2ecf20Sopenharmony_ci	{ "a3vc",	0x380, 0, R8A7795_PD_A3VC,	R8A7795_PD_ALWAYS_ON },
418c2ecf20Sopenharmony_ci	/* A2VC0 exists on ES1.x only */
428c2ecf20Sopenharmony_ci	{ "a2vc0",	0x3c0, 0, R8A7795_PD_A2VC0,	R8A7795_PD_A3VC },
438c2ecf20Sopenharmony_ci	{ "a2vc1",	0x3c0, 1, R8A7795_PD_A2VC1,	R8A7795_PD_A3VC },
448c2ecf20Sopenharmony_ci	{ "3dg-a",	0x100, 0, R8A7795_PD_3DG_A,	R8A7795_PD_ALWAYS_ON },
458c2ecf20Sopenharmony_ci	{ "3dg-b",	0x100, 1, R8A7795_PD_3DG_B,	R8A7795_PD_3DG_A },
468c2ecf20Sopenharmony_ci	{ "3dg-c",	0x100, 2, R8A7795_PD_3DG_C,	R8A7795_PD_3DG_B },
478c2ecf20Sopenharmony_ci	{ "3dg-d",	0x100, 3, R8A7795_PD_3DG_D,	R8A7795_PD_3DG_C },
488c2ecf20Sopenharmony_ci	{ "3dg-e",	0x100, 4, R8A7795_PD_3DG_E,	R8A7795_PD_3DG_D },
498c2ecf20Sopenharmony_ci	{ "a3ir",	0x180, 0, R8A7795_PD_A3IR,	R8A7795_PD_ALWAYS_ON },
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	/*
548c2ecf20Sopenharmony_ci	 * Fixups for R-Car H3 revisions
558c2ecf20Sopenharmony_ci	 */
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#define HAS_A2VC0	BIT(0)		/* Power domain A2VC0 is present */
588c2ecf20Sopenharmony_ci#define NO_EXTMASK	BIT(1)		/* Missing SYSCEXTMASK register */
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic const struct soc_device_attribute r8a7795_quirks_match[] __initconst = {
618c2ecf20Sopenharmony_ci	{
628c2ecf20Sopenharmony_ci		.soc_id = "r8a7795", .revision = "ES1.*",
638c2ecf20Sopenharmony_ci		.data = (void *)(HAS_A2VC0 | NO_EXTMASK),
648c2ecf20Sopenharmony_ci	}, {
658c2ecf20Sopenharmony_ci		.soc_id = "r8a7795", .revision = "ES2.*",
668c2ecf20Sopenharmony_ci		.data = (void *)(NO_EXTMASK),
678c2ecf20Sopenharmony_ci	},
688c2ecf20Sopenharmony_ci	{ /* sentinel */ }
698c2ecf20Sopenharmony_ci};
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cistatic int __init r8a7795_sysc_init(void)
728c2ecf20Sopenharmony_ci{
738c2ecf20Sopenharmony_ci	const struct soc_device_attribute *attr;
748c2ecf20Sopenharmony_ci	u32 quirks = 0;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	attr = soc_device_match(r8a7795_quirks_match);
778c2ecf20Sopenharmony_ci	if (attr)
788c2ecf20Sopenharmony_ci		quirks = (uintptr_t)attr->data;
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	if (!(quirks & HAS_A2VC0))
818c2ecf20Sopenharmony_ci		rcar_sysc_nullify(r8a7795_areas, ARRAY_SIZE(r8a7795_areas),
828c2ecf20Sopenharmony_ci				  R8A7795_PD_A2VC0);
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	if (quirks & NO_EXTMASK)
858c2ecf20Sopenharmony_ci		r8a7795_sysc_info.extmask_val = 0;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	return 0;
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistruct rcar_sysc_info r8a7795_sysc_info __initdata = {
918c2ecf20Sopenharmony_ci	.init = r8a7795_sysc_init,
928c2ecf20Sopenharmony_ci	.areas = r8a7795_areas,
938c2ecf20Sopenharmony_ci	.num_areas = ARRAY_SIZE(r8a7795_areas),
948c2ecf20Sopenharmony_ci	.extmask_offs = 0x2f8,
958c2ecf20Sopenharmony_ci	.extmask_val = BIT(0),
968c2ecf20Sopenharmony_ci};
97