blob: baf4cbc4da1a33776f398fa1d6a4e8d602c1d023 [file] [log] [blame]
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +02001/*
2 * (C) Copyright 2005
3 * Sangmoon Kim, Etin Systems. dogoil@etinsys.com.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +02006 */
7
8#include <common.h>
9#include <mpc824x.h>
10#include <pci.h>
11#include <i2c.h>
Ben Warren10efa022008-08-31 20:37:00 -070012#include <netdev.h>
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +020013#include <asm/processor.h>
Becky Bruced35ae5a2009-02-03 18:10:51 -060014#include <asm/mmu.h>
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +020015
16int checkboard(void)
17{
18 puts ("Board: KVME080\n");
19 return 0;
20}
21
22unsigned long setdram(int m, int row, int col, int bank)
23{
24 int i;
25 unsigned long start, end;
26 uint32_t mccr1;
27 uint32_t mear1 = 0, emear1 = 0, msar1 = 0, emsar1 = 0;
28 uint32_t mear2 = 0, emear2 = 0, msar2 = 0, emsar2 = 0;
29 uint8_t mber = 0;
30
31 CONFIG_READ_WORD(MCCR1, mccr1);
32 mccr1 &= 0xffff0000;
33
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020034 start = CONFIG_SYS_SDRAM_BASE;
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +020035 end = start + (1 << (col + row + 3) ) * bank - 1;
36
37 for (i = 0; i < m; i++) {
38 mccr1 |= ((row == 13)? 2 : (bank == 4)? 0 : 3) << i * 2;
39 if (i < 4) {
40 msar1 |= ((start >> 20) & 0xff) << i * 8;
41 emsar1 |= ((start >> 28) & 0xff) << i * 8;
42 mear1 |= ((end >> 20) & 0xff) << i * 8;
43 emear1 |= ((end >> 28) & 0xff) << i * 8;
44 } else {
45 msar2 |= ((start >> 20) & 0xff) << (i-4) * 8;
46 emsar2 |= ((start >> 28) & 0xff) << (i-4) * 8;
47 mear2 |= ((end >> 20) & 0xff) << (i-4) * 8;
48 emear2 |= ((end >> 28) & 0xff) << (i-4) * 8;
49 }
50 mber |= 1 << i;
51 start += (1 << (col + row + 3) ) * bank;
52 end += (1 << (col + row + 3) ) * bank;
53 }
54 for (; i < 8; i++) {
55 if (i < 4) {
56 msar1 |= 0xff << i * 8;
57 emsar1 |= 0x30 << i * 8;
58 mear1 |= 0xff << i * 8;
59 emear1 |= 0x30 << i * 8;
60 } else {
61 msar2 |= 0xff << (i-4) * 8;
62 emsar2 |= 0x30 << (i-4) * 8;
63 mear2 |= 0xff << (i-4) * 8;
64 emear2 |= 0x30 << (i-4) * 8;
65 }
66 }
67
68 CONFIG_WRITE_WORD(MCCR1, mccr1);
69 CONFIG_WRITE_WORD(MSAR1, msar1);
70 CONFIG_WRITE_WORD(EMSAR1, emsar1);
71 CONFIG_WRITE_WORD(MEAR1, mear1);
72 CONFIG_WRITE_WORD(EMEAR1, emear1);
73 CONFIG_WRITE_WORD(MSAR2, msar2);
74 CONFIG_WRITE_WORD(EMSAR2, emsar2);
75 CONFIG_WRITE_WORD(MEAR2, mear2);
76 CONFIG_WRITE_WORD(EMEAR2, emear2);
77 CONFIG_WRITE_BYTE(MBER, mber);
78
79 return (1 << (col + row + 3) ) * bank * m;
80}
81
Becky Bruce9973e3c2008-06-09 16:03:40 -050082phys_size_t initdram(int board_type)
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +020083{
84 unsigned int msr;
85 long int size = 0;
86
87 msr = mfmsr();
88 mtmsr(msr & ~(MSR_IR | MSR_DR));
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020089 mtspr(IBAT2L, CONFIG_SYS_IBAT0L + 0x10000000);
90 mtspr(IBAT2U, CONFIG_SYS_IBAT0U + 0x10000000);
91 mtspr(DBAT2L, CONFIG_SYS_DBAT0L + 0x10000000);
92 mtspr(DBAT2U, CONFIG_SYS_DBAT0U + 0x10000000);
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +020093 mtmsr(msr);
94
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020095 if (setdram(2,13,10,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x20000000))
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +020096 size = 0x20000000; /* 512MB */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020097 else if (setdram(1,13,10,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x10000000))
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +020098 size = 0x10000000; /* 256MB */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020099 else if (setdram(2,13,9,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x10000000))
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +0200100 size = 0x10000000; /* 256MB */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200101 else if (setdram(1,13,9,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x08000000))
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +0200102 size = 0x08000000; /* 128MB */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200103 else if (setdram(2,12,9,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x08000000))
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +0200104 size = 0x08000000; /* 128MB */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200105 else if (setdram(1,12,9,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x04000000))
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +0200106 size = 0x04000000; /* 64MB */
107
108 msr = mfmsr();
109 mtmsr(msr & ~(MSR_IR | MSR_DR));
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200110 mtspr(IBAT2L, CONFIG_SYS_IBAT2L);
111 mtspr(IBAT2U, CONFIG_SYS_IBAT2U);
112 mtspr(DBAT2L, CONFIG_SYS_DBAT2L);
113 mtspr(DBAT2U, CONFIG_SYS_DBAT2U);
Wolfgang Denk53dd6ce2006-07-21 11:29:20 +0200114 mtmsr(msr);
115
116 return size;
117}
118
119struct pci_controller hose;
120
121void pci_init_board(void)
122{
123 pci_mpc824x_init(&hose);
124}
125
126int board_early_init_f(void)
127{
128 *(volatile unsigned char *)(0xff080120) = 0xfb;
129
130 return 0;
131}
132
133int board_early_init_r(void)
134{
135 unsigned int msr;
136
137 CONFIG_WRITE_WORD(ERCR1, 0x95ff8000);
138 CONFIG_WRITE_WORD(ERCR3, 0x0c00000e);
139 CONFIG_WRITE_WORD(ERCR4, 0x0800000e);
140
141 msr = mfmsr();
142 mtmsr(msr & ~(MSR_IR | MSR_DR));
143 mtspr(IBAT1L, 0x70000000 | BATL_PP_10 | BATL_CACHEINHIBIT);
144 mtspr(IBAT1U, 0x70000000 | BATU_BL_256M | BATU_VS | BATU_VP);
145 mtspr(DBAT1L, 0x70000000 | BATL_PP_10 | BATL_CACHEINHIBIT);
146 mtspr(DBAT1U, 0x70000000 | BATU_BL_256M | BATU_VS | BATU_VP);
147 mtmsr(msr);
148
149 return 0;
150}
151
152extern int multiverse_init(void);
153
154int misc_init_r(void)
155{
156 multiverse_init();
157 return 0;
158}
159
160void *nvram_read(void *dest, const long src, size_t count)
161{
162 volatile uchar *d = (volatile uchar*) dest;
163 volatile uchar *s = (volatile uchar*) src;
164 while(count--) {
165 *d++ = *s++;
166 asm volatile("sync");
167 }
168 return dest;
169}
170
171void nvram_write(long dest, const void *src, size_t count)
172{
173 volatile uchar *d = (volatile uchar*)dest;
174 volatile uchar *s = (volatile uchar*)src;
175 while(count--) {
176 *d++ = *s++;
177 asm volatile("sync");
178 }
179}
Ben Warren10efa022008-08-31 20:37:00 -0700180
181int board_eth_init(bd_t *bis)
182{
183 return pci_eth_init(bis);
184}