]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/uniphier/support_card.c
Merge branch 'master' of git://git.denx.de/u-boot-usb
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / uniphier / support_card.c
1 /*
2  * Copyright (C) 2012-2014 Panasonic Corporation
3  *   Author: Masahiro Yamada <yamada.m@jp.panasonic.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <asm/io.h>
10 #include <asm/arch/board.h>
11
12 #if defined(CONFIG_PFC_MICRO_SUPPORT_CARD)
13
14 #define PFC_MICRO_SUPPORT_CARD_RESET    \
15                                 ((CONFIG_SUPPORT_CARD_BASE) + 0x000D0034)
16 #define PFC_MICRO_SUPPORT_CARD_REVISION \
17                                 ((CONFIG_SUPPORT_CARD_BASE) + 0x000D00E0)
18 /*
19  * 0: reset deassert, 1: reset
20  *
21  * bit[0]: LAN, I2C, LED
22  * bit[1]: UART
23  */
24 void support_card_reset_deassert(void)
25 {
26         writel(0, PFC_MICRO_SUPPORT_CARD_RESET);
27 }
28
29 void support_card_reset(void)
30 {
31         writel(3, PFC_MICRO_SUPPORT_CARD_RESET);
32 }
33
34 static int support_card_show_revision(void)
35 {
36         u32 revision;
37
38         revision = readl(PFC_MICRO_SUPPORT_CARD_REVISION);
39         printf("(PFC CPLD version %d.%d)\n", revision >> 4, revision & 0xf);
40         return 0;
41 }
42 #endif
43
44 #if defined(CONFIG_DCC_MICRO_SUPPORT_CARD)
45
46 #define DCC_MICRO_SUPPORT_CARD_RESET_LAN        \
47                                 ((CONFIG_SUPPORT_CARD_BASE) + 0x00401300)
48 #define DCC_MICRO_SUPPORT_CARD_RESET_UART       \
49                                 ((CONFIG_SUPPORT_CARD_BASE) + 0x00401304)
50 #define DCC_MICRO_SUPPORT_CARD_RESET_I2C        \
51                                 ((CONFIG_SUPPORT_CARD_BASE) + 0x00401308)
52 #define DCC_MICRO_SUPPORT_CARD_REVISION         \
53                                 ((CONFIG_SUPPORT_CARD_BASE) + 0x005000E0)
54
55 void support_card_reset_deassert(void)
56 {
57         writel(1, DCC_MICRO_SUPPORT_CARD_RESET_LAN); /* LAN and LED */
58         writel(1, DCC_MICRO_SUPPORT_CARD_RESET_UART); /* UART */
59         writel(1, DCC_MICRO_SUPPORT_CARD_RESET_I2C); /* I2C */
60 }
61
62 void support_card_reset(void)
63 {
64         writel(0, DCC_MICRO_SUPPORT_CARD_RESET_LAN); /* LAN and LED */
65         writel(0, DCC_MICRO_SUPPORT_CARD_RESET_UART); /* UART */
66         writel(0, DCC_MICRO_SUPPORT_CARD_RESET_I2C); /* I2C */
67 }
68
69 static int support_card_show_revision(void)
70 {
71         u32 revision;
72
73         revision = readl(DCC_MICRO_SUPPORT_CARD_REVISION);
74
75         if (revision >= 0x67) {
76                 printf("(DCC CPLD version 3.%d.%d)\n",
77                        revision >> 4, revision & 0xf);
78                 return 0;
79         } else {
80                 printf("(DCC CPLD unknown version)\n");
81                 return -1;
82         }
83 }
84 #endif
85
86 int check_support_card(void)
87 {
88         printf("SC:    Micro Support Card ");
89         return support_card_show_revision();
90 }
91
92 void support_card_init(void)
93 {
94         /*
95          * After power on, we need to keep the LAN controller in reset state
96          * for a while. (200 usec)
97          * Fortunatelly, enough wait time is already inserted in pll_init()
98          * function. So we do not have to wait here.
99          */
100         support_card_reset_deassert();
101 }
102
103 #if defined(CONFIG_SMC911X)
104 #include <netdev.h>
105
106 int board_eth_init(bd_t *bis)
107 {
108         return smc911x_initialize(0, CONFIG_SMC911X_BASE);
109 }
110 #endif
111
112 #if !defined(CONFIG_SYS_NO_FLASH)
113
114 #include <mtd/cfi_flash.h>
115 #include <asm/arch/sbc-regs.h>
116
117 struct memory_bank {
118         phys_addr_t base;
119         unsigned long size;
120 };
121
122 static int mem_is_flash(const struct memory_bank *mem)
123 {
124         const int loop = 128;
125         u32 *scratch_addr;
126         u32 saved_value;
127         int ret = 1;
128         int i;
129
130         /* just in case, use the tail of the memory bank */
131         scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop,
132                                    sizeof(u32) * loop, MAP_NOCACHE);
133
134         for (i = 0; i < loop; i++, scratch_addr++) {
135                 saved_value = readl(scratch_addr);
136                 writel(~saved_value, scratch_addr);
137                 if (readl(scratch_addr) != saved_value) {
138                         /* We assume no memory or SRAM here. */
139                         writel(saved_value, scratch_addr);
140                         ret = 0;
141                         break;
142                 }
143         }
144
145         unmap_physmem(scratch_addr, MAP_NOCACHE);
146
147         return ret;
148 }
149
150 #if defined(CONFIG_PFC_MICRO_SUPPORT_CARD)
151         /* {address, size} */
152 static const struct memory_bank memory_banks_boot_swap_off[] = {
153         {0x02000000, 0x01f00000},
154 };
155
156 static const struct memory_bank memory_banks_boot_swap_on[] = {
157         {0x00000000, 0x01f00000},
158 };
159 #endif
160
161 #if defined(CONFIG_DCC_MICRO_SUPPORT_CARD)
162 static const struct memory_bank memory_banks_boot_swap_off[] = {
163         {0x04000000, 0x04000000},
164 };
165
166 static const struct memory_bank memory_banks_boot_swap_on[] = {
167         {0x00000000, 0x04000000},
168         {0x04000000, 0x04000000},
169 };
170 #endif
171
172 static const struct memory_bank
173 *flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
174
175 phys_addr_t cfi_flash_bank_addr(int i)
176 {
177         return flash_banks_list[i]->base;
178 }
179
180 unsigned long cfi_flash_bank_size(int i)
181 {
182         return flash_banks_list[i]->size;
183 }
184
185 static void detect_num_flash_banks(void)
186 {
187         const struct memory_bank *memory_bank, *end;
188
189         cfi_flash_num_flash_banks = 0;
190
191         if (boot_is_swapped()) {
192                 memory_bank = memory_banks_boot_swap_on;
193                 end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_on);
194         } else {
195                 memory_bank = memory_banks_boot_swap_off;
196                 end = memory_bank + ARRAY_SIZE(memory_banks_boot_swap_off);
197         }
198
199         for (; memory_bank < end; memory_bank++) {
200                 if (cfi_flash_num_flash_banks >=
201                     CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
202                         break;
203
204                 if (mem_is_flash(memory_bank)) {
205                         flash_banks_list[cfi_flash_num_flash_banks] =
206                                                                 memory_bank;
207
208                         debug("flash bank found: base = 0x%lx, size = 0x%lx\n",
209                               memory_bank->base, memory_bank->size);
210                         cfi_flash_num_flash_banks++;
211                 }
212         }
213
214         debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
215 }
216 #else /* ONFIG_SYS_NO_FLASH */
217 void detect_num_flash_banks(void)
218 {
219 };
220 #endif /* ONFIG_SYS_NO_FLASH */
221
222 void support_card_late_init(void)
223 {
224         detect_num_flash_banks();
225 }