]> git.ipfire.org Git - people/ms/u-boot.git/blob - board/netstal/hcu4/hcu4.c
bb610e2d53de34b7cf6f3812d802467c9c7da9b3
[people/ms/u-boot.git] / board / netstal / hcu4 / hcu4.c
1 /*
2 *(C) Copyright 2005-2008 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>
26 #include "../common/nm.h"
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 #define HCU_MACH_VERSIONS_REGISTER (0x7C000000 + 0xF00000)
31 #define HCU_SLOT_ADDRESS (0x7C000000 + 0x400000)
32 #define HCU_DIGITAL_IO_REGISTER (0x7C000000 + 0x500000)
33 #define HCU_SW_INSTALL_REQUESTED 0x10
34
35 /*
36 * This function is run very early, out of flash, and before devices are
37 * initialized. It is called by lib_ppc/board.c:board_init_f by virtue
38 * of being in the init_sequence array.
39 *
40 * The SDRAM has been initialized already -- start.S:start called
41 * init.S:init_sdram early on -- but it is not yet being used for
42 * anything, not even stack. So be careful.
43 */
44
45 /* Attention: If you want 1 microsecs times from the external oscillator
46 * 0x00004051 is okay for u-boot/linux, but different from old vxworks values
47 * 0x00804051 causes problems with u-boot and linux!
48 */
49 #define CPC0_CR0_VALUE 0x0030103c
50 #define CPC0_CR1_VALUE 0x00004051
51
52 int board_early_init_f (void)
53 {
54 /*
55 * Interrupt controller setup for the HCU4 board.
56 * Note: IRQ 0-15 405GP internally generated; high; level sensitive
57 * IRQ 16 405GP internally generated; low; level sensitive
58 * IRQ 17-24 RESERVED/UNUSED
59 * IRQ 31 (EXT IRQ 6) (unused)
60 */
61 mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
62 mtdcr(uicer, 0x00000000); /* disable all ints */
63 mtdcr(uiccr, 0x00000000); /* set all to be non-critical */
64 mtdcr(uicpr, 0xFFFFE000); /* set int polarities */
65 mtdcr(uictr, 0x00000000); /* set int trigger levels */
66 mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
67
68 mtdcr(CPC0_CR1, CPC0_CR1_VALUE);
69 mtdcr(CPC0_ECR, 0x60606000);
70 mtdcr(CPC0_EIRR, 0x7C000000);
71
72 return 0;
73 }
74
75 #ifdef CONFIG_BOARD_PRE_INIT
76 int board_pre_init (void)
77 {
78 return board_early_init_f ();
79 }
80 #endif
81
82 int sys_install_requested(void)
83 {
84 u16 ioValue = in_be16((u16 *)HCU_DIGITAL_IO_REGISTER);
85 return (ioValue & HCU_SW_INSTALL_REQUESTED) != 0;
86 }
87
88 int checkboard (void)
89 {
90 u16 boardVersReg = in_be16((u16 *)HCU_MACH_VERSIONS_REGISTER);
91 u16 generation = boardVersReg & 0xf0;
92 u16 index = boardVersReg & 0x0f;
93
94 /* Cannot be done in board_early_init */
95 mtdcr(cntrl0, CPC0_CR0_VALUE);
96
97 /* Force /RTS to active. The board it not wired quite
98 * correctly to use cts/rtc flow control, so just force the
99 * /RST active and forget about it.
100 */
101 writeb (readb (0xef600404) | 0x03, 0xef600404);
102 nm_show_print(generation, index, 0);
103
104 return 0;
105 }
106
107 u32 hcu_led_get(void)
108 {
109 return (~(in_be32((u32 *)GPIO0_OR)) >> 23) & 0xff;
110 }
111
112 /*
113 * hcu_led_set value to be placed into the LEDs (max 6 bit)
114 */
115 void hcu_led_set(u32 value)
116 {
117 u32 tmp = ~value;
118
119 tmp = (tmp << 23) | 0x7FFFFF;
120 out_be32((u32 *)GPIO0_OR, tmp);
121 }
122
123 /*
124 * sdram_init - Dummy implementation for start.S, spd_sdram or initdram
125 * used for HCUx
126 */
127 void sdram_init(void)
128 {
129 return;
130 }
131
132 /*
133 * hcu_get_slot
134 */
135 u32 hcu_get_slot(void)
136 {
137 u16 slot = in_be16((u16 *)HCU_SLOT_ADDRESS);
138 return slot & 0x7f;
139 }
140
141 /*
142 * get_serial_number
143 */
144 u32 get_serial_number(void)
145 {
146 u32 serial = in_be32((u32 *)CFG_FLASH_BASE);
147
148 if (serial == 0xffffffff)
149 return 0;
150
151 return serial;
152 }
153
154
155 /*
156 * misc_init_r.
157 */
158
159 int misc_init_r(void)
160 {
161 common_misc_init_r();
162 set_params_for_sw_install( sys_install_requested(), "hcu4" );
163 return 0;
164 }
165
166 long int initdram(int board_type)
167 {
168 long dram_size = 0;
169 u16 boardVersReg = in_be16((u16 *)HCU_MACH_VERSIONS_REGISTER);
170 u16 generation = boardVersReg & 0xf0;
171 u16 index = boardVersReg & 0x0f;
172
173 if (generation == HW_GENERATION_HCU3 && index < 0xf)
174 dram_size = 32 << 20; /* 32 MB - RAM */
175 else
176 dram_size = 64 << 20; /* 64 MB - RAM */
177 init_ppc405_sdram(dram_size);
178
179 #ifdef DEBUG
180 show_sdram_registers();
181 #endif
182
183 return dram_size;
184 }
185
186 #if defined(CONFIG_POST)
187 /*
188 * Returns 1 if keys pressed to start the power-on long-running tests
189 * Called from board_init_f().
190 */
191 int post_hotkeys_pressed(void)
192 {
193 return 0; /* No hotkeys supported */
194 }
195 #endif /* CONFIG_POST */
196
197 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
198 void ft_board_setup(void *blob, bd_t *bd)
199 {
200 ft_cpu_setup(blob, bd);
201
202 }
203 #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */