1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Renesas R-Car E3 System Controller
4  *
5  * Copyright (C) 2018 Renesas Electronics Corp.
6  */
7 
8 #include <linux/bug.h>
9 #include <linux/kernel.h>
10 #include <linux/sys_soc.h>
11 
12 #include <dt-bindings/power/r8a77990-sysc.h>
13 
14 #include "rcar-sysc.h"
15 
16 static struct rcar_sysc_area r8a77990_areas[] __initdata = {
17 	{ "always-on",	    0, 0, R8A77990_PD_ALWAYS_ON, -1, PD_ALWAYS_ON },
18 	{ "ca53-scu",	0x140, 0, R8A77990_PD_CA53_SCU,  R8A77990_PD_ALWAYS_ON,
19 	  PD_SCU },
20 	{ "ca53-cpu0",	0x200, 0, R8A77990_PD_CA53_CPU0, R8A77990_PD_CA53_SCU,
21 	  PD_CPU_NOCR },
22 	{ "ca53-cpu1",	0x200, 1, R8A77990_PD_CA53_CPU1, R8A77990_PD_CA53_SCU,
23 	  PD_CPU_NOCR },
24 	{ "cr7",	0x240, 0, R8A77990_PD_CR7,	R8A77990_PD_ALWAYS_ON },
25 	{ "a3vc",	0x380, 0, R8A77990_PD_A3VC,	R8A77990_PD_ALWAYS_ON },
26 	{ "a2vc1",	0x3c0, 1, R8A77990_PD_A2VC1,	R8A77990_PD_A3VC },
27 	{ "3dg-a",	0x100, 0, R8A77990_PD_3DG_A,	R8A77990_PD_ALWAYS_ON },
28 	{ "3dg-b",	0x100, 1, R8A77990_PD_3DG_B,	R8A77990_PD_3DG_A },
29 };
30 
rcar_sysc_fix_parent(struct rcar_sysc_area * areas,unsigned int num_areas,u8 id,int new_parent)31 static void __init rcar_sysc_fix_parent(struct rcar_sysc_area *areas,
32 					unsigned int num_areas, u8 id,
33 					int new_parent)
34 {
35 	unsigned int i;
36 
37 	for (i = 0; i < num_areas; i++)
38 		if (areas[i].isr_bit == id) {
39 			areas[i].parent = new_parent;
40 			return;
41 		}
42 }
43 
44 /* Fixups for R-Car E3 ES1.0 revision */
45 static const struct soc_device_attribute r8a77990[] __initconst = {
46 	{ .soc_id = "r8a77990", .revision = "ES1.0" },
47 	{ /* sentinel */ }
48 };
49 
r8a77990_sysc_init(void)50 static int __init r8a77990_sysc_init(void)
51 {
52 	if (soc_device_match(r8a77990)) {
53 		rcar_sysc_fix_parent(r8a77990_areas,
54 				     ARRAY_SIZE(r8a77990_areas),
55 				     R8A77990_PD_3DG_A, R8A77990_PD_3DG_B);
56 		rcar_sysc_fix_parent(r8a77990_areas,
57 				     ARRAY_SIZE(r8a77990_areas),
58 				     R8A77990_PD_3DG_B, R8A77990_PD_ALWAYS_ON);
59 	}
60 
61 	return 0;
62 }
63 
64 const struct rcar_sysc_info r8a77990_sysc_info __initconst = {
65 	.init = r8a77990_sysc_init,
66 	.areas = r8a77990_areas,
67 	.num_areas = ARRAY_SIZE(r8a77990_areas),
68 };
69