blob: 1bb9686a3b7b37539d97faa1f92d9e9629c9e4a3 [file] [log] [blame]
Stefan Roese5568e612005-11-22 13:20:42 +01001/*
2 * (C) Copyright 2005
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
5 * Copyright (C) 2002 Scott McNutt <smcnutt@artesyncp.com>
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26#include <common.h>
27#include <asm/processor.h>
28#include <command.h>
29
30#include "p3p440.h"
31
Wolfgang Denkd87080b2006-03-31 18:32:53 +020032DECLARE_GLOBAL_DATA_PTR;
33
Stefan Roese5568e612005-11-22 13:20:42 +010034void set_led(int color)
35{
36 switch (color) {
37 case LED_OFF:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020038 out32(GPIO0_OR, in32(GPIO0_OR) & ~CONFIG_SYS_LED_GREEN & ~CONFIG_SYS_LED_RED);
Stefan Roese5568e612005-11-22 13:20:42 +010039 break;
40
41 case LED_GREEN:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020042 out32(GPIO0_OR, (in32(GPIO0_OR) | CONFIG_SYS_LED_GREEN) & ~CONFIG_SYS_LED_RED);
Stefan Roese5568e612005-11-22 13:20:42 +010043 break;
44
45 case LED_RED:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020046 out32(GPIO0_OR, (in32(GPIO0_OR) | CONFIG_SYS_LED_RED) & ~CONFIG_SYS_LED_GREEN);
Stefan Roese5568e612005-11-22 13:20:42 +010047 break;
48
49 case LED_ORANGE:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020050 out32(GPIO0_OR, in32(GPIO0_OR) | CONFIG_SYS_LED_GREEN | CONFIG_SYS_LED_RED);
Stefan Roese5568e612005-11-22 13:20:42 +010051 break;
52 }
53}
54
55static int is_monarch(void)
56{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020057 out32(GPIO0_OR, in32(GPIO0_OR) & ~CONFIG_SYS_GPIO_RDY);
Stefan Roese5568e612005-11-22 13:20:42 +010058 udelay(1000);
59
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020060 if (in32(GPIO0_IR) & CONFIG_SYS_MONARCH_IO)
Stefan Roese5568e612005-11-22 13:20:42 +010061 return 0;
62 else
63 return 1;
64}
65
66static void wait_for_pci_ready(void)
67{
68 /*
69 * Configure EREADY_IO as input
70 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020071 out32(GPIO0_TCR, in32(GPIO0_TCR) & ~CONFIG_SYS_EREADY_IO);
Stefan Roese5568e612005-11-22 13:20:42 +010072 udelay(1000);
73
74 for (;;) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020075 if (in32(GPIO0_IR) & CONFIG_SYS_EREADY_IO)
Stefan Roese5568e612005-11-22 13:20:42 +010076 return;
Wolfgang Denkf013dac2005-12-04 00:40:34 +010077 }
Stefan Roese5568e612005-11-22 13:20:42 +010078
79}
80
81int board_early_init_f(void)
82{
83 uint reg;
84
85 /*--------------------------------------------------------------------
86 * Setup the external bus controller/chip selects
87 *-------------------------------------------------------------------*/
Stefan Roesed1c3b272009-09-09 16:25:29 +020088 mtdcr(EBC0_CFGADDR, EBC0_CFG);
89 reg = mfdcr(EBC0_CFGDATA);
90 mtdcr(EBC0_CFGDATA, reg | 0x04000000); /* Set ATC */
Stefan Roese5568e612005-11-22 13:20:42 +010091
92 /*--------------------------------------------------------------------
93 * Setup pin multiplexing (GPIO/IRQ...)
94 *-------------------------------------------------------------------*/
Stefan Roesed1c3b272009-09-09 16:25:29 +020095 mtdcr(CPC0_GPIO, 0x03F01F80);
Stefan Roese5568e612005-11-22 13:20:42 +010096
97 out32(GPIO0_ODR, 0x00000000); /* no open drain pins */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020098 out32(GPIO0_TCR, CONFIG_SYS_GPIO_RDY | CONFIG_SYS_EREADY_IO | CONFIG_SYS_LED_RED | CONFIG_SYS_LED_GREEN);
99 out32(GPIO0_OR, CONFIG_SYS_GPIO_RDY);
Stefan Roese5568e612005-11-22 13:20:42 +0100100
101 /*--------------------------------------------------------------------
102 * Setup the interrupt controller polarities, triggers, etc.
103 *-------------------------------------------------------------------*/
Stefan Roese952e7762009-09-24 09:55:50 +0200104 mtdcr(UIC0SR, 0xffffffff); /* clear all */
105 mtdcr(UIC0ER, 0x00000000); /* disable all */
106 mtdcr(UIC0CR, 0x00000001); /* UIC1 crit is critical */
107 mtdcr(UIC0PR, 0xfffffe13); /* per ref-board manual */
108 mtdcr(UIC0TR, 0x01c00008); /* per ref-board manual */
109 mtdcr(UIC0VR, 0x00000001); /* int31 highest, base=0x000 */
110 mtdcr(UIC0SR, 0xffffffff); /* clear all */
Stefan Roese5568e612005-11-22 13:20:42 +0100111
Stefan Roese952e7762009-09-24 09:55:50 +0200112 mtdcr(UIC1SR, 0xffffffff); /* clear all */
113 mtdcr(UIC1ER, 0x00000000); /* disable all */
114 mtdcr(UIC1CR, 0x00000000); /* all non-critical */
115 mtdcr(UIC1PR, 0xffffe0ff); /* per ref-board manual */
116 mtdcr(UIC1TR, 0x00ffc000); /* per ref-board manual */
117 mtdcr(UIC1VR, 0x00000001); /* int31 highest, base=0x000 */
118 mtdcr(UIC1SR, 0xffffffff); /* clear all */
Stefan Roese5568e612005-11-22 13:20:42 +0100119
120 return 0;
121}
122
123int checkboard(void)
124{
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000125 char buf[64];
126 int i = getenv_f("serial#", buf, sizeof(buf));
Stefan Roese5568e612005-11-22 13:20:42 +0100127
128 printf("Board: P3P440");
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000129 if (i > 0) {
Stefan Roese5568e612005-11-22 13:20:42 +0100130 puts(", serial# ");
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000131 puts(buf);
Stefan Roese5568e612005-11-22 13:20:42 +0100132 }
133
134 if (is_monarch()) {
135 puts(", Monarch");
136 } else {
137 puts(", None-Monarch");
138 }
139
140 putc('\n');
141
Stefan Roese5568e612005-11-22 13:20:42 +0100142 return (0);
143}
144
145int misc_init_r (void)
146{
Stefan Roese5568e612005-11-22 13:20:42 +0100147 /*
148 * Adjust flash start and offset to detected values
149 */
150 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
151 gd->bd->bi_flashoffset = 0;
152
153 /*
154 * Check if only one FLASH bank is available
155 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200156 if (gd->bd->bi_flashsize != CONFIG_SYS_MAX_FLASH_BANKS * (0 - CONFIG_SYS_FLASH0)) {
Stefan Roesed1c3b272009-09-09 16:25:29 +0200157 mtebc(PB1CR, 0); /* disable cs */
158 mtebc(PB1AP, 0);
159 mtebc(PB2CR, 0); /* disable cs */
160 mtebc(PB2AP, 0);
161 mtebc(PB3CR, 0); /* disable cs */
162 mtebc(PB3AP, 0);
Stefan Roese5568e612005-11-22 13:20:42 +0100163 }
164
165 return 0;
166}
167
168/*************************************************************************
Stefan Roese9a81c612009-10-29 16:54:52 +0100169 * Override weak is_pci_host()
Stefan Roese5568e612005-11-22 13:20:42 +0100170 *
171 * This routine is called to determine if a pci scan should be
172 * performed. With various hardware environments (especially cPCI and
173 * PPMC) it's insufficient to depend on the state of the arbiter enable
174 * bit in the strap register, or generic host/adapter assumptions.
175 *
176 * Rather than hard-code a bad assumption in the general 440 code, the
177 * 440 pci code requires the board to decide at runtime.
178 *
179 * Return 0 for adapter mode, non-zero for host (monarch) mode.
180 *
181 *
182 ************************************************************************/
183#if defined(CONFIG_PCI)
184int is_pci_host(struct pci_controller *hose)
185{
186 if (is_monarch()) {
187 wait_for_pci_ready();
188 return 1; /* return 1 for host controller */
189 } else {
190 return 0; /* return 0 for adapter controller */
191 }
192}
193#endif /* defined(CONFIG_PCI) */