blob: 0966e257464a26cd273fe75893eb83f99b2ca393 [file] [log] [blame]
Biju Dasda58fb42021-03-01 17:08:47 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * board/hoperun/hihope-rzg2/hihope-rzg2.c
Biju Dasd771b222021-03-01 17:08:49 +00004 * This file is HiHope RZ/G2[HMN] board support.
Biju Dasda58fb42021-03-01 17:08:47 +00005 *
6 * Copyright (C) 2021 Renesas Electronics Corporation
7 */
8
Biju Dasda58fb42021-03-01 17:08:47 +00009#include <asm/global_data.h>
10#include <asm/io.h>
11#include <asm/processor.h>
Marek Vasut97a070b2024-02-27 17:05:54 +010012#include <asm/arch/renesas.h>
Biju Dasda58fb42021-03-01 17:08:47 +000013#include <asm/arch/rcar-mstp.h>
14#include <linux/bitops.h>
15#include <linux/delay.h>
16#include <linux/libfdt.h>
17
18#define RST_BASE 0xE6160000
19#define RST_CA57RESCNT (RST_BASE + 0x40)
20#define RST_CA53RESCNT (RST_BASE + 0x44)
21#define RST_CA57_CODE 0xA5A5000F
22#define RST_CA53_CODE 0x5A5A000F
23
24DECLARE_GLOBAL_DATA_PTR;
25#define HSUSB_MSTP704 BIT(4) /* HSUSB */
26
27/* HSUSB block registers */
28#define HSUSB_REG_LPSTS 0xE6590102
29#define HSUSB_REG_LPSTS_SUSPM_NORMAL BIT(14)
30#define HSUSB_REG_UGCTRL2 0xE6590184
31#define HSUSB_REG_UGCTRL2_USB0SEL_EHCI 0x10
32#define HSUSB_REG_UGCTRL2_RESERVED_3 0x1 /* bit[3:0] should be B'0001 */
33
34#define PRR_REGISTER (0xFFF00044)
35
36int board_init(void)
37{
38 u32 i;
39
40 /* address of boot parameters */
Simon Glass72cc5382022-10-20 18:22:39 -060041 gd->bd->bi_boot_params = CONFIG_TEXT_BASE + 0x50000;
Biju Dasda58fb42021-03-01 17:08:47 +000042
43 /* Configure the HSUSB block */
44 mstp_clrbits_le32(SMSTPCR7, SMSTPCR7, HSUSB_MSTP704);
45 /*
46 * We need to add a barrier instruction after HSUSB module stop release.
47 * This barrier instruction can be either reading back the same MSTP
48 * register or any other register in the same IP block. So like linux
49 * adding check for MSTPSR register, which indicates the clock has been
50 * started.
51 */
52 for (i = 1000; i > 0; --i) {
53 if (!(readl(MSTPSR7) & HSUSB_MSTP704))
54 break;
55 cpu_relax();
56 }
57
58 /* Select EHCI/OHCI host module for USB2.0 ch0 */
59 writel(HSUSB_REG_UGCTRL2_USB0SEL_EHCI | HSUSB_REG_UGCTRL2_RESERVED_3,
60 HSUSB_REG_UGCTRL2);
61 /* low power status */
62 setbits_le16(HSUSB_REG_LPSTS, HSUSB_REG_LPSTS_SUSPM_NORMAL);
63
64 return 0;
65}
66
Patrick Delaunay3fa1bdc2021-07-19 11:21:50 +020067void reset_cpu(void)
Biju Dasda58fb42021-03-01 17:08:47 +000068{
69 unsigned long midr, cputype;
70
71 asm volatile("mrs %0, midr_el1" : "=r" (midr));
72 cputype = (midr >> 4) & 0xfff;
73
74 if (cputype == 0xd03)
75 writel(RST_CA53_CODE, RST_CA53RESCNT);
76 else
77 writel(RST_CA57_CODE, RST_CA57RESCNT);
78}
79
80#if defined(CONFIG_MULTI_DTB_FIT)
81/* If the firmware passed a device tree, use it for board identification. */
82extern u64 rcar_atf_boot_args[];
83
84static bool is_hoperun_hihope_rzg2_board(const char *board_name)
85{
86 void *atf_fdt_blob = (void *)(rcar_atf_boot_args[1]);
87 bool ret = false;
88
89 if ((fdt_magic(atf_fdt_blob) == FDT_MAGIC) &&
90 (fdt_node_check_compatible(atf_fdt_blob, 0, board_name) == 0))
91 ret = true;
92
93 return ret;
94}
95
96int board_fit_config_name_match(const char *name)
97{
98 if (is_hoperun_hihope_rzg2_board("hoperun,hihope-rzg2m") &&
99 !strcmp(name, "r8a774a1-hihope-rzg2m-u-boot"))
100 return 0;
101
Biju Das222cb302021-03-01 17:08:48 +0000102 if (is_hoperun_hihope_rzg2_board("hoperun,hihope-rzg2n") &&
103 !strcmp(name, "r8a774b1-hihope-rzg2n-u-boot"))
104 return 0;
105
Biju Dasd771b222021-03-01 17:08:49 +0000106 if (is_hoperun_hihope_rzg2_board("hoperun,hihope-rzg2h") &&
107 !strcmp(name, "r8a774e1-hihope-rzg2h-u-boot"))
108 return 0;
109
Biju Dasda58fb42021-03-01 17:08:47 +0000110 return -1;
111}
112#endif