2 * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
4 * SPDX-License-Identifier: GPL-2.0+
8 #include <linux/ctype.h>
11 #include "micro-support-card.h"
13 #define MICRO_SUPPORT_CARD_BASE 0x43f00000
14 #define SMC911X_BASE ((MICRO_SUPPORT_CARD_BASE) + 0x00000)
15 #define LED_BASE ((MICRO_SUPPORT_CARD_BASE) + 0x90000)
16 #define NS16550A_BASE ((MICRO_SUPPORT_CARD_BASE) + 0xb0000)
17 #define MICRO_SUPPORT_CARD_RESET ((MICRO_SUPPORT_CARD_BASE) + 0xd0034)
18 #define MICRO_SUPPORT_CARD_REVISION ((MICRO_SUPPORT_CARD_BASE) + 0xd00E0)
21 * 0: reset deassert, 1: reset
23 * bit[0]: LAN, I2C, LED
26 void support_card_reset_deassert(void)
28 writel(0x00010000, MICRO_SUPPORT_CARD_RESET);
31 void support_card_reset(void)
33 writel(0x00020003, MICRO_SUPPORT_CARD_RESET);
36 static int support_card_show_revision(void)
40 revision = readl(MICRO_SUPPORT_CARD_REVISION);
41 printf("(CPLD version %d.%d)\n", revision >> 4, revision & 0xf);
45 int check_support_card(void)
47 printf("SC: Micro Support Card ");
48 return support_card_show_revision();
51 void support_card_init(void)
54 * After power on, we need to keep the LAN controller in reset state
55 * for a while. (200 usec)
56 * Fortunately, enough wait time is already inserted in pll_init()
57 * function. So we do not have to wait here.
59 support_card_reset_deassert();
62 #if defined(CONFIG_SMC911X)
65 int board_eth_init(bd_t *bis)
67 return smc911x_initialize(0, SMC911X_BASE);
71 #if !defined(CONFIG_SYS_NO_FLASH)
73 #include <mtd/cfi_flash.h>
80 static int mem_is_flash(const struct memory_bank *mem)
88 /* just in case, use the tail of the memory bank */
89 scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop,
90 sizeof(u32) * loop, MAP_NOCACHE);
92 for (i = 0; i < loop; i++, scratch_addr++) {
93 saved_value = readl(scratch_addr);
94 writel(~saved_value, scratch_addr);
95 if (readl(scratch_addr) != saved_value) {
96 /* We assume no memory or SRAM here. */
97 writel(saved_value, scratch_addr);
103 unmap_physmem(scratch_addr, MAP_NOCACHE);
108 /* {address, size} */
109 static const struct memory_bank memory_banks[] = {
110 {0x42000000, 0x01f00000},
113 static const struct memory_bank
114 *flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
116 phys_addr_t cfi_flash_bank_addr(int i)
118 return flash_banks_list[i]->base;
121 unsigned long cfi_flash_bank_size(int i)
123 return flash_banks_list[i]->size;
126 static void detect_num_flash_banks(void)
128 const struct memory_bank *memory_bank, *end;
130 cfi_flash_num_flash_banks = 0;
132 memory_bank = memory_banks;
133 end = memory_bank + ARRAY_SIZE(memory_banks);
135 for (; memory_bank < end; memory_bank++) {
136 if (cfi_flash_num_flash_banks >=
137 CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
140 if (mem_is_flash(memory_bank)) {
141 flash_banks_list[cfi_flash_num_flash_banks] =
144 debug("flash bank found: base = 0x%lx, size = 0x%lx\n",
145 (unsigned long)memory_bank->base,
146 (unsigned long)memory_bank->size);
147 cfi_flash_num_flash_banks++;
151 debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
153 #else /* CONFIG_SYS_NO_FLASH */
154 void detect_num_flash_banks(void)
157 #endif /* CONFIG_SYS_NO_FLASH */
159 void support_card_late_init(void)
161 detect_num_flash_banks();
164 static const u8 ledval_num[] = {
177 static const u8 ledval_alpha[] = {
206 static u8 char2ledval(char c)
209 return ledval_num[c - '0'];
211 return ledval_alpha[toupper(c) - 'A'];
216 void led_puts(const char *s)
224 for (i = 0; i < 4; i++) {
226 val |= char2ledval(*s);
231 writel(~val, LED_BASE);