blob: 714b98e365fef60c1999923543b2729182e275d5 [file] [log] [blame]
Niklaus Giger6e5de262007-07-27 11:30:33 +02001/*
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 Giger055606b2008-01-16 18:39:20 +010026#include "../common/nm.h"
Niklaus Giger6e5de262007-07-27 11:30:33 +020027
28DECLARE_GLOBAL_DATA_PTR;
29
Stefan Roese35d22f92007-08-10 10:42:25 +020030#define HCU_MACH_VERSIONS_REGISTER (0x7C000000 + 0xF00000)
Niklaus Giger055606b2008-01-16 18:39:20 +010031#define SYS_SLOT_ADDRESS (0x7C000000 + 0x400000)
32#define HCU3_DIGITAL_IO_REGISTER (0x7C000000 + 0x500000)
33#define HCU_SW_INSTALL_REQUESTED 0x10
Stefan Roese35d22f92007-08-10 10:42:25 +020034
Niklaus Giger055606b2008-01-16 18:39:20 +010035#undef DEBUG
Niklaus Giger6e5de262007-07-27 11:30:33 +020036
37#if defined(DEBUG)
38void show_sdram_registers(void);
39#endif
40
41/*
42 * This function is run very early, out of flash, and before devices are
43 * initialized. It is called by lib_ppc/board.c:board_init_f by virtue
44 * of being in the init_sequence array.
45 *
46 * The SDRAM has been initialized already -- start.S:start called
47 * init.S:init_sdram early on -- but it is not yet being used for
48 * anything, not even stack. So be careful.
49 */
50
51#define CPC0_CR0 0xb1 /* Chip control register 0 */
52#define CPC0_CR1 0xb2 /* Chip control register 1 */
53/* Attention: If you want 1 microsecs times from the external oscillator
54 * use 0x00804051. But this causes problems with u-boot and linux!
55 */
Niklaus Giger055606b2008-01-16 18:39:20 +010056#define CPC0_CR0_VALUE 0x0030103c
Niklaus Giger6e5de262007-07-27 11:30:33 +020057#define CPC0_CR1_VALUE 0x00004051
58#define CPC0_ECR 0xaa /* Edge condition register */
59#define EBC0_CFG 0x23 /* External Peripheral Control Register */
60#define CPC0_EIRR 0xb6 /* External Interrupt Register */
61
62
63int board_early_init_f (void)
64{
Niklaus Giger055606b2008-01-16 18:39:20 +010065 /*
66 * Interrupt controller setup for the HCU4 board.
67 * Note: IRQ 0-15 405GP internally generated; high; level sensitive
68 * IRQ 16 405GP internally generated; low; level sensitive
69 * IRQ 17-24 RESERVED/UNUSED
70 * IRQ 31 (EXT IRQ 6) (unused)
71 */
Niklaus Giger6e5de262007-07-27 11:30:33 +020072 mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
73 mtdcr (uicer, 0x00000000); /* disable all ints */
74 mtdcr (uiccr, 0x00000000); /* set all to be non-critical */
Niklaus Giger055606b2008-01-16 18:39:20 +010075 mtdcr (uicpr, 0xFFFFE000); /* set int polarities */
76 mtdcr (uictr, 0x00000000); /* set int trigger levels */
Niklaus Giger6e5de262007-07-27 11:30:33 +020077 mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
78
79 mtdcr(CPC0_CR1, CPC0_CR1_VALUE);
80 mtdcr(CPC0_ECR, 0x60606000);
81 mtdcr(CPC0_EIRR, 0x7c000000);
82
83 return 0;
84}
85
86#ifdef CONFIG_BOARD_PRE_INIT
87int board_pre_init (void)
88{
89 return board_early_init_f ();
90}
Niklaus Giger6e5de262007-07-27 11:30:33 +020091#endif
92
Niklaus Giger055606b2008-01-16 18:39:20 +010093int sys_install_requested(void)
94{
95 u16 *ioValuePtr = (u16 *)HCU3_DIGITAL_IO_REGISTER;
96 return (in_be16(ioValuePtr) & HCU_SW_INSTALL_REQUESTED) != 0;
97}
98
Niklaus Giger6e5de262007-07-27 11:30:33 +020099int checkboard (void)
100{
Niklaus Giger055606b2008-01-16 18:39:20 +0100101 u16 *boardVersReg = (u16 *)HCU_MACH_VERSIONS_REGISTER;
102 u16 generation = in_be16(boardVersReg) & 0xf0;
103 u16 index = in_be16(boardVersReg) & 0x0f;
Stefan Roese35d22f92007-08-10 10:42:25 +0200104
Niklaus Giger055606b2008-01-16 18:39:20 +0100105 /* Cannot be done, in board_early_init */
106 mtdcr(CPC0_CR0, CPC0_CR0_VALUE);
Niklaus Giger6e5de262007-07-27 11:30:33 +0200107 /* Force /RTS to active. The board it not wired quite
Niklaus Giger055606b2008-01-16 18:39:20 +0100108 * correctly to use cts/rtc flow control, so just force the
109 * /RST active and forget about it.
110 */
Niklaus Giger6e5de262007-07-27 11:30:33 +0200111 writeb (readb (0xef600404) | 0x03, 0xef600404);
Niklaus Giger055606b2008-01-16 18:39:20 +0100112 nm_show_print(generation, index, 0);
Stefan Roese35d22f92007-08-10 10:42:25 +0200113
Niklaus Giger6e5de262007-07-27 11:30:33 +0200114 return 0;
115}
116
Niklaus Giger07bc2052007-08-16 15:16:03 +0200117u32 hcu_led_get(void)
Niklaus Giger6e5de262007-07-27 11:30:33 +0200118{
Niklaus Giger055606b2008-01-16 18:39:20 +0100119 return (~(in_be32((u32 *)GPIO0_OR)) >> 23) & 0xff;
Niklaus Giger6e5de262007-07-27 11:30:33 +0200120}
121
Niklaus Giger055606b2008-01-16 18:39:20 +0100122/*
Niklaus Giger07bc2052007-08-16 15:16:03 +0200123 * hcu_led_set value to be placed into the LEDs (max 6 bit)
Niklaus Giger055606b2008-01-16 18:39:20 +0100124 */
Niklaus Giger07bc2052007-08-16 15:16:03 +0200125void hcu_led_set(u32 value)
Niklaus Giger6e5de262007-07-27 11:30:33 +0200126{
127 u32 tmp = ~value;
Stefan Roese35d22f92007-08-10 10:42:25 +0200128
129 tmp = (tmp << 23) | 0x7FFFFF;
Niklaus Giger055606b2008-01-16 18:39:20 +0100130 out_be32((u32 *)GPIO0_OR, tmp);
Niklaus Giger6e5de262007-07-27 11:30:33 +0200131}
132
133/*
134 * sdram_init - Dummy implementation for start.S, spd_sdram or initdram
135 * used for HCUx
136 */
137void sdram_init(void)
138{
139 return;
140}
141
Niklaus Giger055606b2008-01-16 18:39:20 +0100142/*
143 * hcu_get_slot
144 */
145u32 hcu_get_slot(void)
Niklaus Giger6e5de262007-07-27 11:30:33 +0200146{
Niklaus Giger055606b2008-01-16 18:39:20 +0100147 u16 *slot = (u16 *)SYS_SLOT_ADDRESS;
148 return in_be16(slot) & 0x7f;
Niklaus Giger6e5de262007-07-27 11:30:33 +0200149}
Niklaus Giger6e5de262007-07-27 11:30:33 +0200150
Niklaus Giger6e5de262007-07-27 11:30:33 +0200151/*
Niklaus Giger055606b2008-01-16 18:39:20 +0100152 * get_serial_number
Niklaus Giger6e5de262007-07-27 11:30:33 +0200153 */
Niklaus Giger055606b2008-01-16 18:39:20 +0100154u32 get_serial_number(void)
Niklaus Giger6e5de262007-07-27 11:30:33 +0200155{
156 u32 *serial = (u32 *)CFG_FLASH_BASE;
Stefan Roese35d22f92007-08-10 10:42:25 +0200157
Niklaus Giger055606b2008-01-16 18:39:20 +0100158 if (in_be32(serial) == 0xffffffff)
159 return 0;
Stefan Roese35d22f92007-08-10 10:42:25 +0200160
Niklaus Giger055606b2008-01-16 18:39:20 +0100161 return in_be32(serial);
Niklaus Giger6e5de262007-07-27 11:30:33 +0200162}
163
164
Niklaus Giger055606b2008-01-16 18:39:20 +0100165/*
Niklaus Giger6e5de262007-07-27 11:30:33 +0200166 * misc_init_r.
Niklaus Giger055606b2008-01-16 18:39:20 +0100167 */
Niklaus Giger6e5de262007-07-27 11:30:33 +0200168
169int misc_init_r(void)
170{
Niklaus Giger055606b2008-01-16 18:39:20 +0100171 common_misc_init_r();
172 set_params_for_sw_install( sys_install_requested(), "hcu4" );
Niklaus Giger6e5de262007-07-27 11:30:33 +0200173 return 0;
174}
175
Niklaus Giger6e5de262007-07-27 11:30:33 +0200176long int initdram(int board_type)
177{
178 long dram_size = 0;
Niklaus Giger055606b2008-01-16 18:39:20 +0100179 u16 *boardVersReg = (u16 *) HCU_MACH_VERSIONS_REGISTER;
180 u16 generation = in_be16(boardVersReg) & 0xf0;
181 if (generation == HW_GENERATION_HCU3)
182 dram_size = 32*1024*1024;
183 else dram_size = 64*1024*1024;
184 fixed_hcu4_sdram(dram_size);
Niklaus Giger6e5de262007-07-27 11:30:33 +0200185
186#ifdef DEBUG
187 show_sdram_registers();
188#endif
189
Niklaus Giger6e5de262007-07-27 11:30:33 +0200190 return dram_size;
191}
Niklaus Giger055606b2008-01-16 18:39:20 +0100192
193#if defined(CONFIG_POST)
194/*
195 * Returns 1 if keys pressed to start the power-on long-running tests
196 * Called from board_init_f().
197 */
198int post_hotkeys_pressed(void)
199{
200 return 0; /* No hotkeys supported */
201}
202#endif /* CONFIG_POST */
203
204#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
205void ft_board_setup(void *blob, bd_t *bd)
206{
207 ft_cpu_setup(blob, bd);
208
209}
210#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */