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 | |
| 11 | #if defined(CONFIG_PFC_MICRO_SUPPORT_CARD) |
| 12 | |
| 13 | #define PFC_MICRO_SUPPORT_CARD_RESET \ |
| 14 | ((CONFIG_SUPPORT_CARD_BASE) + 0x000D0034) |
| 15 | #define PFC_MICRO_SUPPORT_CARD_REVISION \ |
| 16 | ((CONFIG_SUPPORT_CARD_BASE) + 0x000D00E0) |
| 17 | /* |
| 18 | * 0: reset deassert, 1: reset |
| 19 | * |
| 20 | * bit[0]: LAN, I2C, LED |
| 21 | * bit[1]: UART |
| 22 | */ |
| 23 | void support_card_reset_deassert(void) |
| 24 | { |
| 25 | writel(0, PFC_MICRO_SUPPORT_CARD_RESET); |
| 26 | } |
| 27 | |
| 28 | void support_card_reset(void) |
| 29 | { |
| 30 | writel(3, PFC_MICRO_SUPPORT_CARD_RESET); |
| 31 | } |
| 32 | |
| 33 | static int support_card_show_revision(void) |
| 34 | { |
| 35 | u32 revision; |
| 36 | |
| 37 | revision = readl(PFC_MICRO_SUPPORT_CARD_REVISION); |
| 38 | printf("(PFC CPLD version %d.%d)\n", revision >> 4, revision & 0xf); |
| 39 | return 0; |
| 40 | } |
| 41 | #endif |
| 42 | |
| 43 | #if defined(CONFIG_DCC_MICRO_SUPPORT_CARD) |
| 44 | |
| 45 | #define DCC_MICRO_SUPPORT_CARD_RESET_LAN \ |
| 46 | ((CONFIG_SUPPORT_CARD_BASE) + 0x00401300) |
| 47 | #define DCC_MICRO_SUPPORT_CARD_RESET_UART \ |
| 48 | ((CONFIG_SUPPORT_CARD_BASE) + 0x00401304) |
| 49 | #define DCC_MICRO_SUPPORT_CARD_RESET_I2C \ |
| 50 | ((CONFIG_SUPPORT_CARD_BASE) + 0x00401308) |
| 51 | #define DCC_MICRO_SUPPORT_CARD_REVISION \ |
| 52 | ((CONFIG_SUPPORT_CARD_BASE) + 0x005000E0) |
| 53 | |
| 54 | void support_card_reset_deassert(void) |
| 55 | { |
| 56 | writel(1, DCC_MICRO_SUPPORT_CARD_RESET_LAN); /* LAN and LED */ |
| 57 | writel(1, DCC_MICRO_SUPPORT_CARD_RESET_UART); /* UART */ |
| 58 | writel(1, DCC_MICRO_SUPPORT_CARD_RESET_I2C); /* I2C */ |
| 59 | } |
| 60 | |
| 61 | void support_card_reset(void) |
| 62 | { |
| 63 | writel(0, DCC_MICRO_SUPPORT_CARD_RESET_LAN); /* LAN and LED */ |
| 64 | writel(0, DCC_MICRO_SUPPORT_CARD_RESET_UART); /* UART */ |
| 65 | writel(0, DCC_MICRO_SUPPORT_CARD_RESET_I2C); /* I2C */ |
| 66 | } |
| 67 | |
| 68 | static int support_card_show_revision(void) |
| 69 | { |
| 70 | u32 revision; |
| 71 | |
| 72 | revision = readl(DCC_MICRO_SUPPORT_CARD_REVISION); |
| 73 | |
| 74 | if (revision >= 0x67) { |
| 75 | printf("(DCC CPLD version 3.%d.%d)\n", |
| 76 | revision >> 4, revision & 0xf); |
| 77 | return 0; |
| 78 | } else { |
| 79 | printf("(DCC CPLD unknown version)\n"); |
| 80 | return -1; |
| 81 | } |
| 82 | } |
| 83 | #endif |
| 84 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 85 | int check_support_card(void) |
| 86 | { |
| 87 | printf("SC: Micro Support Card "); |
| 88 | return support_card_show_revision(); |
| 89 | } |
| 90 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 91 | void support_card_init(void) |
| 92 | { |
| 93 | /* |
| 94 | * After power on, we need to keep the LAN controller in reset state |
| 95 | * for a while. (200 usec) |
Masahiro Yamada | 5d3d996 | 2015-03-23 00:07:30 +0900 | [diff] [blame] | 96 | * Fortunately, enough wait time is already inserted in pll_init() |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 97 | * function. So we do not have to wait here. |
| 98 | */ |
| 99 | support_card_reset_deassert(); |
| 100 | } |
| 101 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 102 | #if defined(CONFIG_SMC911X) |
| 103 | #include <netdev.h> |
| 104 | |
| 105 | int board_eth_init(bd_t *bis) |
| 106 | { |
| 107 | return smc911x_initialize(0, CONFIG_SMC911X_BASE); |
| 108 | } |
| 109 | #endif |
| 110 | |
| 111 | #if !defined(CONFIG_SYS_NO_FLASH) |
| 112 | |
| 113 | #include <mtd/cfi_flash.h> |
Masahiro Yamada | 95387e2 | 2015-02-27 02:26:44 +0900 | [diff] [blame] | 114 | #include <mach/sbc-regs.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 115 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 116 | struct memory_bank { |
| 117 | phys_addr_t base; |
| 118 | unsigned long size; |
| 119 | }; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 120 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 121 | static int mem_is_flash(const struct memory_bank *mem) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 122 | { |
| 123 | const int loop = 128; |
| 124 | u32 *scratch_addr; |
| 125 | u32 saved_value; |
| 126 | int ret = 1; |
| 127 | int i; |
| 128 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 129 | /* just in case, use the tail of the memory bank */ |
| 130 | scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop, |
| 131 | sizeof(u32) * loop, MAP_NOCACHE); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 132 | |
| 133 | for (i = 0; i < loop; i++, scratch_addr++) { |
| 134 | saved_value = readl(scratch_addr); |
| 135 | writel(~saved_value, scratch_addr); |
| 136 | if (readl(scratch_addr) != saved_value) { |
| 137 | /* We assume no memory or SRAM here. */ |
| 138 | writel(saved_value, scratch_addr); |
| 139 | ret = 0; |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | unmap_physmem(scratch_addr, MAP_NOCACHE); |
| 145 | |
| 146 | return ret; |
| 147 | } |
| 148 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 149 | #if defined(CONFIG_PFC_MICRO_SUPPORT_CARD) |
| 150 | /* {address, size} */ |
| 151 | static const struct memory_bank memory_banks_boot_swap_off[] = { |
| 152 | {0x02000000, 0x01f00000}, |
| 153 | }; |
| 154 | |
| 155 | static const struct memory_bank memory_banks_boot_swap_on[] = { |
| 156 | {0x00000000, 0x01f00000}, |
| 157 | }; |
| 158 | #endif |
| 159 | |
| 160 | #if defined(CONFIG_DCC_MICRO_SUPPORT_CARD) |
| 161 | static const struct memory_bank memory_banks_boot_swap_off[] = { |
Masahiro Yamada | b92dabe | 2015-01-06 14:18:57 +0900 | [diff] [blame] | 162 | {0x04000000, 0x02000000}, |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | static const struct memory_bank memory_banks_boot_swap_on[] = { |
Masahiro Yamada | b92dabe | 2015-01-06 14:18:57 +0900 | [diff] [blame] | 166 | {0x00000000, 0x02000000}, |
| 167 | {0x04000000, 0x02000000}, |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 168 | }; |
| 169 | #endif |
| 170 | |
| 171 | static const struct memory_bank |
| 172 | *flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT]; |
| 173 | |
| 174 | phys_addr_t cfi_flash_bank_addr(int i) |
| 175 | { |
| 176 | return flash_banks_list[i]->base; |
| 177 | } |
| 178 | |
| 179 | unsigned long cfi_flash_bank_size(int i) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 180 | { |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 181 | return flash_banks_list[i]->size; |
| 182 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 183 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 184 | static void detect_num_flash_banks(void) |
| 185 | { |
| 186 | const struct memory_bank *memory_bank, *end; |
| 187 | |
| 188 | cfi_flash_num_flash_banks = 0; |
| 189 | |
| 190 | if (boot_is_swapped()) { |
| 191 | memory_bank = memory_banks_boot_swap_on; |
| 192 | end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_on); |
| 193 | } else { |
| 194 | memory_bank = memory_banks_boot_swap_off; |
| 195 | end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_off); |
| 196 | } |
| 197 | |
| 198 | for (; memory_bank < end; memory_bank++) { |
| 199 | if (cfi_flash_num_flash_banks >= |
| 200 | CONFIG_SYS_MAX_FLASH_BANKS_DETECT) |
| 201 | break; |
| 202 | |
| 203 | if (mem_is_flash(memory_bank)) { |
| 204 | flash_banks_list[cfi_flash_num_flash_banks] = |
| 205 | memory_bank; |
| 206 | |
| 207 | debug("flash bank found: base = 0x%lx, size = 0x%lx\n", |
| 208 | memory_bank->base, memory_bank->size); |
| 209 | cfi_flash_num_flash_banks++; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 210 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 211 | } |
| 212 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 213 | debug("number of flash banks: %d\n", cfi_flash_num_flash_banks); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 214 | } |
Masahiro Yamada | 5d3d996 | 2015-03-23 00:07:30 +0900 | [diff] [blame] | 215 | #else /* CONFIG_SYS_NO_FLASH */ |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 216 | void detect_num_flash_banks(void) |
| 217 | { |
| 218 | }; |
Masahiro Yamada | 5d3d996 | 2015-03-23 00:07:30 +0900 | [diff] [blame] | 219 | #endif /* CONFIG_SYS_NO_FLASH */ |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 220 | |
| 221 | void support_card_late_init(void) |
| 222 | { |
| 223 | detect_num_flash_banks(); |
| 224 | } |