blob: 4ca6ffea2dc704ea699208292b579898d40e751c [file] [log] [blame]
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09001/*
Masahiro Yamada663a23f2015-05-29 17:30:00 +09002 * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Masahiro Yamada663a23f2015-05-29 17:30:00 +09008#include <linux/io.h>
Masahiro Yamada95387e22015-02-27 02:26:44 +09009#include <mach/board.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090010
Masahiro Yamada4903b6d2015-09-11 20:17:45 +090011#define MICRO_SUPPORT_CARD_RESET \
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090012 ((CONFIG_SUPPORT_CARD_BASE) + 0x000D0034)
Masahiro Yamada4903b6d2015-09-11 20:17:45 +090013#define MICRO_SUPPORT_CARD_REVISION \
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090014 ((CONFIG_SUPPORT_CARD_BASE) + 0x000D00E0)
15/*
16 * 0: reset deassert, 1: reset
17 *
18 * bit[0]: LAN, I2C, LED
19 * bit[1]: UART
20 */
21void support_card_reset_deassert(void)
22{
Masahiro Yamada4903b6d2015-09-11 20:17:45 +090023 writel(0, MICRO_SUPPORT_CARD_RESET);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090024}
25
26void support_card_reset(void)
27{
Masahiro Yamada4903b6d2015-09-11 20:17:45 +090028 writel(3, MICRO_SUPPORT_CARD_RESET);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090029}
30
31static int support_card_show_revision(void)
32{
33 u32 revision;
34
Masahiro Yamada4903b6d2015-09-11 20:17:45 +090035 revision = readl(MICRO_SUPPORT_CARD_REVISION);
36 printf("(CPLD version %d.%d)\n", revision >> 4, revision & 0xf);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090037 return 0;
38}
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090039
Masahiro Yamada88216812014-12-06 00:03:26 +090040int check_support_card(void)
41{
42 printf("SC: Micro Support Card ");
43 return support_card_show_revision();
44}
45
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090046void support_card_init(void)
47{
48 /*
49 * After power on, we need to keep the LAN controller in reset state
50 * for a while. (200 usec)
Masahiro Yamada5d3d9962015-03-23 00:07:30 +090051 * Fortunately, enough wait time is already inserted in pll_init()
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090052 * function. So we do not have to wait here.
53 */
54 support_card_reset_deassert();
55}
56
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090057#if defined(CONFIG_SMC911X)
58#include <netdev.h>
59
60int board_eth_init(bd_t *bis)
61{
62 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
63}
64#endif
65
66#if !defined(CONFIG_SYS_NO_FLASH)
67
68#include <mtd/cfi_flash.h>
Masahiro Yamada95387e22015-02-27 02:26:44 +090069#include <mach/sbc-regs.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090070
Masahiro Yamada88216812014-12-06 00:03:26 +090071struct memory_bank {
72 phys_addr_t base;
73 unsigned long size;
74};
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090075
Masahiro Yamada88216812014-12-06 00:03:26 +090076static int mem_is_flash(const struct memory_bank *mem)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090077{
78 const int loop = 128;
79 u32 *scratch_addr;
80 u32 saved_value;
81 int ret = 1;
82 int i;
83
Masahiro Yamada88216812014-12-06 00:03:26 +090084 /* just in case, use the tail of the memory bank */
85 scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop,
86 sizeof(u32) * loop, MAP_NOCACHE);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090087
88 for (i = 0; i < loop; i++, scratch_addr++) {
89 saved_value = readl(scratch_addr);
90 writel(~saved_value, scratch_addr);
91 if (readl(scratch_addr) != saved_value) {
92 /* We assume no memory or SRAM here. */
93 writel(saved_value, scratch_addr);
94 ret = 0;
95 break;
96 }
97 }
98
99 unmap_physmem(scratch_addr, MAP_NOCACHE);
100
101 return ret;
102}
103
Masahiro Yamada4903b6d2015-09-11 20:17:45 +0900104/* {address, size} */
105static const struct memory_bank memory_banks[] = {
Masahiro Yamada88216812014-12-06 00:03:26 +0900106 {0x02000000, 0x01f00000},
107};
108
Masahiro Yamada88216812014-12-06 00:03:26 +0900109static const struct memory_bank
110*flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
111
112phys_addr_t cfi_flash_bank_addr(int i)
113{
114 return flash_banks_list[i]->base;
115}
116
117unsigned long cfi_flash_bank_size(int i)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900118{
Masahiro Yamada88216812014-12-06 00:03:26 +0900119 return flash_banks_list[i]->size;
120}
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900121
Masahiro Yamada88216812014-12-06 00:03:26 +0900122static void detect_num_flash_banks(void)
123{
124 const struct memory_bank *memory_bank, *end;
125
126 cfi_flash_num_flash_banks = 0;
127
Masahiro Yamada4903b6d2015-09-11 20:17:45 +0900128 memory_bank = memory_banks;
129 end = memory_bank + ARRAY_SIZE(memory_banks);
Masahiro Yamada88216812014-12-06 00:03:26 +0900130
131 for (; memory_bank < end; memory_bank++) {
132 if (cfi_flash_num_flash_banks >=
133 CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
134 break;
135
136 if (mem_is_flash(memory_bank)) {
137 flash_banks_list[cfi_flash_num_flash_banks] =
138 memory_bank;
139
140 debug("flash bank found: base = 0x%lx, size = 0x%lx\n",
141 memory_bank->base, memory_bank->size);
142 cfi_flash_num_flash_banks++;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900143 }
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900144 }
145
Masahiro Yamada88216812014-12-06 00:03:26 +0900146 debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900147}
Masahiro Yamada5d3d9962015-03-23 00:07:30 +0900148#else /* CONFIG_SYS_NO_FLASH */
Masahiro Yamada88216812014-12-06 00:03:26 +0900149void detect_num_flash_banks(void)
150{
151};
Masahiro Yamada5d3d9962015-03-23 00:07:30 +0900152#endif /* CONFIG_SYS_NO_FLASH */
Masahiro Yamada88216812014-12-06 00:03:26 +0900153
154void support_card_late_init(void)
155{
156 detect_num_flash_banks();
157}