Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 1 | /* |
| 2 | *(C) Copyright 2005-2007 Netstal Maschinen AG |
| 3 | * Niklaus Giger (Niklaus.Giger@netstal.com) |
| 4 | * |
| 5 | * This source code is free software; you can redistribute it |
| 6 | * and/or modify it in source code form under the terms of the GNU |
| 7 | * General Public License as published by the Free Software |
| 8 | * Foundation; either version 2 of the License, or (at your option) |
| 9 | * any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
| 19 | */ |
| 20 | |
| 21 | #include <common.h> |
| 22 | #include <ppc4xx.h> |
| 23 | #include <asm/processor.h> |
| 24 | #include <asm/io.h> |
| 25 | #include <asm-ppc/u-boot.h> |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 26 | #include "../common/nm.h" |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Stefan Roese | 0a677fd | 2007-08-10 10:42:25 +0200 | [diff] [blame] | 30 | #define HCU_MACH_VERSIONS_REGISTER (0x7C000000 + 0xF00000) |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 31 | #define SYS_SLOT_ADDRESS (0x7C000000 + 0x400000) |
| 32 | #define HCU3_DIGITAL_IO_REGISTER (0x7C000000 + 0x500000) |
| 33 | #define HCU_SW_INSTALL_REQUESTED 0x10 |
Stefan Roese | 0a677fd | 2007-08-10 10:42:25 +0200 | [diff] [blame] | 34 | |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 35 | #undef DEBUG |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 36 | |
| 37 | #if defined(DEBUG) |
| 38 | void show_sdram_registers(void); |
| 39 | #endif |
Stefan Roese | 9153cd3 | 2008-01-17 14:29:04 +0100 | [diff] [blame] | 40 | long int fixed_hcu4_sdram (unsigned int dram_size); |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * This function is run very early, out of flash, and before devices are |
| 44 | * initialized. It is called by lib_ppc/board.c:board_init_f by virtue |
| 45 | * of being in the init_sequence array. |
| 46 | * |
| 47 | * The SDRAM has been initialized already -- start.S:start called |
| 48 | * init.S:init_sdram early on -- but it is not yet being used for |
| 49 | * anything, not even stack. So be careful. |
| 50 | */ |
| 51 | |
| 52 | #define CPC0_CR0 0xb1 /* Chip control register 0 */ |
| 53 | #define CPC0_CR1 0xb2 /* Chip control register 1 */ |
| 54 | /* Attention: If you want 1 microsecs times from the external oscillator |
| 55 | * use 0x00804051. But this causes problems with u-boot and linux! |
| 56 | */ |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 57 | #define CPC0_CR0_VALUE 0x0030103c |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 58 | #define CPC0_CR1_VALUE 0x00004051 |
| 59 | #define CPC0_ECR 0xaa /* Edge condition register */ |
| 60 | #define EBC0_CFG 0x23 /* External Peripheral Control Register */ |
| 61 | #define CPC0_EIRR 0xb6 /* External Interrupt Register */ |
| 62 | |
| 63 | |
| 64 | int board_early_init_f (void) |
| 65 | { |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 66 | /* |
| 67 | * Interrupt controller setup for the HCU4 board. |
| 68 | * Note: IRQ 0-15 405GP internally generated; high; level sensitive |
| 69 | * IRQ 16 405GP internally generated; low; level sensitive |
| 70 | * IRQ 17-24 RESERVED/UNUSED |
| 71 | * IRQ 31 (EXT IRQ 6) (unused) |
| 72 | */ |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 73 | mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */ |
| 74 | mtdcr (uicer, 0x00000000); /* disable all ints */ |
| 75 | mtdcr (uiccr, 0x00000000); /* set all to be non-critical */ |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 76 | mtdcr (uicpr, 0xFFFFE000); /* set int polarities */ |
| 77 | mtdcr (uictr, 0x00000000); /* set int trigger levels */ |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 78 | mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */ |
| 79 | |
| 80 | mtdcr(CPC0_CR1, CPC0_CR1_VALUE); |
| 81 | mtdcr(CPC0_ECR, 0x60606000); |
| 82 | mtdcr(CPC0_EIRR, 0x7c000000); |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | #ifdef CONFIG_BOARD_PRE_INIT |
| 88 | int board_pre_init (void) |
| 89 | { |
| 90 | return board_early_init_f (); |
| 91 | } |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 92 | #endif |
| 93 | |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 94 | int sys_install_requested(void) |
| 95 | { |
| 96 | u16 *ioValuePtr = (u16 *)HCU3_DIGITAL_IO_REGISTER; |
| 97 | return (in_be16(ioValuePtr) & HCU_SW_INSTALL_REQUESTED) != 0; |
| 98 | } |
| 99 | |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 100 | int checkboard (void) |
| 101 | { |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 102 | u16 *boardVersReg = (u16 *)HCU_MACH_VERSIONS_REGISTER; |
| 103 | u16 generation = in_be16(boardVersReg) & 0xf0; |
| 104 | u16 index = in_be16(boardVersReg) & 0x0f; |
Stefan Roese | 0a677fd | 2007-08-10 10:42:25 +0200 | [diff] [blame] | 105 | |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 106 | /* Cannot be done, in board_early_init */ |
| 107 | mtdcr(CPC0_CR0, CPC0_CR0_VALUE); |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 108 | /* Force /RTS to active. The board it not wired quite |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 109 | * correctly to use cts/rtc flow control, so just force the |
| 110 | * /RST active and forget about it. |
| 111 | */ |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 112 | writeb (readb (0xef600404) | 0x03, 0xef600404); |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 113 | nm_show_print(generation, index, 0); |
Stefan Roese | 0a677fd | 2007-08-10 10:42:25 +0200 | [diff] [blame] | 114 | |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
Niklaus Giger | c215781 | 2007-08-16 15:16:03 +0200 | [diff] [blame] | 118 | u32 hcu_led_get(void) |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 119 | { |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 120 | return (~(in_be32((u32 *)GPIO0_OR)) >> 23) & 0xff; |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 121 | } |
| 122 | |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 123 | /* |
Niklaus Giger | c215781 | 2007-08-16 15:16:03 +0200 | [diff] [blame] | 124 | * hcu_led_set value to be placed into the LEDs (max 6 bit) |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 125 | */ |
Niklaus Giger | c215781 | 2007-08-16 15:16:03 +0200 | [diff] [blame] | 126 | void hcu_led_set(u32 value) |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 127 | { |
| 128 | u32 tmp = ~value; |
Stefan Roese | 0a677fd | 2007-08-10 10:42:25 +0200 | [diff] [blame] | 129 | |
| 130 | tmp = (tmp << 23) | 0x7FFFFF; |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 131 | out_be32((u32 *)GPIO0_OR, tmp); |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /* |
| 135 | * sdram_init - Dummy implementation for start.S, spd_sdram or initdram |
| 136 | * used for HCUx |
| 137 | */ |
| 138 | void sdram_init(void) |
| 139 | { |
| 140 | return; |
| 141 | } |
| 142 | |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 143 | /* |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 144 | * hcu_get_slot |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 145 | */ |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 146 | u32 hcu_get_slot(void) |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 147 | { |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 148 | u16 *slot = (u16 *)SYS_SLOT_ADDRESS; |
| 149 | return in_be16(slot) & 0x7f; |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 150 | } |
| 151 | |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 152 | /* |
| 153 | * get_serial_number |
| 154 | */ |
| 155 | u32 get_serial_number(void) |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 156 | { |
| 157 | u32 *serial = (u32 *)CFG_FLASH_BASE; |
Stefan Roese | 0a677fd | 2007-08-10 10:42:25 +0200 | [diff] [blame] | 158 | |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 159 | if (in_be32(serial) == 0xffffffff) |
| 160 | return 0; |
Stefan Roese | 0a677fd | 2007-08-10 10:42:25 +0200 | [diff] [blame] | 161 | |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 162 | return in_be32(serial); |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 166 | /* |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 167 | * misc_init_r. |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 168 | */ |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 169 | |
| 170 | int misc_init_r(void) |
| 171 | { |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 172 | common_misc_init_r(); |
| 173 | set_params_for_sw_install( sys_install_requested(), "hcu4" ); |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 174 | return 0; |
| 175 | } |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 176 | |
| 177 | long int initdram(int board_type) |
| 178 | { |
| 179 | long dram_size = 0; |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 180 | u16 *boardVersReg = (u16 *) HCU_MACH_VERSIONS_REGISTER; |
| 181 | u16 generation = in_be16(boardVersReg) & 0xf0; |
| 182 | if (generation == HW_GENERATION_HCU3) |
| 183 | dram_size = 32*1024*1024; |
| 184 | else dram_size = 64*1024*1024; |
| 185 | fixed_hcu4_sdram(dram_size); |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 186 | |
| 187 | #ifdef DEBUG |
| 188 | show_sdram_registers(); |
| 189 | #endif |
| 190 | |
Niklaus Giger | 89b257f | 2007-07-27 11:30:33 +0200 | [diff] [blame] | 191 | return dram_size; |
| 192 | } |
Niklaus Giger | fbf5204 | 2008-01-16 18:39:20 +0100 | [diff] [blame] | 193 | |
| 194 | #if defined(CONFIG_POST) |
| 195 | /* |
| 196 | * Returns 1 if keys pressed to start the power-on long-running tests |
| 197 | * Called from board_init_f(). |
| 198 | */ |
| 199 | int post_hotkeys_pressed(void) |
| 200 | { |
| 201 | return 0; /* No hotkeys supported */ |
| 202 | } |
| 203 | #endif /* CONFIG_POST */ |
| 204 | |
| 205 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 206 | void ft_board_setup(void *blob, bd_t *bd) |
| 207 | { |
| 208 | ft_cpu_setup(blob, bd); |
| 209 | |
| 210 | } |
| 211 | #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */ |