2 * Copyright (C) 2012-2015 Panasonic Corporation
3 * Copyright (C) 2015-2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
6 * SPDX-License-Identifier: GPL-2.0+
10 #include <linux/ctype.h>
13 #include "micro-support-card.h"
15 #define MICRO_SUPPORT_CARD_BASE 0x43f00000
16 #define SMC911X_BASE ((MICRO_SUPPORT_CARD_BASE) + 0x00000)
17 #define LED_BASE ((MICRO_SUPPORT_CARD_BASE) + 0x90000)
18 #define NS16550A_BASE ((MICRO_SUPPORT_CARD_BASE) + 0xb0000)
19 #define MICRO_SUPPORT_CARD_RESET ((MICRO_SUPPORT_CARD_BASE) + 0xd0034)
20 #define MICRO_SUPPORT_CARD_REVISION ((MICRO_SUPPORT_CARD_BASE) + 0xd00E0)
23 * 0: reset deassert, 1: reset
25 * bit[0]: LAN, I2C, LED
28 static void support_card_reset_deassert(void)
30 writel(0x00010000, MICRO_SUPPORT_CARD_RESET);
33 static void support_card_reset(void)
35 writel(0x00020003, MICRO_SUPPORT_CARD_RESET);
38 static int support_card_show_revision(void)
42 revision = readl(MICRO_SUPPORT_CARD_REVISION);
45 /* revision 3.6.x card changed the revision format */
46 printf("(CPLD version %s%d.%d)\n", revision >> 4 == 6 ? "3." : "",
47 revision >> 4, revision & 0xf);
54 printf("SC: Micro Support Card ");
55 return support_card_show_revision();
58 void support_card_init(void)
62 * After power on, we need to keep the LAN controller in reset state
63 * for a while. (200 usec)
66 support_card_reset_deassert();
69 #if defined(CONFIG_SMC911X)
72 int board_eth_init(bd_t *bis)
74 return smc911x_initialize(0, SMC911X_BASE);
78 #if !defined(CONFIG_SYS_NO_FLASH)
80 #include <mtd/cfi_flash.h>
87 static int mem_is_flash(const struct memory_bank *mem)
95 /* just in case, use the tail of the memory bank */
96 scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop,
97 sizeof(u32) * loop, MAP_NOCACHE);
99 for (i = 0; i < loop; i++, scratch_addr++) {
100 saved_value = readl(scratch_addr);
101 writel(~saved_value, scratch_addr);
102 if (readl(scratch_addr) != saved_value) {
103 /* We assume no memory or SRAM here. */
104 writel(saved_value, scratch_addr);
110 unmap_physmem(scratch_addr, MAP_NOCACHE);
115 /* {address, size} */
116 static const struct memory_bank memory_banks[] = {
117 {0x42000000, 0x01f00000},
120 static const struct memory_bank
121 *flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
123 phys_addr_t cfi_flash_bank_addr(int i)
125 return flash_banks_list[i]->base;
128 unsigned long cfi_flash_bank_size(int i)
130 return flash_banks_list[i]->size;
133 static void detect_num_flash_banks(void)
135 const struct memory_bank *memory_bank, *end;
137 cfi_flash_num_flash_banks = 0;
139 memory_bank = memory_banks;
140 end = memory_bank + ARRAY_SIZE(memory_banks);
142 for (; memory_bank < end; memory_bank++) {
143 if (cfi_flash_num_flash_banks >=
144 CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
147 if (mem_is_flash(memory_bank)) {
148 flash_banks_list[cfi_flash_num_flash_banks] =
151 debug("flash bank found: base = 0x%lx, size = 0x%lx\n",
152 (unsigned long)memory_bank->base,
153 (unsigned long)memory_bank->size);
154 cfi_flash_num_flash_banks++;
158 debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
160 #else /* CONFIG_SYS_NO_FLASH */
161 static void detect_num_flash_banks(void)
164 #endif /* CONFIG_SYS_NO_FLASH */
166 void support_card_late_init(void)
168 detect_num_flash_banks();
171 static const u8 ledval_num[] = {
184 static const u8 ledval_alpha[] = {
213 static u8 char2ledval(char c)
216 return ledval_num[c - '0'];
218 return ledval_alpha[toupper(c) - 'A'];
223 void led_puts(const char *s)
231 for (i = 0; i < 4; i++) {
233 val |= char2ledval(*s);
238 writel(~val, LED_BASE);