1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012-2015 Panasonic Corporation
4 * Copyright (C) 2015-2016 Socionext Inc.
5 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
9 #include <linux/ctype.h>
12 #include "micro-support-card.h"
14 #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)
22 * 0: reset deassert, 1: reset
24 * bit[0]: LAN, I2C, LED
27 static void support_card_reset_deassert(void)
29 writel(0x00010000, MICRO_SUPPORT_CARD_RESET);
32 static void support_card_reset(void)
34 writel(0x00020003, MICRO_SUPPORT_CARD_RESET);
37 static int support_card_show_revision(void)
41 revision = readl(MICRO_SUPPORT_CARD_REVISION);
44 /* revision 3.6.x card changed the revision format */
45 printf("SC: Micro Support Card (CPLD version %s%d.%d)\n",
46 revision >> 4 == 6 ? "3." : "",
47 revision >> 4, revision & 0xf);
52 void support_card_init(void)
56 * After power on, we need to keep the LAN controller in reset state
57 * for a while. (200 usec)
60 support_card_reset_deassert();
62 support_card_show_revision();
65 #if defined(CONFIG_SMC911X)
68 int board_eth_init(bd_t *bis)
70 return smc911x_initialize(0, SMC911X_BASE);
74 #if defined(CONFIG_MTD_NOR_FLASH)
76 #include <mtd/cfi_flash.h>
83 static int mem_is_flash(const struct memory_bank *mem)
91 /* 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);
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);
106 unmap_physmem(scratch_addr, MAP_NOCACHE);
111 /* {address, size} */
112 static const struct memory_bank memory_banks[] = {
113 {0x42000000, 0x01f00000},
116 static const struct memory_bank
117 *flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
119 phys_addr_t cfi_flash_bank_addr(int i)
121 return flash_banks_list[i]->base;
124 unsigned long cfi_flash_bank_size(int i)
126 return flash_banks_list[i]->size;
129 static void detect_num_flash_banks(void)
131 const struct memory_bank *memory_bank, *end;
133 cfi_flash_num_flash_banks = 0;
135 memory_bank = memory_banks;
136 end = memory_bank + ARRAY_SIZE(memory_banks);
138 for (; memory_bank < end; memory_bank++) {
139 if (cfi_flash_num_flash_banks >=
140 CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
143 if (mem_is_flash(memory_bank)) {
144 flash_banks_list[cfi_flash_num_flash_banks] =
147 debug("flash bank found: base = 0x%lx, size = 0x%lx\n",
148 (unsigned long)memory_bank->base,
149 (unsigned long)memory_bank->size);
150 cfi_flash_num_flash_banks++;
154 debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
156 #else /* CONFIG_MTD_NOR_FLASH */
157 static void detect_num_flash_banks(void)
160 #endif /* CONFIG_MTD_NOR_FLASH */
162 void support_card_late_init(void)
164 detect_num_flash_banks();
167 static const u8 ledval_num[] = {
180 static const u8 ledval_alpha[] = {
209 static u8 char2ledval(char c)
212 return ledval_num[c - '0'];
214 return ledval_alpha[toupper(c) - 'A'];
219 void led_puts(const char *s)
227 for (i = 0; i < 4; i++) {
229 val |= char2ledval(*s);
234 writel(~val, LED_BASE);