blob: b5ec7f17ec1b35c4f6a79ec639bf9497a58da6c3 [file] [log] [blame]
Alexey Brodkin4b2705b2018-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
10DECLARE_GLOBAL_DATA_PTR;
11
12#define ARC_PERIPHERAL_BASE 0xF0000000
13#define SDIO_BASE (ARC_PERIPHERAL_BASE + 0x10000)
14
15int board_mmc_init(bd_t *bis)
16{
17 struct dwmci_host *host = NULL;
18
19 host = malloc(sizeof(struct dwmci_host));
20 if (!host) {
21 printf("dwmci_host malloc fail!\n");
22 return 1;
23 }
24
25 memset(host, 0, sizeof(struct dwmci_host));
26 host->name = "Synopsys Mobile storage";
27 host->ioaddr = (void *)SDIO_BASE;
28 host->buswidth = 4;
29 host->dev_index = 0;
30 host->bus_hz = 50000000;
31
32 add_dwmci(host, host->bus_hz / 2, 400000);
33
34 return 0;
35}
36
Alexey Brodkinbb537352018-10-11 12:39:55 +030037int board_mmc_getcd(struct mmc *mmc)
38{
39 struct dwmci_host *host = mmc->priv;
40
41 return !(dwmci_readl(host, DWMCI_CDETECT) & 1);
42}
43
Alexey Brodkin4b2705b2018-05-28 15:27:43 +030044#define CREG_BASE 0xF0001000
45#define CREG_BOOT_OFFSET 0
46#define CREG_BOOT_WP_OFFSET 8
47
48#define CGU_BASE 0xF0000000
49#define CGU_IP_SW_RESET 0x0FF0
50
51void reset_cpu(ulong addr)
52{
53 writel(1, (u32 *)(CGU_BASE + CGU_IP_SW_RESET));
54 while (1)
55 ; /* loop forever till reset */
56}
57
Alexey Brodkinddbf6972018-10-18 09:54:58 +030058static int do_emsdp_rom(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
Alexey Brodkin4b2705b2018-05-28 15:27:43 +030059{
60 u32 creg_boot = readl((u32 *)(CREG_BASE + CREG_BOOT_OFFSET));
61
62 if (!strcmp(argv[1], "unlock"))
63 creg_boot &= ~BIT(CREG_BOOT_WP_OFFSET);
64 else if (!strcmp(argv[1], "lock"))
65 creg_boot |= BIT(CREG_BOOT_WP_OFFSET);
66 else
67 return CMD_RET_USAGE;
68
69 writel(creg_boot, (u32 *)(CREG_BASE + CREG_BOOT_OFFSET));
70
71 return CMD_RET_SUCCESS;
72}
73
Alexey Brodkinddbf6972018-10-18 09:54:58 +030074cmd_tbl_t cmd_emsdp[] = {
75 U_BOOT_CMD_MKENT(rom, 2, 0, do_emsdp_rom, "", ""),
Alexey Brodkin4b2705b2018-05-28 15:27:43 +030076};
77
Alexey Brodkinddbf6972018-10-18 09:54:58 +030078static int do_emsdp(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
Alexey Brodkin4b2705b2018-05-28 15:27:43 +030079{
80 cmd_tbl_t *c;
81
Alexey Brodkinddbf6972018-10-18 09:54:58 +030082 c = find_cmd_tbl(argv[1], cmd_emsdp, ARRAY_SIZE(cmd_emsdp));
Alexey Brodkin4b2705b2018-05-28 15:27:43 +030083
Alexey Brodkinddbf6972018-10-18 09:54:58 +030084 /* Strip off leading 'emsdp' command */
Alexey Brodkin4b2705b2018-05-28 15:27:43 +030085 argc--;
86 argv++;
87
88 if (c == NULL || argc > c->maxargs)
89 return CMD_RET_USAGE;
90
91 return c->cmd(cmdtp, flag, argc, argv);
92}
93
94U_BOOT_CMD(
Alexey Brodkinddbf6972018-10-18 09:54:58 +030095 emsdp, CONFIG_SYS_MAXARGS, 0, do_emsdp,
96 "Synopsys EMSDP specific commands",
Alexey Brodkin4b2705b2018-05-28 15:27:43 +030097 "rom unlock - Unlock non-volatile memory for writing\n"
Alexey Brodkinddbf6972018-10-18 09:54:58 +030098 "emsdp rom lock - Lock non-volatile memory to prevent writing\n"
Alexey Brodkin4b2705b2018-05-28 15:27:43 +030099);