blob: ea85b20e979c02749a83360d102d6b1abc91a0d4 [file] [log] [blame]
Masahiro Yamada5894ca02014-10-03 19:21:06 +09001/*
Masahiro Yamadaf6e7f072015-05-29 17:30:00 +09002 * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada5894ca02014-10-03 19:21:06 +09003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Masahiro Yamadaf6e7f072015-05-29 17:30:00 +09008#include <linux/io.h>
Masahiro Yamadaa86ac952015-02-27 02:26:44 +09009#include <mach/board.h>
Masahiro Yamada5894ca02014-10-03 19:21:06 +090010
11#if defined(CONFIG_PFC_MICRO_SUPPORT_CARD)
12
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)
17/*
18 * 0: reset deassert, 1: reset
19 *
20 * bit[0]: LAN, I2C, LED
21 * bit[1]: UART
22 */
23void support_card_reset_deassert(void)
24{
25 writel(0, PFC_MICRO_SUPPORT_CARD_RESET);
26}
27
28void support_card_reset(void)
29{
30 writel(3, PFC_MICRO_SUPPORT_CARD_RESET);
31}
32
33static int support_card_show_revision(void)
34{
35 u32 revision;
36
37 revision = readl(PFC_MICRO_SUPPORT_CARD_REVISION);
38 printf("(PFC CPLD version %d.%d)\n", revision >> 4, revision & 0xf);
39 return 0;
40}
41#endif
42
43#if defined(CONFIG_DCC_MICRO_SUPPORT_CARD)
44
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)
53
54void support_card_reset_deassert(void)
55{
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 */
59}
60
61void support_card_reset(void)
62{
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 */
66}
67
68static int support_card_show_revision(void)
69{
70 u32 revision;
71
72 revision = readl(DCC_MICRO_SUPPORT_CARD_REVISION);
73
74 if (revision >= 0x67) {
75 printf("(DCC CPLD version 3.%d.%d)\n",
76 revision >> 4, revision & 0xf);
77 return 0;
78 } else {
79 printf("(DCC CPLD unknown version)\n");
80 return -1;
81 }
82}
83#endif
84
Masahiro Yamada7a3620b2014-12-06 00:03:26 +090085int check_support_card(void)
86{
87 printf("SC: Micro Support Card ");
88 return support_card_show_revision();
89}
90
Masahiro Yamada5894ca02014-10-03 19:21:06 +090091void support_card_init(void)
92{
93 /*
94 * After power on, we need to keep the LAN controller in reset state
95 * for a while. (200 usec)
Masahiro Yamada4d13b1b2015-03-23 00:07:30 +090096 * Fortunately, enough wait time is already inserted in pll_init()
Masahiro Yamada5894ca02014-10-03 19:21:06 +090097 * function. So we do not have to wait here.
98 */
99 support_card_reset_deassert();
100}
101
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900102#if defined(CONFIG_SMC911X)
103#include <netdev.h>
104
105int board_eth_init(bd_t *bis)
106{
107 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
108}
109#endif
110
111#if !defined(CONFIG_SYS_NO_FLASH)
112
113#include <mtd/cfi_flash.h>
Masahiro Yamadaa86ac952015-02-27 02:26:44 +0900114#include <mach/sbc-regs.h>
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900115
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900116struct memory_bank {
117 phys_addr_t base;
118 unsigned long size;
119};
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900120
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900121static int mem_is_flash(const struct memory_bank *mem)
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900122{
123 const int loop = 128;
124 u32 *scratch_addr;
125 u32 saved_value;
126 int ret = 1;
127 int i;
128
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900129 /* 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);
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900132
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);
139 ret = 0;
140 break;
141 }
142 }
143
144 unmap_physmem(scratch_addr, MAP_NOCACHE);
145
146 return ret;
147}
148
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900149#if defined(CONFIG_PFC_MICRO_SUPPORT_CARD)
150 /* {address, size} */
151static const struct memory_bank memory_banks_boot_swap_off[] = {
152 {0x02000000, 0x01f00000},
153};
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900154
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900155static const struct memory_bank memory_banks_boot_swap_on[] = {
156 {0x00000000, 0x01f00000},
157};
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900158#endif
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900159
160#if defined(CONFIG_DCC_MICRO_SUPPORT_CARD)
161static const struct memory_bank memory_banks_boot_swap_off[] = {
Masahiro Yamada5e165b22015-01-06 14:18:57 +0900162 {0x04000000, 0x02000000},
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900163};
164
165static const struct memory_bank memory_banks_boot_swap_on[] = {
Masahiro Yamada5e165b22015-01-06 14:18:57 +0900166 {0x00000000, 0x02000000},
167 {0x04000000, 0x02000000},
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900168};
169#endif
170
171static const struct memory_bank
172*flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
173
174phys_addr_t cfi_flash_bank_addr(int i)
175{
176 return flash_banks_list[i]->base;
177}
178
179unsigned long cfi_flash_bank_size(int i)
180{
181 return flash_banks_list[i]->size;
182}
183
184static void detect_num_flash_banks(void)
185{
186 const struct memory_bank *memory_bank, *end;
187
188 cfi_flash_num_flash_banks = 0;
189
190 if (boot_is_swapped()) {
191 memory_bank = memory_banks_boot_swap_on;
192 end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_on);
193 } else {
194 memory_bank = memory_banks_boot_swap_off;
195 end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_off);
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900196 }
197
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900198 for (; memory_bank < end; memory_bank++) {
199 if (cfi_flash_num_flash_banks >=
200 CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
201 break;
202
203 if (mem_is_flash(memory_bank)) {
204 flash_banks_list[cfi_flash_num_flash_banks] =
205 memory_bank;
206
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++;
210 }
211 }
212
213 debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900214}
Masahiro Yamada4d13b1b2015-03-23 00:07:30 +0900215#else /* CONFIG_SYS_NO_FLASH */
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900216void detect_num_flash_banks(void)
217{
218};
Masahiro Yamada4d13b1b2015-03-23 00:07:30 +0900219#endif /* CONFIG_SYS_NO_FLASH */
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900220
221void support_card_late_init(void)
222{
223 detect_num_flash_banks();
224}