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