wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 1 | /*------------------------------------------------------------------------------+ |
Josh Boyer | 3177349 | 2009-08-07 13:53:20 -0400 | [diff] [blame] | 2 | * This source code is dual-licensed. You may use it under the terms of |
| 3 | * the GNU General Public License version 2, or under the license below. |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 4 | * |
| 5 | * This source code has been made available to you by IBM on an AS-IS |
| 6 | * basis. Anyone receiving this source is licensed under IBM |
| 7 | * copyrights to use it in any way he or she deems fit, including |
| 8 | * copying it, modifying it, compiling it, and redistributing it either |
| 9 | * with or without modifications. No license under IBM patents or |
| 10 | * patent applications is to be implied by the copyright license. |
| 11 | * |
| 12 | * Any user of this software should understand that IBM cannot provide |
| 13 | * technical support for this software and will not be responsible for |
| 14 | * any consequences resulting from the use of this software. |
| 15 | * |
| 16 | * Any person who transfers this source code or any derivative work |
| 17 | * must include the IBM copyright notice, this paragraph, and the |
| 18 | * preceding two paragraphs in the transferred software. |
| 19 | * |
| 20 | * COPYRIGHT I B M CORPORATION 1995 |
| 21 | * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M |
| 22 | *-------------------------------------------------------------------------------*/ |
| 23 | |
| 24 | /*----------------------------------------------------------------------------- |
| 25 | * Function: ext_bus_cntlr_init |
| 26 | * Description: Initializes the External Bus Controller for the external |
| 27 | * peripherals. IMPORTANT: For pass1 this code must run from |
| 28 | * cache since you can not reliably change a peripheral banks |
| 29 | * timing register (pbxap) while running code from that bank. |
| 30 | * For ex., since we are running from ROM on bank 0, we can NOT |
| 31 | * execute the code that modifies bank 0 timings from ROM, so |
| 32 | * we run it from cache. |
| 33 | * Bank 0 - Flash or Multi Purpose Socket |
| 34 | * Bank 1 - Multi Purpose Socket or Flash (set in C-Code) |
| 35 | * Bank 2 - UART 1 (set in C-Code) |
| 36 | * Bank 3 - UART 2 (set in C-Code) |
| 37 | * Bank 4 - not used |
| 38 | * Bank 5 - not used |
| 39 | * Bank 6 - not used |
| 40 | * Bank 7 - PLD Register |
| 41 | *-----------------------------------------------------------------------------*/ |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 42 | #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */ |
| 43 | |
| 44 | #include <configs/MIP405.h> |
| 45 | #include <ppc_asm.tmpl> |
| 46 | #include <ppc_defs.h> |
| 47 | |
| 48 | #include <asm/cache.h> |
| 49 | #include <asm/mmu.h> |
Stefan Roese | afabb49 | 2010-09-12 06:21:37 +0200 | [diff] [blame] | 50 | #include <asm/ppc4xx.h> |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 51 | #include "mip405.h" |
| 52 | |
| 53 | |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 54 | .globl ext_bus_cntlr_init |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 55 | ext_bus_cntlr_init: |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 56 | mflr r4 /* save link register */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 57 | mfdcr r3,CPC0_PSR /* get strapping reg */ |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 58 | andi. r0, r3, PSR_ROM_LOC /* mask out irrelevant bits */ |
| 59 | bnelr /* jump back if PCI boot */ |
| 60 | |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 61 | bl ..getAddr |
| 62 | ..getAddr: |
| 63 | mflr r3 /* get address of ..getAddr */ |
| 64 | mtlr r4 /* restore link register */ |
| 65 | addi r4,0,14 /* set ctr to 14; used to prefetch */ |
| 66 | mtctr r4 /* 14 cache lines to fit this function */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 67 | /* in cache (gives us 8x14=112 instrctns) */ |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 68 | ..ebcloop: |
| 69 | icbt r0,r3 /* prefetch cache line for addr in r3 */ |
| 70 | addi r3,r3,32 /* move to next cache line */ |
| 71 | bdnz ..ebcloop /* continue for 14 cache lines */ |
| 72 | |
| 73 | /*------------------------------------------------------------------- |
| 74 | * Delay to ensure all accesses to ROM are complete before changing |
| 75 | * bank 0 timings. |
| 76 | *------------------------------------------------------------------- */ |
| 77 | addis r3,0,0x0 |
| 78 | ori r3,r3,0xA000 |
| 79 | mtctr r3 |
| 80 | ..spinlp: |
| 81 | bdnz ..spinlp /* spin loop */ |
| 82 | |
| 83 | /*----------------------------------------------------------------------- |
| 84 | * decide boot up mode |
| 85 | *----------------------------------------------------------------------- */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 86 | addi r4,0,PB0CR |
| 87 | mtdcr EBC0_CFGADDR,r4 |
| 88 | mfdcr r4,EBC0_CFGDATA |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 89 | |
| 90 | andi. r0, r4, 0x2000 /* mask out irrelevant bits */ |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 91 | beq 0f /* jump if 8 bit bus width */ |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 92 | |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 93 | /* setup 16 bit things |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 94 | *----------------------------------------------------------------------- |
| 95 | * Memory Bank 0 (16 Bit Flash) initialization |
| 96 | *---------------------------------------------------------------------- */ |
| 97 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 98 | addi r4,0,PB1AP |
| 99 | mtdcr EBC0_CFGADDR,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 100 | addis r4,0,(FLASH_AP_B)@h |
| 101 | ori r4,r4,(FLASH_AP_B)@l |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 102 | mtdcr EBC0_CFGDATA,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 103 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 104 | addi r4,0,PB0CR |
| 105 | mtdcr EBC0_CFGADDR,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 106 | /* BS=0x010(4MB),BU=0x3(R/W), */ |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 107 | addis r4,0,(FLASH_CR_B)@h |
| 108 | ori r4,r4,(FLASH_CR_B)@l |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 109 | mtdcr EBC0_CFGDATA,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 110 | b 1f |
| 111 | |
| 112 | 0: |
| 113 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 114 | /* 8Bit boot mode: */ |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 115 | /*----------------------------------------------------------------------- |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 116 | * Memory Bank 0 Multi Purpose Socket initialization |
| 117 | *----------------------------------------------------------------------- */ |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 118 | /* 0x7F8FFE80 slowest boot */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 119 | addi r4,0,PB1AP |
| 120 | mtdcr EBC0_CFGADDR,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 121 | addis r4,0,(MPS_AP_B)@h |
| 122 | ori r4,r4,(MPS_AP_B)@l |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 123 | mtdcr EBC0_CFGDATA,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 124 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 125 | addi r4,0,PB0CR |
| 126 | mtdcr EBC0_CFGADDR,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 127 | /* BS=0x010(4MB),BU=0x3(R/W), */ |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 128 | addis r4,0,(MPS_CR_B)@h |
| 129 | ori r4,r4,(MPS_CR_B)@l |
| 130 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 131 | mtdcr EBC0_CFGDATA,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 132 | |
| 133 | |
| 134 | 1: |
| 135 | /*----------------------------------------------------------------------- |
| 136 | * Memory Bank 2-3-4-5-6 (not used) initialization |
| 137 | *-----------------------------------------------------------------------*/ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 138 | addi r4,0,PB1CR |
| 139 | mtdcr EBC0_CFGADDR,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 140 | addis r4,0,0x0000 |
| 141 | ori r4,r4,0x0000 |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 142 | mtdcr EBC0_CFGDATA,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 143 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 144 | addi r4,0,PB2CR |
| 145 | mtdcr EBC0_CFGADDR,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 146 | addis r4,0,0x0000 |
| 147 | ori r4,r4,0x0000 |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 148 | mtdcr EBC0_CFGDATA,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 149 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 150 | addi r4,0,PB3CR |
| 151 | mtdcr EBC0_CFGADDR,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 152 | addis r4,0,0x0000 |
| 153 | ori r4,r4,0x0000 |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 154 | mtdcr EBC0_CFGDATA,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 155 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 156 | addi r4,0,PB4CR |
| 157 | mtdcr EBC0_CFGADDR,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 158 | addis r4,0,0x0000 |
| 159 | ori r4,r4,0x0000 |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 160 | mtdcr EBC0_CFGDATA,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 161 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 162 | addi r4,0,PB5CR |
| 163 | mtdcr EBC0_CFGADDR,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 164 | addis r4,0,0x0000 |
| 165 | ori r4,r4,0x0000 |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 166 | mtdcr EBC0_CFGDATA,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 167 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 168 | addi r4,0,PB6CR |
| 169 | mtdcr EBC0_CFGADDR,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 170 | addis r4,0,0x0000 |
| 171 | ori r4,r4,0x0000 |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 172 | mtdcr EBC0_CFGDATA,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 173 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 174 | addi r4,0,PB7CR |
| 175 | mtdcr EBC0_CFGADDR,r4 |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 176 | addis r4,0,0x0000 |
| 177 | ori r4,r4,0x0000 |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 178 | mtdcr EBC0_CFGDATA,r4 |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 179 | nop /* pass2 DCR errata #8 */ |
wdenk | 37bd321 | 2002-11-03 11:21:28 +0000 | [diff] [blame] | 180 | blr |
| 181 | |
wdenk | f3e0de6 | 2003-06-04 15:05:30 +0000 | [diff] [blame] | 182 | #if defined(CONFIG_BOOT_PCI) |
| 183 | .section .bootpg,"ax" |
| 184 | .globl _start_pci |
| 185 | /******************************************* |
| 186 | */ |
| 187 | |
| 188 | _start_pci: |
| 189 | /* first handle errata #68 / PCI_18 */ |
| 190 | iccci r0, r0 /* invalidate I-cache */ |
| 191 | lis r31, 0 |
| 192 | mticcr r31 /* ICCR = 0 (all uncachable) */ |
| 193 | isync |
| 194 | |
| 195 | mfccr0 r28 /* set CCR0[24] = 1 */ |
| 196 | ori r28, r28, 0x0080 |
| 197 | mtccr0 r28 |
| 198 | |
| 199 | /* setup PMM0MA (0xEF400004) and PMM0PCIHA (0xEF40000C) */ |
| 200 | lis r28, 0xEF40 |
| 201 | addi r28, r28, 0x0004 |
| 202 | stw r31, 0x0C(r28) /* clear PMM0PCIHA */ |
| 203 | lis r29, 0xFFF8 /* open 512 kByte */ |
| 204 | addi r29, r29, 0x0001/* and enable this region */ |
| 205 | stwbrx r29, r0, r28 /* write PMM0MA */ |
| 206 | |
| 207 | lis r28, 0xEEC0 /* address of PCIC0_CFGADDR */ |
| 208 | addi r29, r28, 4 /* add 4 to r29 -> PCIC0_CFGDATA */ |
| 209 | |
| 210 | lis r31, 0x8000 /* set en bit bus 0 */ |
| 211 | ori r31, r31, 0x304C/* device 6 func 0 reg 4C (XBCS register) */ |
| 212 | stwbrx r31, r0, r28 /* write it */ |
| 213 | |
| 214 | lwbrx r31, r0, r29 /* load XBCS register */ |
| 215 | oris r31, r31, 0x02C4/* clear BIOSCS WPE, set lower, extended and 1M extended BIOS enable */ |
| 216 | stwbrx r31, r0, r29 /* write back XBCS register */ |
| 217 | |
| 218 | nop |
| 219 | nop |
| 220 | b _start /* normal start */ |
| 221 | #endif |