blob: c09ed8cff826d616febb252bc2cde7b6fd06c81d [file] [log] [blame]
Alexey Brodkin2c3f9262018-05-28 15:27:43 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018 Synopsys, Inc. All rights reserved.
4 */
5
6#include <common.h>
Simon Glass9a3b4ce2019-12-28 10:45:01 -07007#include <cpu_func.h>
Alexey Brodkin2c3f9262018-05-28 15:27:43 +03008#include <dwmmc.h>
9#include <malloc.h>
10
Alexey Brodkin4e86c7e2018-11-27 09:46:59 +030011#include <asm/arcregs.h>
12
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030013DECLARE_GLOBAL_DATA_PTR;
14
Alexey Brodkin4e86c7e2018-11-27 09:46:59 +030015#define ARC_PERIPHERAL_BASE 0xF0000000
16
17#define CGU_ARC_FMEAS_ARC (void *)(ARC_PERIPHERAL_BASE + 0x84)
18#define CGU_ARC_FMEAS_ARC_START BIT(31)
19#define CGU_ARC_FMEAS_ARC_DONE BIT(30)
20#define CGU_ARC_FMEAS_ARC_CNT_MASK GENMASK(14, 0)
21#define CGU_ARC_FMEAS_ARC_RCNT_OFFSET 0
22#define CGU_ARC_FMEAS_ARC_FCNT_OFFSET 15
23
24#define SDIO_BASE (void *)(ARC_PERIPHERAL_BASE + 0x10000)
25
26int mach_cpu_init(void)
27{
28 int rcnt, fcnt;
29 u32 data;
30
31 /* Start frequency measurement */
32 writel(CGU_ARC_FMEAS_ARC_START, CGU_ARC_FMEAS_ARC);
33
34 /* Poll DONE bit */
35 do {
36 data = readl(CGU_ARC_FMEAS_ARC);
37 } while (!(data & CGU_ARC_FMEAS_ARC_DONE));
38
39 /* Amount of reference 100 MHz clocks */
40 rcnt = ((data >> CGU_ARC_FMEAS_ARC_RCNT_OFFSET) &
41 CGU_ARC_FMEAS_ARC_CNT_MASK);
42
43 /* Amount of CPU clocks */
44 fcnt = ((data >> CGU_ARC_FMEAS_ARC_FCNT_OFFSET) &
45 CGU_ARC_FMEAS_ARC_CNT_MASK);
46
47 gd->cpu_clk = ((100 * fcnt) / rcnt) * 1000000;
48
49 return 0;
50}
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030051
Alexey Brodkin9ddaf1d2019-07-18 15:51:25 +030052int board_early_init_r(void)
53{
54#define EMSDP_PSRAM_BASE 0xf2001000
55#define PSRAM_FLASH_CONFIG_REG_0 (void *)(EMSDP_PSRAM_BASE + 0x10)
56#define PSRAM_FLASH_CONFIG_REG_1 (void *)(EMSDP_PSRAM_BASE + 0x14)
57#define CRE_ENABLE BIT(31)
58#define CRE_DRIVE_CMD BIT(6)
59
60#define PSRAM_RCR_DPD BIT(1)
61#define PSRAM_RCR_PAGE_MODE BIT(7)
62
63/*
64 * PSRAM_FLASH_CONFIG_REG_x[30:15] to the address lines[16:1] of flash,
65 * thus "<< 1".
66 */
67#define PSRAM_RCR_SETUP ((PSRAM_RCR_DPD | PSRAM_RCR_PAGE_MODE) << 1)
68
69 // Switch PSRAM controller to command mode
70 writel(CRE_ENABLE | CRE_DRIVE_CMD, PSRAM_FLASH_CONFIG_REG_0);
71 // Program Refresh Configuration Register (RCR) for BANK0
72 writew(0, (void *)(0x10000000 + PSRAM_RCR_SETUP));
73 // Switch PSRAM controller back to memory mode
74 writel(0, PSRAM_FLASH_CONFIG_REG_0);
75
76
77 // Switch PSRAM controller to command mode
78 writel(CRE_ENABLE | CRE_DRIVE_CMD, PSRAM_FLASH_CONFIG_REG_1);
79 // Program Refresh Configuration Register (RCR) for BANK1
80 writew(0, (void *)(0x10800000 + PSRAM_RCR_SETUP));
81 // Switch PSRAM controller back to memory mode
82 writel(0, PSRAM_FLASH_CONFIG_REG_1);
83
84 printf("PSRAM initialized.\n");
85
86 return 0;
87}
88
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030089#define CREG_BASE 0xF0001000
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +030090#define CREG_BOOT (void *)(CREG_BASE + 0x0FF0)
91#define CREG_IP_SW_RESET (void *)(CREG_BASE + 0x0FF0)
Alexey Brodkin6ef705b2018-11-27 09:47:01 +030092#define CREG_IP_VERSION (void *)(CREG_BASE + 0x0FF8)
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030093
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +030094/* Bits in CREG_BOOT register */
95#define CREG_BOOT_WP_BIT BIT(8)
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030096
97void reset_cpu(ulong addr)
98{
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +030099 writel(1, CREG_IP_SW_RESET);
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300100 while (1)
101 ; /* loop forever till reset */
102}
103
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300104static int do_emsdp_rom(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300105{
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +0300106 u32 creg_boot = readl(CREG_BOOT);
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300107
108 if (!strcmp(argv[1], "unlock"))
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +0300109 creg_boot &= ~CREG_BOOT_WP_BIT;
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300110 else if (!strcmp(argv[1], "lock"))
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +0300111 creg_boot |= CREG_BOOT_WP_BIT;
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300112 else
113 return CMD_RET_USAGE;
114
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +0300115 writel(creg_boot, CREG_BOOT);
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300116
117 return CMD_RET_SUCCESS;
118}
119
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300120cmd_tbl_t cmd_emsdp[] = {
121 U_BOOT_CMD_MKENT(rom, 2, 0, do_emsdp_rom, "", ""),
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300122};
123
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300124static int do_emsdp(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300125{
126 cmd_tbl_t *c;
127
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300128 c = find_cmd_tbl(argv[1], cmd_emsdp, ARRAY_SIZE(cmd_emsdp));
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300129
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300130 /* Strip off leading 'emsdp' command */
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300131 argc--;
132 argv++;
133
134 if (c == NULL || argc > c->maxargs)
135 return CMD_RET_USAGE;
136
137 return c->cmd(cmdtp, flag, argc, argv);
138}
139
140U_BOOT_CMD(
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300141 emsdp, CONFIG_SYS_MAXARGS, 0, do_emsdp,
142 "Synopsys EMSDP specific commands",
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300143 "rom unlock - Unlock non-volatile memory for writing\n"
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300144 "emsdp rom lock - Lock non-volatile memory to prevent writing\n"
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300145);
Alexey Brodkin6ef705b2018-11-27 09:47:01 +0300146
147int checkboard(void)
148{
149 int version = readl(CREG_IP_VERSION);
150
151 printf("Board: ARC EM Software Development Platform v%d.%d\n",
152 (version >> 16) & 0xff, version & 0xff);
153 return 0;
154};