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)
21 static bool support_card_found;
23 static void support_card_detect(void)
25 DECLARE_GLOBAL_DATA_PTR;
26 const void *fdt = gd->fdt_blob;
29 offset = fdt_node_offset_by_compatible(fdt, 0, "smsc,lan9118");
33 offset = fdt_node_offset_by_compatible(fdt, 0, "ns16550a");
37 support_card_found = true;
41 * 0: reset deassert, 1: reset
43 * bit[0]: LAN, I2C, LED
46 static void support_card_reset_deassert(void)
48 writel(0x00010000, MICRO_SUPPORT_CARD_RESET);
51 static void support_card_reset(void)
53 writel(0x00020003, MICRO_SUPPORT_CARD_RESET);
56 static int support_card_show_revision(void)
60 revision = readl(MICRO_SUPPORT_CARD_REVISION);
63 /* revision 3.6.x card changed the revision format */
64 printf("SC: Micro Support Card (CPLD version %s%d.%d)\n",
65 revision >> 4 == 6 ? "3." : "",
66 revision >> 4, revision & 0xf);
71 void support_card_init(void)
73 support_card_detect();
75 if (!support_card_found)
80 * After power on, we need to keep the LAN controller in reset state
81 * for a while. (200 usec)
84 support_card_reset_deassert();
86 support_card_show_revision();
89 #if defined(CONFIG_SMC911X)
92 int board_eth_init(bd_t *bis)
94 if (!support_card_found)
97 return smc911x_initialize(0, SMC911X_BASE);
101 #if defined(CONFIG_MTD_NOR_FLASH)
103 #include <mtd/cfi_flash.h>
110 static int mem_is_flash(const struct memory_bank *mem)
112 const int loop = 128;
118 /* just in case, use the tail of the memory bank */
119 scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop,
120 sizeof(u32) * loop, MAP_NOCACHE);
122 for (i = 0; i < loop; i++, scratch_addr++) {
123 saved_value = readl(scratch_addr);
124 writel(~saved_value, scratch_addr);
125 if (readl(scratch_addr) != saved_value) {
126 /* We assume no memory or SRAM here. */
127 writel(saved_value, scratch_addr);
133 unmap_physmem(scratch_addr, MAP_NOCACHE);
138 /* {address, size} */
139 static const struct memory_bank memory_banks[] = {
140 {0x42000000, 0x01f00000},
143 static const struct memory_bank
144 *flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
146 phys_addr_t cfi_flash_bank_addr(int i)
148 return flash_banks_list[i]->base;
151 unsigned long cfi_flash_bank_size(int i)
153 return flash_banks_list[i]->size;
156 static void detect_num_flash_banks(void)
158 const struct memory_bank *memory_bank, *end;
160 cfi_flash_num_flash_banks = 0;
162 memory_bank = memory_banks;
163 end = memory_bank + ARRAY_SIZE(memory_banks);
165 for (; memory_bank < end; memory_bank++) {
166 if (cfi_flash_num_flash_banks >=
167 CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
170 if (mem_is_flash(memory_bank)) {
171 flash_banks_list[cfi_flash_num_flash_banks] =
174 debug("flash bank found: base = 0x%lx, size = 0x%lx\n",
175 (unsigned long)memory_bank->base,
176 (unsigned long)memory_bank->size);
177 cfi_flash_num_flash_banks++;
181 debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
183 #else /* CONFIG_MTD_NOR_FLASH */
184 static void detect_num_flash_banks(void)
187 #endif /* CONFIG_MTD_NOR_FLASH */
189 void support_card_late_init(void)
191 if (!support_card_found)
194 detect_num_flash_banks();
197 static const u8 ledval_num[] = {
210 static const u8 ledval_alpha[] = {
239 static u8 char2ledval(char c)
242 return ledval_num[c - '0'];
244 return ledval_alpha[toupper(c) - 'A'];
249 void led_puts(const char *s)
254 if (!support_card_found)
260 for (i = 0; i < 4; i++) {
262 val |= char2ledval(*s);
267 writel(~val, LED_BASE);