Alexey Brodkin | 4b2705b | 2018-05-28 15:27:43 +0300 | [diff] [blame] | 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 | #define CREG_BASE 0xF0001000 |
| 38 | #define CREG_BOOT_OFFSET 0 |
| 39 | #define CREG_BOOT_WP_OFFSET 8 |
| 40 | |
| 41 | #define CGU_BASE 0xF0000000 |
| 42 | #define CGU_IP_SW_RESET 0x0FF0 |
| 43 | |
| 44 | void reset_cpu(ulong addr) |
| 45 | { |
| 46 | writel(1, (u32 *)(CGU_BASE + CGU_IP_SW_RESET)); |
| 47 | while (1) |
| 48 | ; /* loop forever till reset */ |
| 49 | } |
| 50 | |
| 51 | static int do_emdk_rom(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 52 | { |
| 53 | u32 creg_boot = readl((u32 *)(CREG_BASE + CREG_BOOT_OFFSET)); |
| 54 | |
| 55 | if (!strcmp(argv[1], "unlock")) |
| 56 | creg_boot &= ~BIT(CREG_BOOT_WP_OFFSET); |
| 57 | else if (!strcmp(argv[1], "lock")) |
| 58 | creg_boot |= BIT(CREG_BOOT_WP_OFFSET); |
| 59 | else |
| 60 | return CMD_RET_USAGE; |
| 61 | |
| 62 | writel(creg_boot, (u32 *)(CREG_BASE + CREG_BOOT_OFFSET)); |
| 63 | |
| 64 | return CMD_RET_SUCCESS; |
| 65 | } |
| 66 | |
| 67 | cmd_tbl_t cmd_emdk[] = { |
| 68 | U_BOOT_CMD_MKENT(rom, 2, 0, do_emdk_rom, "", ""), |
| 69 | }; |
| 70 | |
| 71 | static int do_emdk(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 72 | { |
| 73 | cmd_tbl_t *c; |
| 74 | |
| 75 | c = find_cmd_tbl(argv[1], cmd_emdk, ARRAY_SIZE(cmd_emdk)); |
| 76 | |
| 77 | /* Strip off leading 'emdk' command */ |
| 78 | argc--; |
| 79 | argv++; |
| 80 | |
| 81 | if (c == NULL || argc > c->maxargs) |
| 82 | return CMD_RET_USAGE; |
| 83 | |
| 84 | return c->cmd(cmdtp, flag, argc, argv); |
| 85 | } |
| 86 | |
| 87 | U_BOOT_CMD( |
| 88 | emdk, CONFIG_SYS_MAXARGS, 0, do_emdk, |
| 89 | "Synopsys EMDK specific commands", |
| 90 | "rom unlock - Unlock non-volatile memory for writing\n" |
| 91 | "emdk rom lock - Lock non-volatile memory to prevent writing\n" |
| 92 | ); |