Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2018 Synopsys, Inc. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dwmmc.h> |
| 8 | #include <malloc.h> |
| 9 | |
Alexey Brodkin | d4472c8 | 2018-11-27 09:46:59 +0300 | [diff] [blame] | 10 | #include <asm/arcregs.h> |
| 11 | |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
Alexey Brodkin | d4472c8 | 2018-11-27 09:46:59 +0300 | [diff] [blame] | 14 | #define ARC_PERIPHERAL_BASE 0xF0000000 |
| 15 | |
| 16 | #define CGU_ARC_FMEAS_ARC (void *)(ARC_PERIPHERAL_BASE + 0x84) |
| 17 | #define CGU_ARC_FMEAS_ARC_START BIT(31) |
| 18 | #define CGU_ARC_FMEAS_ARC_DONE BIT(30) |
| 19 | #define CGU_ARC_FMEAS_ARC_CNT_MASK GENMASK(14, 0) |
| 20 | #define CGU_ARC_FMEAS_ARC_RCNT_OFFSET 0 |
| 21 | #define CGU_ARC_FMEAS_ARC_FCNT_OFFSET 15 |
| 22 | |
| 23 | #define SDIO_BASE (void *)(ARC_PERIPHERAL_BASE + 0x10000) |
| 24 | |
| 25 | int mach_cpu_init(void) |
| 26 | { |
| 27 | int rcnt, fcnt; |
| 28 | u32 data; |
| 29 | |
| 30 | /* Start frequency measurement */ |
| 31 | writel(CGU_ARC_FMEAS_ARC_START, CGU_ARC_FMEAS_ARC); |
| 32 | |
| 33 | /* Poll DONE bit */ |
| 34 | do { |
| 35 | data = readl(CGU_ARC_FMEAS_ARC); |
| 36 | } while (!(data & CGU_ARC_FMEAS_ARC_DONE)); |
| 37 | |
| 38 | /* Amount of reference 100 MHz clocks */ |
| 39 | rcnt = ((data >> CGU_ARC_FMEAS_ARC_RCNT_OFFSET) & |
| 40 | CGU_ARC_FMEAS_ARC_CNT_MASK); |
| 41 | |
| 42 | /* Amount of CPU clocks */ |
| 43 | fcnt = ((data >> CGU_ARC_FMEAS_ARC_FCNT_OFFSET) & |
| 44 | CGU_ARC_FMEAS_ARC_CNT_MASK); |
| 45 | |
| 46 | gd->cpu_clk = ((100 * fcnt) / rcnt) * 1000000; |
| 47 | |
| 48 | return 0; |
| 49 | } |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 50 | |
Alexey Brodkin | b347f75 | 2019-07-18 15:51:25 +0300 | [diff] [blame^] | 51 | int board_early_init_r(void) |
| 52 | { |
| 53 | #define EMSDP_PSRAM_BASE 0xf2001000 |
| 54 | #define PSRAM_FLASH_CONFIG_REG_0 (void *)(EMSDP_PSRAM_BASE + 0x10) |
| 55 | #define PSRAM_FLASH_CONFIG_REG_1 (void *)(EMSDP_PSRAM_BASE + 0x14) |
| 56 | #define CRE_ENABLE BIT(31) |
| 57 | #define CRE_DRIVE_CMD BIT(6) |
| 58 | |
| 59 | #define PSRAM_RCR_DPD BIT(1) |
| 60 | #define PSRAM_RCR_PAGE_MODE BIT(7) |
| 61 | |
| 62 | /* |
| 63 | * PSRAM_FLASH_CONFIG_REG_x[30:15] to the address lines[16:1] of flash, |
| 64 | * thus "<< 1". |
| 65 | */ |
| 66 | #define PSRAM_RCR_SETUP ((PSRAM_RCR_DPD | PSRAM_RCR_PAGE_MODE) << 1) |
| 67 | |
| 68 | // Switch PSRAM controller to command mode |
| 69 | writel(CRE_ENABLE | CRE_DRIVE_CMD, PSRAM_FLASH_CONFIG_REG_0); |
| 70 | // Program Refresh Configuration Register (RCR) for BANK0 |
| 71 | writew(0, (void *)(0x10000000 + PSRAM_RCR_SETUP)); |
| 72 | // Switch PSRAM controller back to memory mode |
| 73 | writel(0, PSRAM_FLASH_CONFIG_REG_0); |
| 74 | |
| 75 | |
| 76 | // Switch PSRAM controller to command mode |
| 77 | writel(CRE_ENABLE | CRE_DRIVE_CMD, PSRAM_FLASH_CONFIG_REG_1); |
| 78 | // Program Refresh Configuration Register (RCR) for BANK1 |
| 79 | writew(0, (void *)(0x10800000 + PSRAM_RCR_SETUP)); |
| 80 | // Switch PSRAM controller back to memory mode |
| 81 | writel(0, PSRAM_FLASH_CONFIG_REG_1); |
| 82 | |
| 83 | printf("PSRAM initialized.\n"); |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 88 | int board_mmc_init(bd_t *bis) |
| 89 | { |
| 90 | struct dwmci_host *host = NULL; |
| 91 | |
| 92 | host = malloc(sizeof(struct dwmci_host)); |
| 93 | if (!host) { |
| 94 | printf("dwmci_host malloc fail!\n"); |
| 95 | return 1; |
| 96 | } |
| 97 | |
| 98 | memset(host, 0, sizeof(struct dwmci_host)); |
| 99 | host->name = "Synopsys Mobile storage"; |
Alexey Brodkin | d4472c8 | 2018-11-27 09:46:59 +0300 | [diff] [blame] | 100 | host->ioaddr = SDIO_BASE; |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 101 | host->buswidth = 4; |
| 102 | host->dev_index = 0; |
| 103 | host->bus_hz = 50000000; |
| 104 | |
| 105 | add_dwmci(host, host->bus_hz / 2, 400000); |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
Alexey Brodkin | bb53735 | 2018-10-11 12:39:55 +0300 | [diff] [blame] | 110 | int board_mmc_getcd(struct mmc *mmc) |
| 111 | { |
| 112 | struct dwmci_host *host = mmc->priv; |
| 113 | |
| 114 | return !(dwmci_readl(host, DWMCI_CDETECT) & 1); |
| 115 | } |
| 116 | |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 117 | #define CREG_BASE 0xF0001000 |
Alexey Brodkin | 3cadcbd | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 118 | #define CREG_BOOT (void *)(CREG_BASE + 0x0FF0) |
| 119 | #define CREG_IP_SW_RESET (void *)(CREG_BASE + 0x0FF0) |
Alexey Brodkin | dbf9fa2 | 2018-11-27 09:47:01 +0300 | [diff] [blame] | 120 | #define CREG_IP_VERSION (void *)(CREG_BASE + 0x0FF8) |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 121 | |
Alexey Brodkin | 3cadcbd | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 122 | /* Bits in CREG_BOOT register */ |
| 123 | #define CREG_BOOT_WP_BIT BIT(8) |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 124 | |
| 125 | void reset_cpu(ulong addr) |
| 126 | { |
Alexey Brodkin | 3cadcbd | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 127 | writel(1, CREG_IP_SW_RESET); |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 128 | while (1) |
| 129 | ; /* loop forever till reset */ |
| 130 | } |
| 131 | |
Alexey Brodkin | ddbf697 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 132 | static int do_emsdp_rom(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 133 | { |
Alexey Brodkin | 3cadcbd | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 134 | u32 creg_boot = readl(CREG_BOOT); |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 135 | |
| 136 | if (!strcmp(argv[1], "unlock")) |
Alexey Brodkin | 3cadcbd | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 137 | creg_boot &= ~CREG_BOOT_WP_BIT; |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 138 | else if (!strcmp(argv[1], "lock")) |
Alexey Brodkin | 3cadcbd | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 139 | creg_boot |= CREG_BOOT_WP_BIT; |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 140 | else |
| 141 | return CMD_RET_USAGE; |
| 142 | |
Alexey Brodkin | 3cadcbd | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 143 | writel(creg_boot, CREG_BOOT); |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 144 | |
| 145 | return CMD_RET_SUCCESS; |
| 146 | } |
| 147 | |
Alexey Brodkin | ddbf697 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 148 | cmd_tbl_t cmd_emsdp[] = { |
| 149 | U_BOOT_CMD_MKENT(rom, 2, 0, do_emsdp_rom, "", ""), |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 150 | }; |
| 151 | |
Alexey Brodkin | ddbf697 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 152 | static int do_emsdp(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 153 | { |
| 154 | cmd_tbl_t *c; |
| 155 | |
Alexey Brodkin | ddbf697 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 156 | c = find_cmd_tbl(argv[1], cmd_emsdp, ARRAY_SIZE(cmd_emsdp)); |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 157 | |
Alexey Brodkin | ddbf697 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 158 | /* Strip off leading 'emsdp' command */ |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 159 | argc--; |
| 160 | argv++; |
| 161 | |
| 162 | if (c == NULL || argc > c->maxargs) |
| 163 | return CMD_RET_USAGE; |
| 164 | |
| 165 | return c->cmd(cmdtp, flag, argc, argv); |
| 166 | } |
| 167 | |
| 168 | U_BOOT_CMD( |
Alexey Brodkin | ddbf697 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 169 | emsdp, CONFIG_SYS_MAXARGS, 0, do_emsdp, |
| 170 | "Synopsys EMSDP specific commands", |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 171 | "rom unlock - Unlock non-volatile memory for writing\n" |
Alexey Brodkin | ddbf697 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 172 | "emsdp rom lock - Lock non-volatile memory to prevent writing\n" |
Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 173 | ); |
Alexey Brodkin | dbf9fa2 | 2018-11-27 09:47:01 +0300 | [diff] [blame] | 174 | |
| 175 | int checkboard(void) |
| 176 | { |
| 177 | int version = readl(CREG_IP_VERSION); |
| 178 | |
| 179 | printf("Board: ARC EM Software Development Platform v%d.%d\n", |
| 180 | (version >> 16) & 0xff, version & 0xff); |
| 181 | return 0; |
| 182 | }; |