blob: 5ab44353746b1b0b92cca798e12550d508663281 [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>
7#include <dwmmc.h>
8#include <malloc.h>
9
Alexey Brodkin4e86c7e2018-11-27 09:46:59 +030010#include <asm/arcregs.h>
11
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030012DECLARE_GLOBAL_DATA_PTR;
13
Alexey Brodkin4e86c7e2018-11-27 09:46:59 +030014#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
25int 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 Brodkin2c3f9262018-05-28 15:27:43 +030050
51int 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 Brodkin4e86c7e2018-11-27 09:46:59 +030063 host->ioaddr = SDIO_BASE;
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030064 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 Brodkin9f87d472018-10-11 12:39:55 +030073int 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 Brodkin2c3f9262018-05-28 15:27:43 +030080#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
87void 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 Brodkinadc9b092018-10-18 09:54:58 +030094static int do_emsdp_rom(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
Alexey Brodkin2c3f9262018-05-28 15:27:43 +030095{
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 Brodkinadc9b092018-10-18 09:54:58 +0300110cmd_tbl_t cmd_emsdp[] = {
111 U_BOOT_CMD_MKENT(rom, 2, 0, do_emsdp_rom, "", ""),
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300112};
113
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300114static int do_emsdp(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300115{
116 cmd_tbl_t *c;
117
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300118 c = find_cmd_tbl(argv[1], cmd_emsdp, ARRAY_SIZE(cmd_emsdp));
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300119
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300120 /* Strip off leading 'emsdp' command */
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300121 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
130U_BOOT_CMD(
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300131 emsdp, CONFIG_SYS_MAXARGS, 0, do_emsdp,
132 "Synopsys EMSDP specific commands",
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300133 "rom unlock - Unlock non-volatile memory for writing\n"
Alexey Brodkinadc9b092018-10-18 09:54:58 +0300134 "emsdp rom lock - Lock non-volatile memory to prevent writing\n"
Alexey Brodkin2c3f9262018-05-28 15:27:43 +0300135);