blob: a3cee23411d0f720059b757bac3bea255ae551fe [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 Glass09140112020-05-10 11:40:03 -06007#include <command.h>
Simon Glass9a3b4ce2019-12-28 10:45:01 -07008#include <cpu_func.h>
Alexey Brodkin2c3f9262018-05-28 15:27:43 +03009#include <dwmmc.h>
Simon Glass691d7192020-05-10 11:40:02 -060010#include <init.h>
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030011#include <malloc.h>
Simon Glass401d1c42020-10-30 21:38:53 -060012#include <asm/global_data.h>
Simon Glasscd93d622020-05-10 11:40:13 -060013#include <linux/bitops.h>
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030014
Alexey Brodkin4e86c7e2018-11-27 09:46:59 +030015#include <asm/arcregs.h>
16
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030017DECLARE_GLOBAL_DATA_PTR;
18
Alexey Brodkin4e86c7e2018-11-27 09:46:59 +030019#define ARC_PERIPHERAL_BASE 0xF0000000
20
21#define CGU_ARC_FMEAS_ARC (void *)(ARC_PERIPHERAL_BASE + 0x84)
22#define CGU_ARC_FMEAS_ARC_START BIT(31)
23#define CGU_ARC_FMEAS_ARC_DONE BIT(30)
24#define CGU_ARC_FMEAS_ARC_CNT_MASK GENMASK(14, 0)
25#define CGU_ARC_FMEAS_ARC_RCNT_OFFSET 0
26#define CGU_ARC_FMEAS_ARC_FCNT_OFFSET 15
27
28#define SDIO_BASE (void *)(ARC_PERIPHERAL_BASE + 0x10000)
29
30int mach_cpu_init(void)
31{
32 int rcnt, fcnt;
33 u32 data;
34
35 /* Start frequency measurement */
36 writel(CGU_ARC_FMEAS_ARC_START, CGU_ARC_FMEAS_ARC);
37
38 /* Poll DONE bit */
39 do {
40 data = readl(CGU_ARC_FMEAS_ARC);
41 } while (!(data & CGU_ARC_FMEAS_ARC_DONE));
42
43 /* Amount of reference 100 MHz clocks */
44 rcnt = ((data >> CGU_ARC_FMEAS_ARC_RCNT_OFFSET) &
45 CGU_ARC_FMEAS_ARC_CNT_MASK);
46
47 /* Amount of CPU clocks */
48 fcnt = ((data >> CGU_ARC_FMEAS_ARC_FCNT_OFFSET) &
49 CGU_ARC_FMEAS_ARC_CNT_MASK);
50
51 gd->cpu_clk = ((100 * fcnt) / rcnt) * 1000000;
52
53 return 0;
54}
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030055
Alexey Brodkin9ddaf1d2019-07-18 15:51:25 +030056int board_early_init_r(void)
57{
58#define EMSDP_PSRAM_BASE 0xf2001000
59#define PSRAM_FLASH_CONFIG_REG_0 (void *)(EMSDP_PSRAM_BASE + 0x10)
60#define PSRAM_FLASH_CONFIG_REG_1 (void *)(EMSDP_PSRAM_BASE + 0x14)
61#define CRE_ENABLE BIT(31)
62#define CRE_DRIVE_CMD BIT(6)
63
64#define PSRAM_RCR_DPD BIT(1)
65#define PSRAM_RCR_PAGE_MODE BIT(7)
66
67/*
68 * PSRAM_FLASH_CONFIG_REG_x[30:15] to the address lines[16:1] of flash,
69 * thus "<< 1".
70 */
71#define PSRAM_RCR_SETUP ((PSRAM_RCR_DPD | PSRAM_RCR_PAGE_MODE) << 1)
72
73 // Switch PSRAM controller to command mode
74 writel(CRE_ENABLE | CRE_DRIVE_CMD, PSRAM_FLASH_CONFIG_REG_0);
75 // Program Refresh Configuration Register (RCR) for BANK0
76 writew(0, (void *)(0x10000000 + PSRAM_RCR_SETUP));
77 // Switch PSRAM controller back to memory mode
78 writel(0, PSRAM_FLASH_CONFIG_REG_0);
79
80
81 // Switch PSRAM controller to command mode
82 writel(CRE_ENABLE | CRE_DRIVE_CMD, PSRAM_FLASH_CONFIG_REG_1);
83 // Program Refresh Configuration Register (RCR) for BANK1
84 writew(0, (void *)(0x10800000 + PSRAM_RCR_SETUP));
85 // Switch PSRAM controller back to memory mode
86 writel(0, PSRAM_FLASH_CONFIG_REG_1);
87
88 printf("PSRAM initialized.\n");
89
90 return 0;
91}
92
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030093#define CREG_BASE 0xF0001000
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +030094#define CREG_BOOT (void *)(CREG_BASE + 0x0FF0)
95#define CREG_IP_SW_RESET (void *)(CREG_BASE + 0x0FF0)
Alexey Brodkin6ef705b2018-11-27 09:47:01 +030096#define CREG_IP_VERSION (void *)(CREG_BASE + 0x0FF8)
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030097
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +030098/* Bits in CREG_BOOT register */
99#define CREG_BOOT_WP_BIT BIT(8)
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300100
Harald Seiler35b65dd2020-12-15 16:47:52 +0100101void reset_cpu(void)
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300102{
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +0300103 writel(1, CREG_IP_SW_RESET);
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300104 while (1)
105 ; /* loop forever till reset */
106}
107
Simon Glass09140112020-05-10 11:40:03 -0600108static int do_emsdp_rom(struct cmd_tbl *cmdtp, int flag, int argc,
109 char *const argv[])
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300110{
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +0300111 u32 creg_boot = readl(CREG_BOOT);
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300112
113 if (!strcmp(argv[1], "unlock"))
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +0300114 creg_boot &= ~CREG_BOOT_WP_BIT;
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300115 else if (!strcmp(argv[1], "lock"))
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +0300116 creg_boot |= CREG_BOOT_WP_BIT;
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300117 else
118 return CMD_RET_USAGE;
119
Alexey Brodkinfb9a46a2018-11-27 09:47:00 +0300120 writel(creg_boot, CREG_BOOT);
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300121
122 return CMD_RET_SUCCESS;
123}
124
Simon Glass09140112020-05-10 11:40:03 -0600125struct cmd_tbl cmd_emsdp[] = {
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300126 U_BOOT_CMD_MKENT(rom, 2, 0, do_emsdp_rom, "", ""),
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300127};
128
Simon Glass09140112020-05-10 11:40:03 -0600129static int do_emsdp(struct cmd_tbl *cmdtp, int flag, int argc,
130 char *const argv[])
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300131{
Simon Glass09140112020-05-10 11:40:03 -0600132 struct cmd_tbl *c;
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300133
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300134 c = find_cmd_tbl(argv[1], cmd_emsdp, ARRAY_SIZE(cmd_emsdp));
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300135
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300136 /* Strip off leading 'emsdp' command */
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300137 argc--;
138 argv++;
139
140 if (c == NULL || argc > c->maxargs)
141 return CMD_RET_USAGE;
142
143 return c->cmd(cmdtp, flag, argc, argv);
144}
145
146U_BOOT_CMD(
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300147 emsdp, CONFIG_SYS_MAXARGS, 0, do_emsdp,
148 "Synopsys EMSDP specific commands",
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300149 "rom unlock - Unlock non-volatile memory for writing\n"
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300150 "emsdp rom lock - Lock non-volatile memory to prevent writing\n"
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300151);
Alexey Brodkin6ef705b2018-11-27 09:47:01 +0300152
153int checkboard(void)
154{
155 int version = readl(CREG_IP_VERSION);
156
157 printf("Board: ARC EM Software Development Platform v%d.%d\n",
158 (version >> 16) & 0xff, version & 0xff);
159 return 0;
160};