Wolfgang Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2005 |
| 3 | * Sangmoon Kim, Etin Systems. dogoil@etinsys.com. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <mpc824x.h> |
| 10 | #include <pci.h> |
| 11 | #include <i2c.h> |
Ben Warren | 10efa02 | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 12 | #include <netdev.h> |
Wolfgang Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 13 | #include <asm/processor.h> |
Becky Bruce | d35ae5a | 2009-02-03 18:10:51 -0600 | [diff] [blame] | 14 | #include <asm/mmu.h> |
Wolfgang Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 15 | |
| 16 | int checkboard(void) |
| 17 | { |
| 18 | puts ("Board: KVME080\n"); |
| 19 | return 0; |
| 20 | } |
| 21 | |
| 22 | unsigned 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-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 34 | start = CONFIG_SYS_SDRAM_BASE; |
Wolfgang Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 35 | 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 Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 82 | phys_size_t initdram(int board_type) |
Wolfgang Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 83 | { |
| 84 | unsigned int msr; |
| 85 | long int size = 0; |
| 86 | |
| 87 | msr = mfmsr(); |
| 88 | mtmsr(msr & ~(MSR_IR | MSR_DR)); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 89 | 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 Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 93 | mtmsr(msr); |
| 94 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 95 | if (setdram(2,13,10,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x20000000)) |
Wolfgang Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 96 | size = 0x20000000; /* 512MB */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 97 | else if (setdram(1,13,10,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x10000000)) |
Wolfgang Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 98 | size = 0x10000000; /* 256MB */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 99 | else if (setdram(2,13,9,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x10000000)) |
Wolfgang Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 100 | size = 0x10000000; /* 256MB */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 101 | else if (setdram(1,13,9,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x08000000)) |
Wolfgang Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 102 | size = 0x08000000; /* 128MB */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 103 | else if (setdram(2,12,9,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x08000000)) |
Wolfgang Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 104 | size = 0x08000000; /* 128MB */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 105 | else if (setdram(1,12,9,4) == get_ram_size(CONFIG_SYS_SDRAM_BASE, 0x04000000)) |
Wolfgang Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 106 | size = 0x04000000; /* 64MB */ |
| 107 | |
| 108 | msr = mfmsr(); |
| 109 | mtmsr(msr & ~(MSR_IR | MSR_DR)); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 110 | mtspr(IBAT2L, CONFIG_SYS_IBAT2L); |
| 111 | mtspr(IBAT2U, CONFIG_SYS_IBAT2U); |
| 112 | mtspr(DBAT2L, CONFIG_SYS_DBAT2L); |
| 113 | mtspr(DBAT2U, CONFIG_SYS_DBAT2U); |
Wolfgang Denk | 53dd6ce | 2006-07-21 11:29:20 +0200 | [diff] [blame] | 114 | mtmsr(msr); |
| 115 | |
| 116 | return size; |
| 117 | } |
| 118 | |
| 119 | struct pci_controller hose; |
| 120 | |
| 121 | void pci_init_board(void) |
| 122 | { |
| 123 | pci_mpc824x_init(&hose); |
| 124 | } |
| 125 | |
| 126 | int board_early_init_f(void) |
| 127 | { |
| 128 | *(volatile unsigned char *)(0xff080120) = 0xfb; |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | int 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 | |
| 152 | extern int multiverse_init(void); |
| 153 | |
| 154 | int misc_init_r(void) |
| 155 | { |
| 156 | multiverse_init(); |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | void *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 | |
| 171 | void 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 Warren | 10efa02 | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 180 | |
| 181 | int board_eth_init(bd_t *bis) |
| 182 | { |
| 183 | return pci_eth_init(bis); |
| 184 | } |