blob: f8333060301e0013518a5b9dfecca74d446a88f4 [file] [log] [blame]
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09001/*
Masahiro Yamada663a23f2015-05-29 17:30:00 +09002 * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Masahiro Yamada4e5d28d2015-09-22 00:27:31 +09008#include <linux/ctype.h>
Masahiro Yamada663a23f2015-05-29 17:30:00 +09009#include <linux/io.h>
Masahiro Yamada4e5d28d2015-09-22 00:27:31 +090010#include <mach/micro-support-card.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090011
Masahiro Yamada4903b6d2015-09-11 20:17:45 +090012#define MICRO_SUPPORT_CARD_RESET \
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090013 ((CONFIG_SUPPORT_CARD_BASE) + 0x000D0034)
Masahiro Yamada4903b6d2015-09-11 20:17:45 +090014#define MICRO_SUPPORT_CARD_REVISION \
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090015 ((CONFIG_SUPPORT_CARD_BASE) + 0x000D00E0)
16/*
17 * 0: reset deassert, 1: reset
18 *
19 * bit[0]: LAN, I2C, LED
20 * bit[1]: UART
21 */
22void support_card_reset_deassert(void)
23{
Masahiro Yamada4903b6d2015-09-11 20:17:45 +090024 writel(0, MICRO_SUPPORT_CARD_RESET);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090025}
26
27void support_card_reset(void)
28{
Masahiro Yamada4903b6d2015-09-11 20:17:45 +090029 writel(3, MICRO_SUPPORT_CARD_RESET);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090030}
31
32static int support_card_show_revision(void)
33{
34 u32 revision;
35
Masahiro Yamada4903b6d2015-09-11 20:17:45 +090036 revision = readl(MICRO_SUPPORT_CARD_REVISION);
37 printf("(CPLD version %d.%d)\n", revision >> 4, revision & 0xf);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090038 return 0;
39}
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090040
Masahiro Yamada88216812014-12-06 00:03:26 +090041int check_support_card(void)
42{
43 printf("SC: Micro Support Card ");
44 return support_card_show_revision();
45}
46
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090047void support_card_init(void)
48{
49 /*
50 * After power on, we need to keep the LAN controller in reset state
51 * for a while. (200 usec)
Masahiro Yamada5d3d9962015-03-23 00:07:30 +090052 * Fortunately, enough wait time is already inserted in pll_init()
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090053 * function. So we do not have to wait here.
54 */
55 support_card_reset_deassert();
56}
57
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090058#if defined(CONFIG_SMC911X)
59#include <netdev.h>
60
61int board_eth_init(bd_t *bis)
62{
63 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
64}
65#endif
66
67#if !defined(CONFIG_SYS_NO_FLASH)
68
69#include <mtd/cfi_flash.h>
Masahiro Yamada95387e22015-02-27 02:26:44 +090070#include <mach/sbc-regs.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090071
Masahiro Yamada88216812014-12-06 00:03:26 +090072struct memory_bank {
73 phys_addr_t base;
74 unsigned long size;
75};
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090076
Masahiro Yamada88216812014-12-06 00:03:26 +090077static int mem_is_flash(const struct memory_bank *mem)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090078{
79 const int loop = 128;
80 u32 *scratch_addr;
81 u32 saved_value;
82 int ret = 1;
83 int i;
84
Masahiro Yamada88216812014-12-06 00:03:26 +090085 /* just in case, use the tail of the memory bank */
86 scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop,
87 sizeof(u32) * loop, MAP_NOCACHE);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090088
89 for (i = 0; i < loop; i++, scratch_addr++) {
90 saved_value = readl(scratch_addr);
91 writel(~saved_value, scratch_addr);
92 if (readl(scratch_addr) != saved_value) {
93 /* We assume no memory or SRAM here. */
94 writel(saved_value, scratch_addr);
95 ret = 0;
96 break;
97 }
98 }
99
100 unmap_physmem(scratch_addr, MAP_NOCACHE);
101
102 return ret;
103}
104
Masahiro Yamada4903b6d2015-09-11 20:17:45 +0900105/* {address, size} */
106static const struct memory_bank memory_banks[] = {
Masahiro Yamada4b275ea2015-09-11 20:17:47 +0900107 {0x42000000, 0x01f00000},
Masahiro Yamada88216812014-12-06 00:03:26 +0900108};
109
Masahiro Yamada88216812014-12-06 00:03:26 +0900110static const struct memory_bank
111*flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
112
113phys_addr_t cfi_flash_bank_addr(int i)
114{
115 return flash_banks_list[i]->base;
116}
117
118unsigned long cfi_flash_bank_size(int i)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900119{
Masahiro Yamada88216812014-12-06 00:03:26 +0900120 return flash_banks_list[i]->size;
121}
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900122
Masahiro Yamada88216812014-12-06 00:03:26 +0900123static void detect_num_flash_banks(void)
124{
125 const struct memory_bank *memory_bank, *end;
126
127 cfi_flash_num_flash_banks = 0;
128
Masahiro Yamada4903b6d2015-09-11 20:17:45 +0900129 memory_bank = memory_banks;
130 end = memory_bank + ARRAY_SIZE(memory_banks);
Masahiro Yamada88216812014-12-06 00:03:26 +0900131
132 for (; memory_bank < end; memory_bank++) {
133 if (cfi_flash_num_flash_banks >=
134 CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
135 break;
136
137 if (mem_is_flash(memory_bank)) {
138 flash_banks_list[cfi_flash_num_flash_banks] =
139 memory_bank;
140
141 debug("flash bank found: base = 0x%lx, size = 0x%lx\n",
142 memory_bank->base, memory_bank->size);
143 cfi_flash_num_flash_banks++;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900144 }
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900145 }
146
Masahiro Yamada88216812014-12-06 00:03:26 +0900147 debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900148}
Masahiro Yamada5d3d9962015-03-23 00:07:30 +0900149#else /* CONFIG_SYS_NO_FLASH */
Masahiro Yamada88216812014-12-06 00:03:26 +0900150void detect_num_flash_banks(void)
151{
152};
Masahiro Yamada5d3d9962015-03-23 00:07:30 +0900153#endif /* CONFIG_SYS_NO_FLASH */
Masahiro Yamada88216812014-12-06 00:03:26 +0900154
155void support_card_late_init(void)
156{
157 detect_num_flash_banks();
158}
Masahiro Yamada4e5d28d2015-09-22 00:27:31 +0900159
160static const u8 ledval_num[] = {
161 0x7e, /* 0 */
162 0x0c, /* 1 */
163 0xb6, /* 2 */
164 0x9e, /* 3 */
165 0xcc, /* 4 */
166 0xda, /* 5 */
167 0xfa, /* 6 */
168 0x4e, /* 7 */
169 0xfe, /* 8 */
170 0xde, /* 9 */
171};
172
173static const u8 ledval_alpha[] = {
174 0xee, /* A */
175 0xf8, /* B */
176 0x72, /* C */
177 0xbc, /* D */
178 0xf2, /* E */
179 0xe2, /* F */
180 0x7a, /* G */
181 0xe8, /* H */
182 0x08, /* I */
183 0x3c, /* J */
184 0xea, /* K */
185 0x70, /* L */
186 0x6e, /* M */
187 0xa8, /* N */
188 0xb8, /* O */
189 0xe6, /* P */
190 0xce, /* Q */
191 0xa0, /* R */
192 0xc8, /* S */
193 0x8c, /* T */
194 0x7c, /* U */
195 0x54, /* V */
196 0xfc, /* W */
197 0xec, /* X */
198 0xdc, /* Y */
199 0xa4, /* Z */
200};
201
202static u8 char2ledval(char c)
203{
204 if (isdigit(c))
205 return ledval_num[c - '0'];
206 else if (isalpha(c))
207 return ledval_alpha[toupper(c) - 'A'];
208
209 return 0;
210}
211
212void led_puts(const char *s)
213{
214 int i;
215 u32 val = 0;
216
217 if (!s)
218 return;
219
220 for (i = 0; i < 4; i++) {
221 val <<= 8;
222 val |= char2ledval(*s);
223 if (*s != '\0')
224 s++;
225 }
226
227 writel(~val, CONFIG_SUPPORT_CARD_LED_BASE);
228}