2 * Copyright (C) 2012-2014 Panasonic Corporation
3 * Author: Masahiro Yamada <yamada.m@jp.panasonic.com>
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/arch/board.h>
12 #if defined(CONFIG_PFC_MICRO_SUPPORT_CARD)
14 #define PFC_MICRO_SUPPORT_CARD_RESET \
15 ((CONFIG_SUPPORT_CARD_BASE) + 0x000D0034)
16 #define PFC_MICRO_SUPPORT_CARD_REVISION \
17 ((CONFIG_SUPPORT_CARD_BASE) + 0x000D00E0)
19 * 0: reset deassert, 1: reset
21 * bit[0]: LAN, I2C, LED
24 void support_card_reset_deassert(void)
26 writel(0, PFC_MICRO_SUPPORT_CARD_RESET);
29 void support_card_reset(void)
31 writel(3, PFC_MICRO_SUPPORT_CARD_RESET);
34 static int support_card_show_revision(void)
38 revision = readl(PFC_MICRO_SUPPORT_CARD_REVISION);
39 printf("(PFC CPLD version %d.%d)\n", revision >> 4, revision & 0xf);
44 #if defined(CONFIG_DCC_MICRO_SUPPORT_CARD)
46 #define DCC_MICRO_SUPPORT_CARD_RESET_LAN \
47 ((CONFIG_SUPPORT_CARD_BASE) + 0x00401300)
48 #define DCC_MICRO_SUPPORT_CARD_RESET_UART \
49 ((CONFIG_SUPPORT_CARD_BASE) + 0x00401304)
50 #define DCC_MICRO_SUPPORT_CARD_RESET_I2C \
51 ((CONFIG_SUPPORT_CARD_BASE) + 0x00401308)
52 #define DCC_MICRO_SUPPORT_CARD_REVISION \
53 ((CONFIG_SUPPORT_CARD_BASE) + 0x005000E0)
55 void support_card_reset_deassert(void)
57 writel(1, DCC_MICRO_SUPPORT_CARD_RESET_LAN); /* LAN and LED */
58 writel(1, DCC_MICRO_SUPPORT_CARD_RESET_UART); /* UART */
59 writel(1, DCC_MICRO_SUPPORT_CARD_RESET_I2C); /* I2C */
62 void support_card_reset(void)
64 writel(0, DCC_MICRO_SUPPORT_CARD_RESET_LAN); /* LAN and LED */
65 writel(0, DCC_MICRO_SUPPORT_CARD_RESET_UART); /* UART */
66 writel(0, DCC_MICRO_SUPPORT_CARD_RESET_I2C); /* I2C */
69 static int support_card_show_revision(void)
73 revision = readl(DCC_MICRO_SUPPORT_CARD_REVISION);
75 if (revision >= 0x67) {
76 printf("(DCC CPLD version 3.%d.%d)\n",
77 revision >> 4, revision & 0xf);
80 printf("(DCC CPLD unknown version)\n");
86 int check_support_card(void)
88 printf("SC: Micro Support Card ");
89 return support_card_show_revision();
92 void support_card_init(void)
95 * After power on, we need to keep the LAN controller in reset state
96 * for a while. (200 usec)
97 * Fortunatelly, enough wait time is already inserted in pll_init()
98 * function. So we do not have to wait here.
100 support_card_reset_deassert();
103 #if defined(CONFIG_SMC911X)
106 int board_eth_init(bd_t *bis)
108 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
112 #if !defined(CONFIG_SYS_NO_FLASH)
114 #include <mtd/cfi_flash.h>
115 #include <asm/arch/sbc-regs.h>
122 static int mem_is_flash(const struct memory_bank *mem)
124 const int loop = 128;
130 /* just in case, use the tail of the memory bank */
131 scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop,
132 sizeof(u32) * loop, MAP_NOCACHE);
134 for (i = 0; i < loop; i++, scratch_addr++) {
135 saved_value = readl(scratch_addr);
136 writel(~saved_value, scratch_addr);
137 if (readl(scratch_addr) != saved_value) {
138 /* We assume no memory or SRAM here. */
139 writel(saved_value, scratch_addr);
145 unmap_physmem(scratch_addr, MAP_NOCACHE);
150 #if defined(CONFIG_PFC_MICRO_SUPPORT_CARD)
151 /* {address, size} */
152 static const struct memory_bank memory_banks_boot_swap_off[] = {
153 {0x02000000, 0x01f00000},
156 static const struct memory_bank memory_banks_boot_swap_on[] = {
157 {0x00000000, 0x01f00000},
161 #if defined(CONFIG_DCC_MICRO_SUPPORT_CARD)
162 static const struct memory_bank memory_banks_boot_swap_off[] = {
163 {0x04000000, 0x02000000},
166 static const struct memory_bank memory_banks_boot_swap_on[] = {
167 {0x00000000, 0x02000000},
168 {0x04000000, 0x02000000},
172 static const struct memory_bank
173 *flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
175 phys_addr_t cfi_flash_bank_addr(int i)
177 return flash_banks_list[i]->base;
180 unsigned long cfi_flash_bank_size(int i)
182 return flash_banks_list[i]->size;
185 static void detect_num_flash_banks(void)
187 const struct memory_bank *memory_bank, *end;
189 cfi_flash_num_flash_banks = 0;
191 if (boot_is_swapped()) {
192 memory_bank = memory_banks_boot_swap_on;
193 end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_on);
195 memory_bank = memory_banks_boot_swap_off;
196 end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_off);
199 for (; memory_bank < end; memory_bank++) {
200 if (cfi_flash_num_flash_banks >=
201 CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
204 if (mem_is_flash(memory_bank)) {
205 flash_banks_list[cfi_flash_num_flash_banks] =
208 debug("flash bank found: base = 0x%lx, size = 0x%lx\n",
209 memory_bank->base, memory_bank->size);
210 cfi_flash_num_flash_banks++;
214 debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
216 #else /* ONFIG_SYS_NO_FLASH */
217 void detect_num_flash_banks(void)
220 #endif /* ONFIG_SYS_NO_FLASH */
222 void support_card_late_init(void)
224 detect_num_flash_banks();