]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/arm/mach-uniphier/micro-support-card.c
ARM: uniphier: move cmd_pinmon.c to boot-mode subdirectory
[people/ms/u-boot.git] / arch / arm / mach-uniphier / micro-support-card.c
CommitLineData
5894ca00 1/*
f6e7f07c 2 * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
5894ca00
MY
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8469700b 8#include <linux/ctype.h>
f6e7f07c 9#include <linux/io.h>
8469700b 10#include <mach/micro-support-card.h>
5894ca00 11
d7728aa4
MY
12#define MICRO_SUPPORT_CARD_BASE 0x43f00000
13#define SMC911X_BASE ((MICRO_SUPPORT_CARD_BASE) + 0x00000)
14#define LED_BASE ((MICRO_SUPPORT_CARD_BASE) + 0x90000)
15#define NS16550A_BASE ((MICRO_SUPPORT_CARD_BASE) + 0xb0000)
16#define MICRO_SUPPORT_CARD_RESET ((MICRO_SUPPORT_CARD_BASE) + 0xd0034)
17#define MICRO_SUPPORT_CARD_REVISION ((MICRO_SUPPORT_CARD_BASE) + 0xd00E0)
18
5894ca00
MY
19/*
20 * 0: reset deassert, 1: reset
21 *
22 * bit[0]: LAN, I2C, LED
23 * bit[1]: UART
24 */
25void support_card_reset_deassert(void)
26{
9879842c 27 writel(0, MICRO_SUPPORT_CARD_RESET);
5894ca00
MY
28}
29
30void support_card_reset(void)
31{
9879842c 32 writel(3, MICRO_SUPPORT_CARD_RESET);
5894ca00
MY
33}
34
35static int support_card_show_revision(void)
36{
37 u32 revision;
38
9879842c
MY
39 revision = readl(MICRO_SUPPORT_CARD_REVISION);
40 printf("(CPLD version %d.%d)\n", revision >> 4, revision & 0xf);
5894ca00
MY
41 return 0;
42}
5894ca00 43
7a3620b2
MY
44int check_support_card(void)
45{
46 printf("SC: Micro Support Card ");
47 return support_card_show_revision();
48}
49
5894ca00
MY
50void support_card_init(void)
51{
52 /*
53 * After power on, we need to keep the LAN controller in reset state
54 * for a while. (200 usec)
4d13b1b7 55 * Fortunately, enough wait time is already inserted in pll_init()
5894ca00
MY
56 * function. So we do not have to wait here.
57 */
58 support_card_reset_deassert();
59}
60
5894ca00
MY
61#if defined(CONFIG_SMC911X)
62#include <netdev.h>
63
64int board_eth_init(bd_t *bis)
65{
d7728aa4 66 return smc911x_initialize(0, SMC911X_BASE);
5894ca00
MY
67}
68#endif
69
70#if !defined(CONFIG_SYS_NO_FLASH)
71
72#include <mtd/cfi_flash.h>
73
7a3620b2
MY
74struct memory_bank {
75 phys_addr_t base;
76 unsigned long size;
77};
5894ca00 78
7a3620b2 79static int mem_is_flash(const struct memory_bank *mem)
5894ca00
MY
80{
81 const int loop = 128;
82 u32 *scratch_addr;
83 u32 saved_value;
84 int ret = 1;
85 int i;
86
7a3620b2
MY
87 /* just in case, use the tail of the memory bank */
88 scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop,
89 sizeof(u32) * loop, MAP_NOCACHE);
5894ca00
MY
90
91 for (i = 0; i < loop; i++, scratch_addr++) {
92 saved_value = readl(scratch_addr);
93 writel(~saved_value, scratch_addr);
94 if (readl(scratch_addr) != saved_value) {
95 /* We assume no memory or SRAM here. */
96 writel(saved_value, scratch_addr);
97 ret = 0;
98 break;
99 }
100 }
101
102 unmap_physmem(scratch_addr, MAP_NOCACHE);
103
104 return ret;
105}
106
9879842c
MY
107/* {address, size} */
108static const struct memory_bank memory_banks[] = {
d5ed8c57 109 {0x42000000, 0x01f00000},
7a3620b2
MY
110};
111
7a3620b2
MY
112static const struct memory_bank
113*flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
114
115phys_addr_t cfi_flash_bank_addr(int i)
5894ca00 116{
7a3620b2
MY
117 return flash_banks_list[i]->base;
118}
5894ca00 119
7a3620b2
MY
120unsigned long cfi_flash_bank_size(int i)
121{
122 return flash_banks_list[i]->size;
123}
124
125static void detect_num_flash_banks(void)
126{
127 const struct memory_bank *memory_bank, *end;
128
129 cfi_flash_num_flash_banks = 0;
130
9879842c
MY
131 memory_bank = memory_banks;
132 end = memory_bank + ARRAY_SIZE(memory_banks);
7a3620b2
MY
133
134 for (; memory_bank < end; memory_bank++) {
135 if (cfi_flash_num_flash_banks >=
136 CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
137 break;
138
139 if (mem_is_flash(memory_bank)) {
140 flash_banks_list[cfi_flash_num_flash_banks] =
141 memory_bank;
142
143 debug("flash bank found: base = 0x%lx, size = 0x%lx\n",
144 memory_bank->base, memory_bank->size);
145 cfi_flash_num_flash_banks++;
5894ca00 146 }
5894ca00
MY
147 }
148
7a3620b2
MY
149 debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
150}
4d13b1b7 151#else /* CONFIG_SYS_NO_FLASH */
7a3620b2
MY
152void detect_num_flash_banks(void)
153{
154};
4d13b1b7 155#endif /* CONFIG_SYS_NO_FLASH */
7a3620b2
MY
156
157void support_card_late_init(void)
158{
159 detect_num_flash_banks();
5894ca00 160}
8469700b
MY
161
162static const u8 ledval_num[] = {
163 0x7e, /* 0 */
164 0x0c, /* 1 */
165 0xb6, /* 2 */
166 0x9e, /* 3 */
167 0xcc, /* 4 */
168 0xda, /* 5 */
169 0xfa, /* 6 */
170 0x4e, /* 7 */
171 0xfe, /* 8 */
172 0xde, /* 9 */
173};
174
175static const u8 ledval_alpha[] = {
176 0xee, /* A */
177 0xf8, /* B */
178 0x72, /* C */
179 0xbc, /* D */
180 0xf2, /* E */
181 0xe2, /* F */
182 0x7a, /* G */
183 0xe8, /* H */
184 0x08, /* I */
185 0x3c, /* J */
186 0xea, /* K */
187 0x70, /* L */
188 0x6e, /* M */
189 0xa8, /* N */
190 0xb8, /* O */
191 0xe6, /* P */
192 0xce, /* Q */
193 0xa0, /* R */
194 0xc8, /* S */
195 0x8c, /* T */
196 0x7c, /* U */
197 0x54, /* V */
198 0xfc, /* W */
199 0xec, /* X */
200 0xdc, /* Y */
201 0xa4, /* Z */
202};
203
204static u8 char2ledval(char c)
205{
206 if (isdigit(c))
207 return ledval_num[c - '0'];
208 else if (isalpha(c))
209 return ledval_alpha[toupper(c) - 'A'];
210
211 return 0;
212}
213
214void led_puts(const char *s)
215{
216 int i;
217 u32 val = 0;
218
219 if (!s)
220 return;
221
222 for (i = 0; i < 4; i++) {
223 val <<= 8;
224 val |= char2ledval(*s);
225 if (*s != '\0')
226 s++;
227 }
228
d7728aa4 229 writel(~val, LED_BASE);
8469700b 230}