2 * Copyright (C) 2012-2015 Panasonic Corporation
3 * Copyright (C) 2015 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <mach/board.h>
13 #if defined(CONFIG_PFC_MICRO_SUPPORT_CARD)
15 #define PFC_MICRO_SUPPORT_CARD_RESET \
16 ((CONFIG_SUPPORT_CARD_BASE) + 0x000D0034)
17 #define PFC_MICRO_SUPPORT_CARD_REVISION \
18 ((CONFIG_SUPPORT_CARD_BASE) + 0x000D00E0)
20 * 0: reset deassert, 1: reset
22 * bit[0]: LAN, I2C, LED
25 void support_card_reset_deassert(void)
27 writel(0, PFC_MICRO_SUPPORT_CARD_RESET);
30 void support_card_reset(void)
32 writel(3, PFC_MICRO_SUPPORT_CARD_RESET);
35 static int support_card_show_revision(void)
39 revision = readl(PFC_MICRO_SUPPORT_CARD_REVISION);
40 printf("(PFC CPLD version %d.%d)\n", revision >> 4, revision & 0xf);
45 #if defined(CONFIG_DCC_MICRO_SUPPORT_CARD)
47 #define DCC_MICRO_SUPPORT_CARD_RESET_LAN \
48 ((CONFIG_SUPPORT_CARD_BASE) + 0x00401300)
49 #define DCC_MICRO_SUPPORT_CARD_RESET_UART \
50 ((CONFIG_SUPPORT_CARD_BASE) + 0x00401304)
51 #define DCC_MICRO_SUPPORT_CARD_RESET_I2C \
52 ((CONFIG_SUPPORT_CARD_BASE) + 0x00401308)
53 #define DCC_MICRO_SUPPORT_CARD_REVISION \
54 ((CONFIG_SUPPORT_CARD_BASE) + 0x005000E0)
56 void support_card_reset_deassert(void)
58 writel(1, DCC_MICRO_SUPPORT_CARD_RESET_LAN); /* LAN and LED */
59 writel(1, DCC_MICRO_SUPPORT_CARD_RESET_UART); /* UART */
60 writel(1, DCC_MICRO_SUPPORT_CARD_RESET_I2C); /* I2C */
63 void support_card_reset(void)
65 writel(0, DCC_MICRO_SUPPORT_CARD_RESET_LAN); /* LAN and LED */
66 writel(0, DCC_MICRO_SUPPORT_CARD_RESET_UART); /* UART */
67 writel(0, DCC_MICRO_SUPPORT_CARD_RESET_I2C); /* I2C */
70 static int support_card_show_revision(void)
74 revision = readl(DCC_MICRO_SUPPORT_CARD_REVISION);
76 if (revision >= 0x67) {
77 printf("(DCC CPLD version 3.%d.%d)\n",
78 revision >> 4, revision & 0xf);
81 printf("(DCC CPLD unknown version)\n");
87 int check_support_card(void)
89 printf("SC: Micro Support Card ");
90 return support_card_show_revision();
93 void support_card_init(void)
96 * After power on, we need to keep the LAN controller in reset state
97 * for a while. (200 usec)
98 * Fortunately, enough wait time is already inserted in pll_init()
99 * function. So we do not have to wait here.
101 support_card_reset_deassert();
104 #if defined(CONFIG_SMC911X)
107 int board_eth_init(bd_t *bis)
109 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
113 #if !defined(CONFIG_SYS_NO_FLASH)
115 #include <mtd/cfi_flash.h>
116 #include <mach/sbc-regs.h>
123 static int mem_is_flash(const struct memory_bank *mem)
125 const int loop = 128;
131 /* just in case, use the tail of the memory bank */
132 scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop,
133 sizeof(u32) * loop, MAP_NOCACHE);
135 for (i = 0; i < loop; i++, scratch_addr++) {
136 saved_value = readl(scratch_addr);
137 writel(~saved_value, scratch_addr);
138 if (readl(scratch_addr) != saved_value) {
139 /* We assume no memory or SRAM here. */
140 writel(saved_value, scratch_addr);
146 unmap_physmem(scratch_addr, MAP_NOCACHE);
151 #if defined(CONFIG_PFC_MICRO_SUPPORT_CARD)
152 /* {address, size} */
153 static const struct memory_bank memory_banks_boot_swap_off[] = {
154 {0x02000000, 0x01f00000},
157 static const struct memory_bank memory_banks_boot_swap_on[] = {
158 {0x00000000, 0x01f00000},
162 #if defined(CONFIG_DCC_MICRO_SUPPORT_CARD)
163 static const struct memory_bank memory_banks_boot_swap_off[] = {
164 {0x04000000, 0x02000000},
167 static const struct memory_bank memory_banks_boot_swap_on[] = {
168 {0x00000000, 0x02000000},
169 {0x04000000, 0x02000000},
173 static const struct memory_bank
174 *flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
176 phys_addr_t cfi_flash_bank_addr(int i)
178 return flash_banks_list[i]->base;
181 unsigned long cfi_flash_bank_size(int i)
183 return flash_banks_list[i]->size;
186 static void detect_num_flash_banks(void)
188 const struct memory_bank *memory_bank, *end;
190 cfi_flash_num_flash_banks = 0;
192 if (boot_is_swapped()) {
193 memory_bank = memory_banks_boot_swap_on;
194 end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_on);
196 memory_bank = memory_banks_boot_swap_off;
197 end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_off);
200 for (; memory_bank < end; memory_bank++) {
201 if (cfi_flash_num_flash_banks >=
202 CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
205 if (mem_is_flash(memory_bank)) {
206 flash_banks_list[cfi_flash_num_flash_banks] =
209 debug("flash bank found: base = 0x%lx, size = 0x%lx\n",
210 memory_bank->base, memory_bank->size);
211 cfi_flash_num_flash_banks++;
215 debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
217 #else /* CONFIG_SYS_NO_FLASH */
218 void detect_num_flash_banks(void)
221 #endif /* CONFIG_SYS_NO_FLASH */
223 void support_card_late_init(void)
225 detect_num_flash_banks();