2 * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <mach/board.h>
11 #if defined(CONFIG_PFC_MICRO_SUPPORT_CARD)
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)
18 * 0: reset deassert, 1: reset
20 * bit[0]: LAN, I2C, LED
23 void support_card_reset_deassert(void)
25 writel(0, PFC_MICRO_SUPPORT_CARD_RESET);
28 void support_card_reset(void)
30 writel(3, PFC_MICRO_SUPPORT_CARD_RESET);
33 static int support_card_show_revision(void)
37 revision = readl(PFC_MICRO_SUPPORT_CARD_REVISION);
38 printf("(PFC CPLD version %d.%d)\n", revision >> 4, revision & 0xf);
43 #if defined(CONFIG_DCC_MICRO_SUPPORT_CARD)
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)
54 void support_card_reset_deassert(void)
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 */
61 void support_card_reset(void)
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 */
68 static int support_card_show_revision(void)
72 revision = readl(DCC_MICRO_SUPPORT_CARD_REVISION);
74 if (revision >= 0x67) {
75 printf("(DCC CPLD version 3.%d.%d)\n",
76 revision >> 4, revision & 0xf);
79 printf("(DCC CPLD unknown version)\n");
85 int check_support_card(void)
87 printf("SC: Micro Support Card ");
88 return support_card_show_revision();
91 void support_card_init(void)
94 * After power on, we need to keep the LAN controller in reset state
95 * for a while. (200 usec)
96 * Fortunately, enough wait time is already inserted in pll_init()
97 * function. So we do not have to wait here.
99 support_card_reset_deassert();
102 #if defined(CONFIG_SMC911X)
105 int board_eth_init(bd_t *bis)
107 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
111 #if !defined(CONFIG_SYS_NO_FLASH)
113 #include <mtd/cfi_flash.h>
114 #include <mach/sbc-regs.h>
121 static int mem_is_flash(const struct memory_bank *mem)
123 const int loop = 128;
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);
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);
144 unmap_physmem(scratch_addr, MAP_NOCACHE);
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},
155 static const struct memory_bank memory_banks_boot_swap_on[] = {
156 {0x00000000, 0x01f00000},
160 #if defined(CONFIG_DCC_MICRO_SUPPORT_CARD)
161 static const struct memory_bank memory_banks_boot_swap_off[] = {
162 {0x04000000, 0x02000000},
165 static const struct memory_bank memory_banks_boot_swap_on[] = {
166 {0x00000000, 0x02000000},
167 {0x04000000, 0x02000000},
171 static const struct memory_bank
172 *flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
174 phys_addr_t cfi_flash_bank_addr(int i)
176 return flash_banks_list[i]->base;
179 unsigned long cfi_flash_bank_size(int i)
181 return flash_banks_list[i]->size;
184 static void detect_num_flash_banks(void)
186 const struct memory_bank *memory_bank, *end;
188 cfi_flash_num_flash_banks = 0;
190 if (boot_is_swapped()) {
191 memory_bank = memory_banks_boot_swap_on;
192 end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_on);
194 memory_bank = memory_banks_boot_swap_off;
195 end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_off);
198 for (; memory_bank < end; memory_bank++) {
199 if (cfi_flash_num_flash_banks >=
200 CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
203 if (mem_is_flash(memory_bank)) {
204 flash_banks_list[cfi_flash_num_flash_banks] =
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++;
213 debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
215 #else /* CONFIG_SYS_NO_FLASH */
216 void detect_num_flash_banks(void)
219 #endif /* CONFIG_SYS_NO_FLASH */
221 void support_card_late_init(void)
223 detect_num_flash_banks();