Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 1 | /* |
Masahiro Yamada | 663a23f | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 2 | * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Masahiro Yamada | 663a23f | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 8 | #include <linux/io.h> |
Masahiro Yamada | 95387e2 | 2015-02-27 02:26:44 +0900 | [diff] [blame] | 9 | #include <mach/board.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 10 | |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 11 | #define MICRO_SUPPORT_CARD_RESET \ |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 12 | ((CONFIG_SUPPORT_CARD_BASE) + 0x000D0034) |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 13 | #define MICRO_SUPPORT_CARD_REVISION \ |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 14 | ((CONFIG_SUPPORT_CARD_BASE) + 0x000D00E0) |
| 15 | /* |
| 16 | * 0: reset deassert, 1: reset |
| 17 | * |
| 18 | * bit[0]: LAN, I2C, LED |
| 19 | * bit[1]: UART |
| 20 | */ |
| 21 | void support_card_reset_deassert(void) |
| 22 | { |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 23 | writel(0, MICRO_SUPPORT_CARD_RESET); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | void support_card_reset(void) |
| 27 | { |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 28 | writel(3, MICRO_SUPPORT_CARD_RESET); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static int support_card_show_revision(void) |
| 32 | { |
| 33 | u32 revision; |
| 34 | |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 35 | revision = readl(MICRO_SUPPORT_CARD_REVISION); |
| 36 | printf("(CPLD version %d.%d)\n", revision >> 4, revision & 0xf); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 37 | return 0; |
| 38 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 39 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 40 | int check_support_card(void) |
| 41 | { |
| 42 | printf("SC: Micro Support Card "); |
| 43 | return support_card_show_revision(); |
| 44 | } |
| 45 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 46 | void support_card_init(void) |
| 47 | { |
| 48 | /* |
| 49 | * After power on, we need to keep the LAN controller in reset state |
| 50 | * for a while. (200 usec) |
Masahiro Yamada | 5d3d996 | 2015-03-23 00:07:30 +0900 | [diff] [blame] | 51 | * Fortunately, enough wait time is already inserted in pll_init() |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 52 | * function. So we do not have to wait here. |
| 53 | */ |
| 54 | support_card_reset_deassert(); |
| 55 | } |
| 56 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 57 | #if defined(CONFIG_SMC911X) |
| 58 | #include <netdev.h> |
| 59 | |
| 60 | int board_eth_init(bd_t *bis) |
| 61 | { |
| 62 | return smc911x_initialize(0, CONFIG_SMC911X_BASE); |
| 63 | } |
| 64 | #endif |
| 65 | |
| 66 | #if !defined(CONFIG_SYS_NO_FLASH) |
| 67 | |
| 68 | #include <mtd/cfi_flash.h> |
Masahiro Yamada | 95387e2 | 2015-02-27 02:26:44 +0900 | [diff] [blame] | 69 | #include <mach/sbc-regs.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 70 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 71 | struct memory_bank { |
| 72 | phys_addr_t base; |
| 73 | unsigned long size; |
| 74 | }; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 75 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 76 | static int mem_is_flash(const struct memory_bank *mem) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 77 | { |
| 78 | const int loop = 128; |
| 79 | u32 *scratch_addr; |
| 80 | u32 saved_value; |
| 81 | int ret = 1; |
| 82 | int i; |
| 83 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 84 | /* just in case, use the tail of the memory bank */ |
| 85 | scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop, |
| 86 | sizeof(u32) * loop, MAP_NOCACHE); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 87 | |
| 88 | for (i = 0; i < loop; i++, scratch_addr++) { |
| 89 | saved_value = readl(scratch_addr); |
| 90 | writel(~saved_value, scratch_addr); |
| 91 | if (readl(scratch_addr) != saved_value) { |
| 92 | /* We assume no memory or SRAM here. */ |
| 93 | writel(saved_value, scratch_addr); |
| 94 | ret = 0; |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | unmap_physmem(scratch_addr, MAP_NOCACHE); |
| 100 | |
| 101 | return ret; |
| 102 | } |
| 103 | |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 104 | /* {address, size} */ |
| 105 | static const struct memory_bank memory_banks[] = { |
Masahiro Yamada | 4b275ea | 2015-09-11 20:17:47 +0900 | [diff] [blame^] | 106 | {0x42000000, 0x01f00000}, |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 107 | }; |
| 108 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 109 | static const struct memory_bank |
| 110 | *flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT]; |
| 111 | |
| 112 | phys_addr_t cfi_flash_bank_addr(int i) |
| 113 | { |
| 114 | return flash_banks_list[i]->base; |
| 115 | } |
| 116 | |
| 117 | unsigned long cfi_flash_bank_size(int i) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 118 | { |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 119 | return flash_banks_list[i]->size; |
| 120 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 121 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 122 | static void detect_num_flash_banks(void) |
| 123 | { |
| 124 | const struct memory_bank *memory_bank, *end; |
| 125 | |
| 126 | cfi_flash_num_flash_banks = 0; |
| 127 | |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 128 | memory_bank = memory_banks; |
| 129 | end = memory_bank + ARRAY_SIZE(memory_banks); |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 130 | |
| 131 | for (; memory_bank < end; memory_bank++) { |
| 132 | if (cfi_flash_num_flash_banks >= |
| 133 | CONFIG_SYS_MAX_FLASH_BANKS_DETECT) |
| 134 | break; |
| 135 | |
| 136 | if (mem_is_flash(memory_bank)) { |
| 137 | flash_banks_list[cfi_flash_num_flash_banks] = |
| 138 | memory_bank; |
| 139 | |
| 140 | debug("flash bank found: base = 0x%lx, size = 0x%lx\n", |
| 141 | memory_bank->base, memory_bank->size); |
| 142 | cfi_flash_num_flash_banks++; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 143 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 144 | } |
| 145 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 146 | debug("number of flash banks: %d\n", cfi_flash_num_flash_banks); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 147 | } |
Masahiro Yamada | 5d3d996 | 2015-03-23 00:07:30 +0900 | [diff] [blame] | 148 | #else /* CONFIG_SYS_NO_FLASH */ |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 149 | void detect_num_flash_banks(void) |
| 150 | { |
| 151 | }; |
Masahiro Yamada | 5d3d996 | 2015-03-23 00:07:30 +0900 | [diff] [blame] | 152 | #endif /* CONFIG_SYS_NO_FLASH */ |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 153 | |
| 154 | void support_card_late_init(void) |
| 155 | { |
| 156 | detect_num_flash_banks(); |
| 157 | } |