xref: /openbmc/u-boot/board/synopsys/emsdp/emsdp.c (revision 8d773c4a)
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 
10 DECLARE_GLOBAL_DATA_PTR;
11 
12 #define ARC_PERIPHERAL_BASE	0xF0000000
13 #define SDIO_BASE		(ARC_PERIPHERAL_BASE + 0x10000)
14 
15 int 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 
37 int 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 
44 #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 
51 void 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 
58 static int do_emsdp_rom(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
59 {
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 
74 cmd_tbl_t cmd_emsdp[] = {
75 	U_BOOT_CMD_MKENT(rom, 2, 0, do_emsdp_rom, "", ""),
76 };
77 
78 static int do_emsdp(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
79 {
80 	cmd_tbl_t *c;
81 
82 	c = find_cmd_tbl(argv[1], cmd_emsdp, ARRAY_SIZE(cmd_emsdp));
83 
84 	/* Strip off leading 'emsdp' command */
85 	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 
94 U_BOOT_CMD(
95 	emsdp, CONFIG_SYS_MAXARGS, 0, do_emsdp,
96 	"Synopsys EMSDP specific commands",
97 	"rom unlock - Unlock non-volatile memory for writing\n"
98 	"emsdp rom lock - Lock non-volatile memory to prevent writing\n"
99 );
100