blob: 1be5685c6fbfe4b5255d12954c45d406e5dd8149 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamada5894ca02014-10-03 19:21:06 +09002/*
Masahiro Yamada499c8672016-08-25 17:02:31 +09003 * Copyright (C) 2012-2015 Panasonic Corporation
4 * Copyright (C) 2015-2016 Socionext Inc.
5 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada5894ca02014-10-03 19:21:06 +09006 */
7
8#include <common.h>
Masahiro Yamada84697002015-09-22 00:27:31 +09009#include <linux/ctype.h>
Masahiro Yamadaf6e7f072015-05-29 17:30:00 +090010#include <linux/io.h>
Masahiro Yamada107b3fb2016-01-09 01:51:13 +090011
12#include "micro-support-card.h"
Masahiro Yamada5894ca02014-10-03 19:21:06 +090013
Masahiro Yamadad7728aa2015-09-22 00:27:32 +090014#define MICRO_SUPPORT_CARD_BASE 0x43f00000
15#define SMC911X_BASE ((MICRO_SUPPORT_CARD_BASE) + 0x00000)
16#define LED_BASE ((MICRO_SUPPORT_CARD_BASE) + 0x90000)
17#define NS16550A_BASE ((MICRO_SUPPORT_CARD_BASE) + 0xb0000)
18#define MICRO_SUPPORT_CARD_RESET ((MICRO_SUPPORT_CARD_BASE) + 0xd0034)
19#define MICRO_SUPPORT_CARD_REVISION ((MICRO_SUPPORT_CARD_BASE) + 0xd00E0)
20
Masahiro Yamada5894ca02014-10-03 19:21:06 +090021/*
22 * 0: reset deassert, 1: reset
23 *
24 * bit[0]: LAN, I2C, LED
25 * bit[1]: UART
26 */
Masahiro Yamadaef07a992017-01-15 14:59:06 +090027static void support_card_reset_deassert(void)
Masahiro Yamada5894ca02014-10-03 19:21:06 +090028{
Masahiro Yamada36223f52016-03-18 16:41:46 +090029 writel(0x00010000, MICRO_SUPPORT_CARD_RESET);
Masahiro Yamada5894ca02014-10-03 19:21:06 +090030}
31
Masahiro Yamadaef07a992017-01-15 14:59:06 +090032static void support_card_reset(void)
Masahiro Yamada5894ca02014-10-03 19:21:06 +090033{
Masahiro Yamada36223f52016-03-18 16:41:46 +090034 writel(0x00020003, MICRO_SUPPORT_CARD_RESET);
Masahiro Yamada5894ca02014-10-03 19:21:06 +090035}
36
37static int support_card_show_revision(void)
38{
39 u32 revision;
40
Masahiro Yamada98798422015-09-11 20:17:45 +090041 revision = readl(MICRO_SUPPORT_CARD_REVISION);
Masahiro Yamada499c8672016-08-25 17:02:31 +090042 revision &= 0xff;
43
44 /* revision 3.6.x card changed the revision format */
Masahiro Yamada6fc84912017-02-20 17:32:19 +090045 printf("SC: Micro Support Card (CPLD version %s%d.%d)\n",
46 revision >> 4 == 6 ? "3." : "",
Masahiro Yamada499c8672016-08-25 17:02:31 +090047 revision >> 4, revision & 0xf);
48
Masahiro Yamada5894ca02014-10-03 19:21:06 +090049 return 0;
50}
Masahiro Yamada5894ca02014-10-03 19:21:06 +090051
52void support_card_init(void)
53{
Masahiro Yamadaef07a992017-01-15 14:59:06 +090054 support_card_reset();
Masahiro Yamada5894ca02014-10-03 19:21:06 +090055 /*
56 * After power on, we need to keep the LAN controller in reset state
57 * for a while. (200 usec)
Masahiro Yamada5894ca02014-10-03 19:21:06 +090058 */
Masahiro Yamada66e3efe2016-10-08 13:25:29 +090059 udelay(200);
Masahiro Yamada5894ca02014-10-03 19:21:06 +090060 support_card_reset_deassert();
Masahiro Yamada6fc84912017-02-20 17:32:19 +090061
62 support_card_show_revision();
Masahiro Yamada5894ca02014-10-03 19:21:06 +090063}
64
Masahiro Yamada5894ca02014-10-03 19:21:06 +090065#if defined(CONFIG_SMC911X)
66#include <netdev.h>
67
68int board_eth_init(bd_t *bis)
69{
Masahiro Yamadad7728aa2015-09-22 00:27:32 +090070 return smc911x_initialize(0, SMC911X_BASE);
Masahiro Yamada5894ca02014-10-03 19:21:06 +090071}
72#endif
73
Masahiro Yamadae856bdc2017-02-11 22:43:54 +090074#if defined(CONFIG_MTD_NOR_FLASH)
Masahiro Yamada5894ca02014-10-03 19:21:06 +090075
76#include <mtd/cfi_flash.h>
77
Masahiro Yamada7a3620b2014-12-06 00:03:26 +090078struct memory_bank {
79 phys_addr_t base;
80 unsigned long size;
81};
Masahiro Yamada5894ca02014-10-03 19:21:06 +090082
Masahiro Yamada7a3620b2014-12-06 00:03:26 +090083static int mem_is_flash(const struct memory_bank *mem)
Masahiro Yamada5894ca02014-10-03 19:21:06 +090084{
85 const int loop = 128;
86 u32 *scratch_addr;
87 u32 saved_value;
88 int ret = 1;
89 int i;
90
Masahiro Yamada7a3620b2014-12-06 00:03:26 +090091 /* just in case, use the tail of the memory bank */
92 scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop,
93 sizeof(u32) * loop, MAP_NOCACHE);
Masahiro Yamada5894ca02014-10-03 19:21:06 +090094
95 for (i = 0; i < loop; i++, scratch_addr++) {
96 saved_value = readl(scratch_addr);
97 writel(~saved_value, scratch_addr);
98 if (readl(scratch_addr) != saved_value) {
99 /* We assume no memory or SRAM here. */
100 writel(saved_value, scratch_addr);
101 ret = 0;
102 break;
103 }
104 }
105
106 unmap_physmem(scratch_addr, MAP_NOCACHE);
107
108 return ret;
109}
110
Masahiro Yamada98798422015-09-11 20:17:45 +0900111/* {address, size} */
112static const struct memory_bank memory_banks[] = {
Masahiro Yamadad5ed8c52015-09-11 20:17:47 +0900113 {0x42000000, 0x01f00000},
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900114};
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900115
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900116static const struct memory_bank
117*flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
118
119phys_addr_t cfi_flash_bank_addr(int i)
120{
121 return flash_banks_list[i]->base;
122}
123
124unsigned long cfi_flash_bank_size(int i)
125{
126 return flash_banks_list[i]->size;
127}
128
129static void detect_num_flash_banks(void)
130{
131 const struct memory_bank *memory_bank, *end;
132
133 cfi_flash_num_flash_banks = 0;
134
Masahiro Yamada98798422015-09-11 20:17:45 +0900135 memory_bank = memory_banks;
136 end = memory_bank + ARRAY_SIZE(memory_banks);
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900137
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900138 for (; memory_bank < end; memory_bank++) {
139 if (cfi_flash_num_flash_banks >=
140 CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
141 break;
142
143 if (mem_is_flash(memory_bank)) {
144 flash_banks_list[cfi_flash_num_flash_banks] =
145 memory_bank;
146
147 debug("flash bank found: base = 0x%lx, size = 0x%lx\n",
Masahiro Yamada11d3ede2016-02-26 18:59:45 +0900148 (unsigned long)memory_bank->base,
149 (unsigned long)memory_bank->size);
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900150 cfi_flash_num_flash_banks++;
151 }
152 }
153
154 debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
Masahiro Yamada5894ca02014-10-03 19:21:06 +0900155}
Masahiro Yamadae856bdc2017-02-11 22:43:54 +0900156#else /* CONFIG_MTD_NOR_FLASH */
Masahiro Yamadaef07a992017-01-15 14:59:06 +0900157static void detect_num_flash_banks(void)
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900158{
159};
Masahiro Yamadae856bdc2017-02-11 22:43:54 +0900160#endif /* CONFIG_MTD_NOR_FLASH */
Masahiro Yamada7a3620b2014-12-06 00:03:26 +0900161
162void support_card_late_init(void)
163{
164 detect_num_flash_banks();
165}
Masahiro Yamada84697002015-09-22 00:27:31 +0900166
167static const u8 ledval_num[] = {
168 0x7e, /* 0 */
169 0x0c, /* 1 */
170 0xb6, /* 2 */
171 0x9e, /* 3 */
172 0xcc, /* 4 */
173 0xda, /* 5 */
174 0xfa, /* 6 */
175 0x4e, /* 7 */
176 0xfe, /* 8 */
177 0xde, /* 9 */
178};
179
180static const u8 ledval_alpha[] = {
181 0xee, /* A */
182 0xf8, /* B */
183 0x72, /* C */
184 0xbc, /* D */
185 0xf2, /* E */
186 0xe2, /* F */
187 0x7a, /* G */
188 0xe8, /* H */
189 0x08, /* I */
190 0x3c, /* J */
191 0xea, /* K */
192 0x70, /* L */
193 0x6e, /* M */
194 0xa8, /* N */
195 0xb8, /* O */
196 0xe6, /* P */
197 0xce, /* Q */
198 0xa0, /* R */
199 0xc8, /* S */
200 0x8c, /* T */
201 0x7c, /* U */
202 0x54, /* V */
203 0xfc, /* W */
204 0xec, /* X */
205 0xdc, /* Y */
206 0xa4, /* Z */
207};
208
209static u8 char2ledval(char c)
210{
211 if (isdigit(c))
212 return ledval_num[c - '0'];
213 else if (isalpha(c))
214 return ledval_alpha[toupper(c) - 'A'];
215
216 return 0;
217}
218
219void led_puts(const char *s)
220{
221 int i;
222 u32 val = 0;
223
224 if (!s)
225 return;
226
227 for (i = 0; i < 4; i++) {
228 val <<= 8;
229 val |= char2ledval(*s);
230 if (*s != '\0')
231 s++;
232 }
233
Masahiro Yamadad7728aa2015-09-22 00:27:32 +0900234 writel(~val, LED_BASE);
Masahiro Yamada84697002015-09-22 00:27:31 +0900235}