Biju Das | da58fb4 | 2021-03-01 17:08:47 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * board/hoperun/hihope-rzg2/hihope-rzg2.c |
Biju Das | d771b22 | 2021-03-01 17:08:49 +0000 | [diff] [blame] | 4 | * This file is HiHope RZ/G2[HMN] board support. |
Biju Das | da58fb4 | 2021-03-01 17:08:47 +0000 | [diff] [blame] | 5 | * |
| 6 | * Copyright (C) 2021 Renesas Electronics Corporation |
| 7 | */ |
| 8 | |
Biju Das | da58fb4 | 2021-03-01 17:08:47 +0000 | [diff] [blame] | 9 | #include <asm/global_data.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <asm/processor.h> |
Marek Vasut | 97a070b | 2024-02-27 17:05:54 +0100 | [diff] [blame] | 12 | #include <asm/arch/renesas.h> |
Biju Das | da58fb4 | 2021-03-01 17:08:47 +0000 | [diff] [blame] | 13 | #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 | |
| 24 | DECLARE_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 | |
| 36 | int board_init(void) |
| 37 | { |
| 38 | u32 i; |
| 39 | |
| 40 | /* address of boot parameters */ |
Simon Glass | 72cc538 | 2022-10-20 18:22:39 -0600 | [diff] [blame] | 41 | gd->bd->bi_boot_params = CONFIG_TEXT_BASE + 0x50000; |
Biju Das | da58fb4 | 2021-03-01 17:08:47 +0000 | [diff] [blame] | 42 | |
| 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 Delaunay | 3fa1bdc | 2021-07-19 11:21:50 +0200 | [diff] [blame] | 67 | void reset_cpu(void) |
Biju Das | da58fb4 | 2021-03-01 17:08:47 +0000 | [diff] [blame] | 68 | { |
| 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. */ |
| 82 | extern u64 rcar_atf_boot_args[]; |
| 83 | |
| 84 | static 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 | |
| 96 | int 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 Das | 222cb30 | 2021-03-01 17:08:48 +0000 | [diff] [blame] | 102 | if (is_hoperun_hihope_rzg2_board("hoperun,hihope-rzg2n") && |
| 103 | !strcmp(name, "r8a774b1-hihope-rzg2n-u-boot")) |
| 104 | return 0; |
| 105 | |
Biju Das | d771b22 | 2021-03-01 17:08:49 +0000 | [diff] [blame] | 106 | if (is_hoperun_hihope_rzg2_board("hoperun,hihope-rzg2h") && |
| 107 | !strcmp(name, "r8a774e1-hihope-rzg2h-u-boot")) |
| 108 | return 0; |
| 109 | |
Biju Das | da58fb4 | 2021-03-01 17:08:47 +0000 | [diff] [blame] | 110 | return -1; |
| 111 | } |
| 112 | #endif |