Alexey Brodkin | 2c3f926 | 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 | 4e86c7e | 2018-11-27 09:46:59 +0300 | [diff] [blame] | 10 | #include <asm/arcregs.h> |
| 11 | |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
Alexey Brodkin | 4e86c7e | 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 | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 50 | |
| 51 | int board_mmc_init(bd_t *bis) |
| 52 | { |
| 53 | struct dwmci_host *host = NULL; |
| 54 | |
| 55 | host = malloc(sizeof(struct dwmci_host)); |
| 56 | if (!host) { |
| 57 | printf("dwmci_host malloc fail!\n"); |
| 58 | return 1; |
| 59 | } |
| 60 | |
| 61 | memset(host, 0, sizeof(struct dwmci_host)); |
| 62 | host->name = "Synopsys Mobile storage"; |
Alexey Brodkin | 4e86c7e | 2018-11-27 09:46:59 +0300 | [diff] [blame] | 63 | host->ioaddr = SDIO_BASE; |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 64 | host->buswidth = 4; |
| 65 | host->dev_index = 0; |
| 66 | host->bus_hz = 50000000; |
| 67 | |
| 68 | add_dwmci(host, host->bus_hz / 2, 400000); |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
Alexey Brodkin | 9f87d47 | 2018-10-11 12:39:55 +0300 | [diff] [blame] | 73 | int board_mmc_getcd(struct mmc *mmc) |
| 74 | { |
| 75 | struct dwmci_host *host = mmc->priv; |
| 76 | |
| 77 | return !(dwmci_readl(host, DWMCI_CDETECT) & 1); |
| 78 | } |
| 79 | |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 80 | #define CREG_BASE 0xF0001000 |
Alexey Brodkin | fb9a46a | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 81 | #define CREG_BOOT (void *)(CREG_BASE + 0x0FF0) |
| 82 | #define CREG_IP_SW_RESET (void *)(CREG_BASE + 0x0FF0) |
Alexey Brodkin | 6ef705b | 2018-11-27 09:47:01 +0300 | [diff] [blame^] | 83 | #define CREG_IP_VERSION (void *)(CREG_BASE + 0x0FF8) |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 84 | |
Alexey Brodkin | fb9a46a | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 85 | /* Bits in CREG_BOOT register */ |
| 86 | #define CREG_BOOT_WP_BIT BIT(8) |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 87 | |
| 88 | void reset_cpu(ulong addr) |
| 89 | { |
Alexey Brodkin | fb9a46a | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 90 | writel(1, CREG_IP_SW_RESET); |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 91 | while (1) |
| 92 | ; /* loop forever till reset */ |
| 93 | } |
| 94 | |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 95 | static int do_emsdp_rom(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 96 | { |
Alexey Brodkin | fb9a46a | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 97 | u32 creg_boot = readl(CREG_BOOT); |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 98 | |
| 99 | if (!strcmp(argv[1], "unlock")) |
Alexey Brodkin | fb9a46a | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 100 | creg_boot &= ~CREG_BOOT_WP_BIT; |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 101 | else if (!strcmp(argv[1], "lock")) |
Alexey Brodkin | fb9a46a | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 102 | creg_boot |= CREG_BOOT_WP_BIT; |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 103 | else |
| 104 | return CMD_RET_USAGE; |
| 105 | |
Alexey Brodkin | fb9a46a | 2018-11-27 09:47:00 +0300 | [diff] [blame] | 106 | writel(creg_boot, CREG_BOOT); |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 107 | |
| 108 | return CMD_RET_SUCCESS; |
| 109 | } |
| 110 | |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 111 | cmd_tbl_t cmd_emsdp[] = { |
| 112 | U_BOOT_CMD_MKENT(rom, 2, 0, do_emsdp_rom, "", ""), |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 113 | }; |
| 114 | |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 115 | static int do_emsdp(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 116 | { |
| 117 | cmd_tbl_t *c; |
| 118 | |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 119 | c = find_cmd_tbl(argv[1], cmd_emsdp, ARRAY_SIZE(cmd_emsdp)); |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 120 | |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 121 | /* Strip off leading 'emsdp' command */ |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 122 | argc--; |
| 123 | argv++; |
| 124 | |
| 125 | if (c == NULL || argc > c->maxargs) |
| 126 | return CMD_RET_USAGE; |
| 127 | |
| 128 | return c->cmd(cmdtp, flag, argc, argv); |
| 129 | } |
| 130 | |
| 131 | U_BOOT_CMD( |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 132 | emsdp, CONFIG_SYS_MAXARGS, 0, do_emsdp, |
| 133 | "Synopsys EMSDP specific commands", |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 134 | "rom unlock - Unlock non-volatile memory for writing\n" |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 135 | "emsdp rom lock - Lock non-volatile memory to prevent writing\n" |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 136 | ); |
Alexey Brodkin | 6ef705b | 2018-11-27 09:47:01 +0300 | [diff] [blame^] | 137 | |
| 138 | int checkboard(void) |
| 139 | { |
| 140 | int version = readl(CREG_IP_VERSION); |
| 141 | |
| 142 | printf("Board: ARC EM Software Development Platform v%d.%d\n", |
| 143 | (version >> 16) & 0xff, version & 0xff); |
| 144 | return 0; |
| 145 | }; |