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 |
| 81 | #define CREG_BOOT_OFFSET 0 |
| 82 | #define CREG_BOOT_WP_OFFSET 8 |
| 83 | |
| 84 | #define CGU_BASE 0xF0000000 |
| 85 | #define CGU_IP_SW_RESET 0x0FF0 |
| 86 | |
| 87 | void reset_cpu(ulong addr) |
| 88 | { |
| 89 | writel(1, (u32 *)(CGU_BASE + CGU_IP_SW_RESET)); |
| 90 | while (1) |
| 91 | ; /* loop forever till reset */ |
| 92 | } |
| 93 | |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 94 | 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] | 95 | { |
| 96 | u32 creg_boot = readl((u32 *)(CREG_BASE + CREG_BOOT_OFFSET)); |
| 97 | |
| 98 | if (!strcmp(argv[1], "unlock")) |
| 99 | creg_boot &= ~BIT(CREG_BOOT_WP_OFFSET); |
| 100 | else if (!strcmp(argv[1], "lock")) |
| 101 | creg_boot |= BIT(CREG_BOOT_WP_OFFSET); |
| 102 | else |
| 103 | return CMD_RET_USAGE; |
| 104 | |
| 105 | writel(creg_boot, (u32 *)(CREG_BASE + CREG_BOOT_OFFSET)); |
| 106 | |
| 107 | return CMD_RET_SUCCESS; |
| 108 | } |
| 109 | |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 110 | cmd_tbl_t cmd_emsdp[] = { |
| 111 | U_BOOT_CMD_MKENT(rom, 2, 0, do_emsdp_rom, "", ""), |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 112 | }; |
| 113 | |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 114 | 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] | 115 | { |
| 116 | cmd_tbl_t *c; |
| 117 | |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 118 | c = find_cmd_tbl(argv[1], cmd_emsdp, ARRAY_SIZE(cmd_emsdp)); |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 119 | |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 120 | /* Strip off leading 'emsdp' command */ |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 121 | argc--; |
| 122 | argv++; |
| 123 | |
| 124 | if (c == NULL || argc > c->maxargs) |
| 125 | return CMD_RET_USAGE; |
| 126 | |
| 127 | return c->cmd(cmdtp, flag, argc, argv); |
| 128 | } |
| 129 | |
| 130 | U_BOOT_CMD( |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 131 | emsdp, CONFIG_SYS_MAXARGS, 0, do_emsdp, |
| 132 | "Synopsys EMSDP specific commands", |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 133 | "rom unlock - Unlock non-volatile memory for writing\n" |
Alexey Brodkin | adc9b09 | 2018-10-18 09:54:58 +0300 | [diff] [blame] | 134 | "emsdp rom lock - Lock non-volatile memory to prevent writing\n" |
Alexey Brodkin | 2c3f926 | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 135 | ); |