blob: e7b4158636827a7ac66f7ddad4d00ed0381ba4ed [file] [log] [blame]
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09001/*
2 * Copyright (C) 2012-2014 Panasonic Corporation
3 * Author: Masahiro Yamada <yamada.m@jp.panasonic.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <asm/io.h>
Masahiro Yamada95387e22015-02-27 02:26:44 +090010#include <mach/board.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090011
12#if defined(CONFIG_PFC_MICRO_SUPPORT_CARD)
13
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)
18/*
19 * 0: reset deassert, 1: reset
20 *
21 * bit[0]: LAN, I2C, LED
22 * bit[1]: UART
23 */
24void support_card_reset_deassert(void)
25{
26 writel(0, PFC_MICRO_SUPPORT_CARD_RESET);
27}
28
29void support_card_reset(void)
30{
31 writel(3, PFC_MICRO_SUPPORT_CARD_RESET);
32}
33
34static int support_card_show_revision(void)
35{
36 u32 revision;
37
38 revision = readl(PFC_MICRO_SUPPORT_CARD_REVISION);
39 printf("(PFC CPLD version %d.%d)\n", revision >> 4, revision & 0xf);
40 return 0;
41}
42#endif
43
44#if defined(CONFIG_DCC_MICRO_SUPPORT_CARD)
45
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)
54
55void support_card_reset_deassert(void)
56{
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 */
60}
61
62void support_card_reset(void)
63{
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 */
67}
68
69static int support_card_show_revision(void)
70{
71 u32 revision;
72
73 revision = readl(DCC_MICRO_SUPPORT_CARD_REVISION);
74
75 if (revision >= 0x67) {
76 printf("(DCC CPLD version 3.%d.%d)\n",
77 revision >> 4, revision & 0xf);
78 return 0;
79 } else {
80 printf("(DCC CPLD unknown version)\n");
81 return -1;
82 }
83}
84#endif
85
Masahiro Yamada88216812014-12-06 00:03:26 +090086int check_support_card(void)
87{
88 printf("SC: Micro Support Card ");
89 return support_card_show_revision();
90}
91
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090092void support_card_init(void)
93{
94 /*
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.
99 */
100 support_card_reset_deassert();
101}
102
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900103#if defined(CONFIG_SMC911X)
104#include <netdev.h>
105
106int board_eth_init(bd_t *bis)
107{
108 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
109}
110#endif
111
112#if !defined(CONFIG_SYS_NO_FLASH)
113
114#include <mtd/cfi_flash.h>
Masahiro Yamada95387e22015-02-27 02:26:44 +0900115#include <mach/sbc-regs.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900116
Masahiro Yamada88216812014-12-06 00:03:26 +0900117struct memory_bank {
118 phys_addr_t base;
119 unsigned long size;
120};
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900121
Masahiro Yamada88216812014-12-06 00:03:26 +0900122static int mem_is_flash(const struct memory_bank *mem)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900123{
124 const int loop = 128;
125 u32 *scratch_addr;
126 u32 saved_value;
127 int ret = 1;
128 int i;
129
Masahiro Yamada88216812014-12-06 00:03:26 +0900130 /* 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);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900133
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);
140 ret = 0;
141 break;
142 }
143 }
144
145 unmap_physmem(scratch_addr, MAP_NOCACHE);
146
147 return ret;
148}
149
Masahiro Yamada88216812014-12-06 00:03:26 +0900150#if defined(CONFIG_PFC_MICRO_SUPPORT_CARD)
151 /* {address, size} */
152static const struct memory_bank memory_banks_boot_swap_off[] = {
153 {0x02000000, 0x01f00000},
154};
155
156static const struct memory_bank memory_banks_boot_swap_on[] = {
157 {0x00000000, 0x01f00000},
158};
159#endif
160
161#if defined(CONFIG_DCC_MICRO_SUPPORT_CARD)
162static const struct memory_bank memory_banks_boot_swap_off[] = {
Masahiro Yamadab92dabe2015-01-06 14:18:57 +0900163 {0x04000000, 0x02000000},
Masahiro Yamada88216812014-12-06 00:03:26 +0900164};
165
166static const struct memory_bank memory_banks_boot_swap_on[] = {
Masahiro Yamadab92dabe2015-01-06 14:18:57 +0900167 {0x00000000, 0x02000000},
168 {0x04000000, 0x02000000},
Masahiro Yamada88216812014-12-06 00:03:26 +0900169};
170#endif
171
172static const struct memory_bank
173*flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
174
175phys_addr_t cfi_flash_bank_addr(int i)
176{
177 return flash_banks_list[i]->base;
178}
179
180unsigned long cfi_flash_bank_size(int i)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900181{
Masahiro Yamada88216812014-12-06 00:03:26 +0900182 return flash_banks_list[i]->size;
183}
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900184
Masahiro Yamada88216812014-12-06 00:03:26 +0900185static void detect_num_flash_banks(void)
186{
187 const struct memory_bank *memory_bank, *end;
188
189 cfi_flash_num_flash_banks = 0;
190
191 if (boot_is_swapped()) {
192 memory_bank = memory_banks_boot_swap_on;
193 end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_on);
194 } else {
195 memory_bank = memory_banks_boot_swap_off;
196 end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_off);
197 }
198
199 for (; memory_bank < end; memory_bank++) {
200 if (cfi_flash_num_flash_banks >=
201 CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
202 break;
203
204 if (mem_is_flash(memory_bank)) {
205 flash_banks_list[cfi_flash_num_flash_banks] =
206 memory_bank;
207
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++;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900211 }
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900212 }
213
Masahiro Yamada88216812014-12-06 00:03:26 +0900214 debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900215}
Masahiro Yamada88216812014-12-06 00:03:26 +0900216#else /* ONFIG_SYS_NO_FLASH */
217void detect_num_flash_banks(void)
218{
219};
220#endif /* ONFIG_SYS_NO_FLASH */
221
222void support_card_late_init(void)
223{
224 detect_num_flash_banks();
225}