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 | 4e5d28d | 2015-09-22 00:27:31 +0900 | [diff] [blame^] | 8 | #include <linux/ctype.h> |
Masahiro Yamada | 663a23f | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 9 | #include <linux/io.h> |
Masahiro Yamada | 4e5d28d | 2015-09-22 00:27:31 +0900 | [diff] [blame^] | 10 | #include <mach/micro-support-card.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 11 | |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 12 | #define MICRO_SUPPORT_CARD_RESET \ |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 13 | ((CONFIG_SUPPORT_CARD_BASE) + 0x000D0034) |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 14 | #define MICRO_SUPPORT_CARD_REVISION \ |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 15 | ((CONFIG_SUPPORT_CARD_BASE) + 0x000D00E0) |
| 16 | /* |
| 17 | * 0: reset deassert, 1: reset |
| 18 | * |
| 19 | * bit[0]: LAN, I2C, LED |
| 20 | * bit[1]: UART |
| 21 | */ |
| 22 | void support_card_reset_deassert(void) |
| 23 | { |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 24 | writel(0, MICRO_SUPPORT_CARD_RESET); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | void support_card_reset(void) |
| 28 | { |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 29 | writel(3, MICRO_SUPPORT_CARD_RESET); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | static int support_card_show_revision(void) |
| 33 | { |
| 34 | u32 revision; |
| 35 | |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 36 | revision = readl(MICRO_SUPPORT_CARD_REVISION); |
| 37 | printf("(CPLD version %d.%d)\n", revision >> 4, revision & 0xf); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 38 | return 0; |
| 39 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 40 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 41 | int check_support_card(void) |
| 42 | { |
| 43 | printf("SC: Micro Support Card "); |
| 44 | return support_card_show_revision(); |
| 45 | } |
| 46 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 47 | void support_card_init(void) |
| 48 | { |
| 49 | /* |
| 50 | * After power on, we need to keep the LAN controller in reset state |
| 51 | * for a while. (200 usec) |
Masahiro Yamada | 5d3d996 | 2015-03-23 00:07:30 +0900 | [diff] [blame] | 52 | * Fortunately, enough wait time is already inserted in pll_init() |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 53 | * function. So we do not have to wait here. |
| 54 | */ |
| 55 | support_card_reset_deassert(); |
| 56 | } |
| 57 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 58 | #if defined(CONFIG_SMC911X) |
| 59 | #include <netdev.h> |
| 60 | |
| 61 | int board_eth_init(bd_t *bis) |
| 62 | { |
| 63 | return smc911x_initialize(0, CONFIG_SMC911X_BASE); |
| 64 | } |
| 65 | #endif |
| 66 | |
| 67 | #if !defined(CONFIG_SYS_NO_FLASH) |
| 68 | |
| 69 | #include <mtd/cfi_flash.h> |
Masahiro Yamada | 95387e2 | 2015-02-27 02:26:44 +0900 | [diff] [blame] | 70 | #include <mach/sbc-regs.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 71 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 72 | struct memory_bank { |
| 73 | phys_addr_t base; |
| 74 | unsigned long size; |
| 75 | }; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 76 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 77 | static int mem_is_flash(const struct memory_bank *mem) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 78 | { |
| 79 | const int loop = 128; |
| 80 | u32 *scratch_addr; |
| 81 | u32 saved_value; |
| 82 | int ret = 1; |
| 83 | int i; |
| 84 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 85 | /* just in case, use the tail of the memory bank */ |
| 86 | scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop, |
| 87 | sizeof(u32) * loop, MAP_NOCACHE); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 88 | |
| 89 | for (i = 0; i < loop; i++, scratch_addr++) { |
| 90 | saved_value = readl(scratch_addr); |
| 91 | writel(~saved_value, scratch_addr); |
| 92 | if (readl(scratch_addr) != saved_value) { |
| 93 | /* We assume no memory or SRAM here. */ |
| 94 | writel(saved_value, scratch_addr); |
| 95 | ret = 0; |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | unmap_physmem(scratch_addr, MAP_NOCACHE); |
| 101 | |
| 102 | return ret; |
| 103 | } |
| 104 | |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 105 | /* {address, size} */ |
| 106 | static const struct memory_bank memory_banks[] = { |
Masahiro Yamada | 4b275ea | 2015-09-11 20:17:47 +0900 | [diff] [blame] | 107 | {0x42000000, 0x01f00000}, |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 108 | }; |
| 109 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 110 | static const struct memory_bank |
| 111 | *flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT]; |
| 112 | |
| 113 | phys_addr_t cfi_flash_bank_addr(int i) |
| 114 | { |
| 115 | return flash_banks_list[i]->base; |
| 116 | } |
| 117 | |
| 118 | unsigned long cfi_flash_bank_size(int i) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 119 | { |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 120 | return flash_banks_list[i]->size; |
| 121 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 122 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 123 | static void detect_num_flash_banks(void) |
| 124 | { |
| 125 | const struct memory_bank *memory_bank, *end; |
| 126 | |
| 127 | cfi_flash_num_flash_banks = 0; |
| 128 | |
Masahiro Yamada | 4903b6d | 2015-09-11 20:17:45 +0900 | [diff] [blame] | 129 | memory_bank = memory_banks; |
| 130 | end = memory_bank + ARRAY_SIZE(memory_banks); |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 131 | |
| 132 | for (; memory_bank < end; memory_bank++) { |
| 133 | if (cfi_flash_num_flash_banks >= |
| 134 | CONFIG_SYS_MAX_FLASH_BANKS_DETECT) |
| 135 | break; |
| 136 | |
| 137 | if (mem_is_flash(memory_bank)) { |
| 138 | flash_banks_list[cfi_flash_num_flash_banks] = |
| 139 | memory_bank; |
| 140 | |
| 141 | debug("flash bank found: base = 0x%lx, size = 0x%lx\n", |
| 142 | memory_bank->base, memory_bank->size); |
| 143 | cfi_flash_num_flash_banks++; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 144 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 145 | } |
| 146 | |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 147 | debug("number of flash banks: %d\n", cfi_flash_num_flash_banks); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 148 | } |
Masahiro Yamada | 5d3d996 | 2015-03-23 00:07:30 +0900 | [diff] [blame] | 149 | #else /* CONFIG_SYS_NO_FLASH */ |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 150 | void detect_num_flash_banks(void) |
| 151 | { |
| 152 | }; |
Masahiro Yamada | 5d3d996 | 2015-03-23 00:07:30 +0900 | [diff] [blame] | 153 | #endif /* CONFIG_SYS_NO_FLASH */ |
Masahiro Yamada | 8821681 | 2014-12-06 00:03:26 +0900 | [diff] [blame] | 154 | |
| 155 | void support_card_late_init(void) |
| 156 | { |
| 157 | detect_num_flash_banks(); |
| 158 | } |
Masahiro Yamada | 4e5d28d | 2015-09-22 00:27:31 +0900 | [diff] [blame^] | 159 | |
| 160 | static const u8 ledval_num[] = { |
| 161 | 0x7e, /* 0 */ |
| 162 | 0x0c, /* 1 */ |
| 163 | 0xb6, /* 2 */ |
| 164 | 0x9e, /* 3 */ |
| 165 | 0xcc, /* 4 */ |
| 166 | 0xda, /* 5 */ |
| 167 | 0xfa, /* 6 */ |
| 168 | 0x4e, /* 7 */ |
| 169 | 0xfe, /* 8 */ |
| 170 | 0xde, /* 9 */ |
| 171 | }; |
| 172 | |
| 173 | static const u8 ledval_alpha[] = { |
| 174 | 0xee, /* A */ |
| 175 | 0xf8, /* B */ |
| 176 | 0x72, /* C */ |
| 177 | 0xbc, /* D */ |
| 178 | 0xf2, /* E */ |
| 179 | 0xe2, /* F */ |
| 180 | 0x7a, /* G */ |
| 181 | 0xe8, /* H */ |
| 182 | 0x08, /* I */ |
| 183 | 0x3c, /* J */ |
| 184 | 0xea, /* K */ |
| 185 | 0x70, /* L */ |
| 186 | 0x6e, /* M */ |
| 187 | 0xa8, /* N */ |
| 188 | 0xb8, /* O */ |
| 189 | 0xe6, /* P */ |
| 190 | 0xce, /* Q */ |
| 191 | 0xa0, /* R */ |
| 192 | 0xc8, /* S */ |
| 193 | 0x8c, /* T */ |
| 194 | 0x7c, /* U */ |
| 195 | 0x54, /* V */ |
| 196 | 0xfc, /* W */ |
| 197 | 0xec, /* X */ |
| 198 | 0xdc, /* Y */ |
| 199 | 0xa4, /* Z */ |
| 200 | }; |
| 201 | |
| 202 | static u8 char2ledval(char c) |
| 203 | { |
| 204 | if (isdigit(c)) |
| 205 | return ledval_num[c - '0']; |
| 206 | else if (isalpha(c)) |
| 207 | return ledval_alpha[toupper(c) - 'A']; |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | void led_puts(const char *s) |
| 213 | { |
| 214 | int i; |
| 215 | u32 val = 0; |
| 216 | |
| 217 | if (!s) |
| 218 | return; |
| 219 | |
| 220 | for (i = 0; i < 4; i++) { |
| 221 | val <<= 8; |
| 222 | val |= char2ledval(*s); |
| 223 | if (*s != '\0') |
| 224 | s++; |
| 225 | } |
| 226 | |
| 227 | writel(~val, CONFIG_SUPPORT_CARD_LED_BASE); |
| 228 | } |