]>
Commit | Line | Data |
---|---|---|
5894ca00 | 1 | /* |
f6e7f07c | 2 | * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
5894ca00 MY |
3 | * |
4 | * SPDX-License-Identifier: GPL-2.0+ | |
5 | */ | |
6 | ||
7 | #include <common.h> | |
f6e7f07c | 8 | #include <linux/io.h> |
a86ac954 | 9 | #include <mach/board.h> |
5894ca00 | 10 | |
9879842c | 11 | #define MICRO_SUPPORT_CARD_RESET \ |
5894ca00 | 12 | ((CONFIG_SUPPORT_CARD_BASE) + 0x000D0034) |
9879842c | 13 | #define MICRO_SUPPORT_CARD_REVISION \ |
5894ca00 MY |
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 | { | |
9879842c | 23 | writel(0, MICRO_SUPPORT_CARD_RESET); |
5894ca00 MY |
24 | } |
25 | ||
26 | void support_card_reset(void) | |
27 | { | |
9879842c | 28 | writel(3, MICRO_SUPPORT_CARD_RESET); |
5894ca00 MY |
29 | } |
30 | ||
31 | static int support_card_show_revision(void) | |
32 | { | |
33 | u32 revision; | |
34 | ||
9879842c MY |
35 | revision = readl(MICRO_SUPPORT_CARD_REVISION); |
36 | printf("(CPLD version %d.%d)\n", revision >> 4, revision & 0xf); | |
5894ca00 MY |
37 | return 0; |
38 | } | |
5894ca00 | 39 | |
7a3620b2 MY |
40 | int check_support_card(void) |
41 | { | |
42 | printf("SC: Micro Support Card "); | |
43 | return support_card_show_revision(); | |
44 | } | |
45 | ||
5894ca00 MY |
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) | |
4d13b1b7 | 51 | * Fortunately, enough wait time is already inserted in pll_init() |
5894ca00 MY |
52 | * function. So we do not have to wait here. |
53 | */ | |
54 | support_card_reset_deassert(); | |
55 | } | |
56 | ||
5894ca00 MY |
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> | |
a86ac954 | 69 | #include <mach/sbc-regs.h> |
5894ca00 | 70 | |
7a3620b2 MY |
71 | struct memory_bank { |
72 | phys_addr_t base; | |
73 | unsigned long size; | |
74 | }; | |
5894ca00 | 75 | |
7a3620b2 | 76 | static int mem_is_flash(const struct memory_bank *mem) |
5894ca00 MY |
77 | { |
78 | const int loop = 128; | |
79 | u32 *scratch_addr; | |
80 | u32 saved_value; | |
81 | int ret = 1; | |
82 | int i; | |
83 | ||
7a3620b2 MY |
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); | |
5894ca00 MY |
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 | ||
9879842c MY |
104 | /* {address, size} */ |
105 | static const struct memory_bank memory_banks[] = { | |
7a3620b2 MY |
106 | {0x02000000, 0x01f00000}, |
107 | }; | |
108 | ||
7a3620b2 MY |
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) | |
5894ca00 | 113 | { |
7a3620b2 MY |
114 | return flash_banks_list[i]->base; |
115 | } | |
5894ca00 | 116 | |
7a3620b2 MY |
117 | unsigned long cfi_flash_bank_size(int i) |
118 | { | |
119 | return flash_banks_list[i]->size; | |
120 | } | |
121 | ||
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 | ||
9879842c MY |
128 | memory_bank = memory_banks; |
129 | end = memory_bank + ARRAY_SIZE(memory_banks); | |
7a3620b2 MY |
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++; | |
5894ca00 | 143 | } |
5894ca00 MY |
144 | } |
145 | ||
7a3620b2 MY |
146 | debug("number of flash banks: %d\n", cfi_flash_num_flash_banks); |
147 | } | |
4d13b1b7 | 148 | #else /* CONFIG_SYS_NO_FLASH */ |
7a3620b2 MY |
149 | void detect_num_flash_banks(void) |
150 | { | |
151 | }; | |
4d13b1b7 | 152 | #endif /* CONFIG_SYS_NO_FLASH */ |
7a3620b2 MY |
153 | |
154 | void support_card_late_init(void) | |
155 | { | |
156 | detect_num_flash_banks(); | |
5894ca00 | 157 | } |