1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  Board device initialization		File: bcm91280e_devs.c
5    *
6    *  This is the "C" part of the board support package.  The
7    *  routines to create and initialize the console, wire up
8    *  device drivers, and do other customization live here.
9    *
10    *  Author:  Mitch Lichtenberg
11    *
12    *********************************************************************
13    *
14    *  Copyright 2000,2001,2002,2003,2005
15    *  Broadcom Corporation. All rights reserved.
16    *
17    *  This software is furnished under license and may be used and
18    *  copied only in accordance with the following terms and
19    *  conditions.  Subject to these conditions, you may download,
20    *  copy, install, use, modify and distribute modified or unmodified
21    *  copies of this software in source and/or binary form.  No title
22    *  or ownership is transferred hereby.
23    *
24    *  1) Any source code used, modified or distributed must reproduce
25    *     and retain this copyright notice and list of conditions
26    *     as they appear in the source file.
27    *
28    *  2) No right is granted to use any trade name, trademark, or
29    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
30    *     name may not be used to endorse or promote products derived
31    *     from this software without the prior written permission of
32    *     Broadcom Corporation.
33    *
34    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
35    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
36    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
37    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
38    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
39    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
40    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
42    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
44    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
45    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
46    *     THE POSSIBILITY OF SUCH DAMAGE.
47    ********************************************************************* */
48
49
50#include "cfe.h"
51#include "sbmips.h"
52
53#include "env_subr.h"
54#include "cfe_smbus.h"
55#include "dev_newflash.h"
56
57#include "bcm1480_regs.h"
58#include "bcm1480_scd.h"
59#include "bcm1480_mc.h"
60#include "lib_physio.h"
61
62#include "bcm91280e.h"
63
64
65/*  *********************************************************************
66    *  Devices we're importing
67    ********************************************************************* */
68
69extern cfe_driver_t promice_uart;		/* promice serial port */
70extern cfe_driver_t sb1250_uart;		/* SB1250 serial ports */
71extern cfe_driver_t sb1250_ether;		/* SB1250 MACs */
72extern cfe_driver_t newflashdrv;		/* AMD-style flash */
73
74extern cfe_smbus_t sb1250_smbus;       		/* SiByte SMBus host */
75
76extern cfe_driver_t smbus_24lc128;		/* Microchip EEPROM */
77extern cfe_driver_t smbus_m41t81clock;		/* ST Micro clock */
78
79
80/*  *********************************************************************
81    *  Commands we're importing
82    ********************************************************************* */
83
84extern int ui_docommands(char *);
85
86extern void ui_init_bcm91280ecmds(void);
87extern void ui_init_cpu1cmds(void);
88extern int ui_init_corecmds(void);
89extern int ui_init_soccmds(void);
90extern int ui_init_testcmds(void);
91extern int ui_init_tempsensorcmds(void);
92extern int ui_init_toyclockcmds(void);
93extern int ui_init_memtestcmds(void);
94extern int ui_init_resetcmds(void);
95extern int ui_init_phycmds(void);
96extern int ui_init_ethertestcmds(void);
97extern int ui_init_flashtestcmds(void);
98extern int ui_init_uarttestcmds(void);
99extern int ui_init_pmcmds(void);
100extern int ui_init_swtrccmds(void);
101
102/*  *********************************************************************
103    *  Some other stuff we use
104    ********************************************************************* */
105
106extern void sb1250_show_cpu_type(void);
107
108/*  *********************************************************************
109    *  Some board-specific parameters
110    ********************************************************************* */
111
112/*
113 * Note!  Configure the PROMICE for burst mode zero (one byte per
114 * access).
115 */
116
117#define PROMICE_BASE	(0x1FDFFC00)
118#define PROMICE_WORDSIZE 1
119
120#define REAL_BOOTROM_SIZE	(2*1024*1024)	/* region is 4MB, but rom is 2MB */
121
122/*  *********************************************************************
123    *  SysConfig switch settings and related parameters
124    ********************************************************************* */
125
126static int board_config;
127static int board_rev;
128
129#define PROMICE_CONSOLE		0x00000001
130
131
132
133/*  *********************************************************************
134    *  board_console_init()
135    *
136    *  Add the console device and set it to be the primary
137    *  console.
138    *
139    *  Input parameters:
140    *  	   nothing
141    *
142    *  Return value:
143    *  	   nothing
144    ********************************************************************* */
145
146void board_console_init(void)
147{
148    uint64_t sysrev;
149    uint64_t syscfg;
150
151    sysrev = SBREADCSR(A_SCD_SYSTEM_REVISION);
152    syscfg = SBREADCSR(A_SCD_SYSTEM_CFG);
153
154    /* Console */
155    cfe_add_device(&sb1250_uart,A_BCM1480_DUART(0),0,0);
156    cfe_add_device(&promice_uart,PROMICE_BASE,PROMICE_WORDSIZE,0);
157
158    /*
159     * Read the config switch and decide how we are going to set up
160     * the console.
161     *
162     * Note that the human-readable board revision is the revision
163     * encoded by the revision bits + 1.
164     */
165    board_config = board_get_config();
166    board_rev = (board_config & BOARD_CFG_REV_MASK) + 1;
167
168    cfe_startflags = 0;
169
170    /* Set up CFE start flags based on config switch */
171
172    switch (board_config & BOARD_CFG_CONS_MASK) {
173    case BOARD_CFG_CONS_UART0:
174    default:
175	break;
176
177    case BOARD_CFG_CONS_PROMICE:
178	cfe_startflags |= PROMICE_CONSOLE;
179	break;
180    }
181
182    if ((board_config & BOARD_CFG_INIT_PCI) != 0) {
183	cfe_startflags |= CFE_INIT_PCI;
184	}
185
186    /* Configure console */
187
188    if (cfe_startflags & PROMICE_CONSOLE) {
189	cfe_set_console("promice0");
190	}
191    else {
192	cfe_set_console("uart0");
193	}
194
195    /*
196     * SMBus buses - need to be initialized before we attach
197     * devices that use them.
198     */
199
200    cfe_add_smbus(&sb1250_smbus,A_SMB_BASE(0),0);
201    cfe_add_smbus(&sb1250_smbus,A_SMB_BASE(1),0);
202
203    /*
204     * NVRAM (environment variables)
205     */
206
207    cfe_add_device(&smbus_24lc128,BIGEEPROM_SMBUS_CHAN_1,BIGEEPROM_SMBUS_DEV_1,0);
208    cfe_set_envdevice("eeprom0");	/* Connect NVRAM subsystem to EEPROM */
209}
210
211
212/*  *********************************************************************
213    *  board_device_init()
214    *
215    *  Initialize and add other devices.  Add everything you need
216    *  for bootstrap here, like disk drives, flash memory, UARTs,
217    *  network controllers, etc.
218    *
219    *  Input parameters:
220    *  	   nothing
221    *
222    *  Return value:
223    *  	   nothing
224    ********************************************************************* */
225
226void board_device_init(void)
227{
228    uint64_t syscfg;
229    uint64_t mcreg;
230
231    syscfg = SBREADCSR(A_SCD_SYSTEM_CFG);
232
233    /*
234     * Print out the board version number and config straps
235     */
236
237    printf("%s board revision %d\n",CFG_BOARDNAME,board_rev);
238    printf("%s configuration switches: 0x%x\n",CFG_BOARDNAME,board_config);
239
240    /* Enable token ring timeouts.  By default, references to
241       unimplemented south ring addresses will give no response and
242       thus hang the CPU. */
243    phys_write64(A_BCM1480_NC_SR_TIMEOUT_COUNTER_SEL, 0x1);
244
245    /*
246     * UART channel B on primary DUART
247     */
248
249    cfe_add_device(&sb1250_uart,A_BCM1480_DUART(0),1,0);
250
251    /*
252     * UARTs on second DUART, if enabled
253     */
254
255    if (syscfg & M_BCM1480_SYS_DUART1_ENABLE) {
256	cfe_add_device(&sb1250_uart,A_BCM1480_DUART(2),0,0);
257	cfe_add_device(&sb1250_uart,A_BCM1480_DUART(2),1,0);
258	}
259
260#ifndef _FUNCSIM_
261    /*
262     * Boot ROM, using "new" flash driver
263     */
264
265    cfe_add_device(&newflashdrv,
266		   BOOTROM_PHYS,
267		   REAL_BOOTROM_SIZE | FLASH_FLG_BUS8 | FLASH_FLG_DEV16,
268		   NULL);
269    cfe_add_device(&newflashdrv,
270		   ALT_BOOTROM_PHYS,
271		   REAL_BOOTROM_SIZE | FLASH_FLG_BUS8 | FLASH_FLG_DEV16,
272		   NULL);
273#endif /*_FUNCSIM_*/
274
275    /*
276     * This is the 24LC128 on SMBus0.  CFE doesn't use it for anything,
277     * but you can load data into it and then boot from it by changing a jumper.
278     */
279
280    cfe_add_device(&smbus_24lc128,BIGEEPROM_SMBUS_CHAN,BIGEEPROM_SMBUS_DEV,0);
281
282    /*
283     * MACs - must init after environment, since the hw address is stored there
284     */
285
286#if (!CFG_BOOTRAM && !CFG_L2_RAM)
287    cfe_add_device(&sb1250_ether,A_MAC_BASE_0,0,env_getenv("ETH0_HWADDR"));
288    cfe_add_device(&sb1250_ether,A_MAC_BASE_1,1,env_getenv("ETH1_HWADDR"));
289    cfe_add_device(&sb1250_ether,A_MAC_BASE_2,2,env_getenv("ETH2_HWADDR"));
290#endif
291    cfe_add_device(&sb1250_ether,A_MAC_BASE_3,3,env_getenv("ETH3_HWADDR"));
292
293    /*
294     * Real-time clock
295     */
296
297    cfe_add_device(&smbus_m41t81clock,M41T81_SMBUS_CHAN,M41T81_SMBUS_DEV,0);
298
299    /*
300     * Display config register and CPU type
301     */
302
303    sb1250_show_cpu_type();
304
305    mcreg = SBREADCSR(A_BCM1480_MC_REGISTER(0,R_BCM1480_MC_CLOCK_CFG));
306    if (G_BCM1480_MC_CLK_RATIO(mcreg)) {
307	printf("Memory controller #0: %dMHz\n",
308	       (cfe_cpu_speed / 2000000) * 4 / ((int)G_BCM1480_MC_CLK_RATIO(mcreg)));
309	}
310
311    mcreg = SBREADCSR(A_BCM1480_MC_REGISTER(1,R_BCM1480_MC_CLOCK_CFG));
312    if (G_BCM1480_MC_CLK_RATIO(mcreg)) {
313	printf("Memory controller #1: %dMHz\n",
314	       (cfe_cpu_speed / 2000000) * 4 / ((int)G_BCM1480_MC_CLK_RATIO(mcreg)));
315	}
316
317    printf("Switch Clock: %dMHz\n",
318	   (cfe_cpu_speed * 2 / 1000000) / ((int)G_BCM1480_SYS_SW_DIV(syscfg)));
319
320}
321
322
323
324/*  *********************************************************************
325    *  board_device_reset()
326    *
327    *  Reset devices.  This call is done when the firmware is restarted,
328    *  as might happen when an operating system exits, just before the
329    *  "reset" command is applied to the installed devices.   You can
330    *  do whatever board-specific things are here to keep the system
331    *  stable, like stopping DMA sources, interrupts, etc.
332    *
333    *  Input parameters:
334    *  	   nothing
335    *
336    *  Return value:
337    *  	   nothing
338    ********************************************************************* */
339
340void board_device_reset(void)
341{
342}
343
344
345/*  *********************************************************************
346    *  board_final_init()
347    *
348    *  Do any final initialization, such as adding commands to the
349    *  user interface.
350    *
351    *  If you don't want a user interface, put the startup code here.
352    *  This routine is called just before CFE starts its user interface.
353    *
354    *  Input parameters:
355    *  	   nothing
356    *
357    *  Return value:
358    *  	   nothing
359    ********************************************************************* */
360
361void board_final_init(void)
362{
363    int flag;
364
365    ui_init_bcm91280ecmds();
366    ui_init_cpu1cmds();
367#if 0
368    ui_init_corecmds();
369#endif
370    ui_init_soccmds();
371    ui_init_testcmds();
372    ui_init_tempsensorcmds();
373    ui_init_toyclockcmds();
374    ui_init_memtestcmds();
375    ui_init_resetcmds();
376    ui_init_phycmds();
377    ui_init_ethertestcmds();
378    ui_init_flashtestcmds();
379    ui_init_uarttestcmds();
380    ui_init_pmcmds();
381    ui_init_swtrccmds();
382
383
384    if ((board_config & BOARD_CFG_DO_STARTUP) != 0) {
385	/* Change STARTUP's flags so it can run or error message if not set */
386	if (env_getenv("STARTUP") == NULL) {
387	    printf("*** STARTUP environment variable not set.\n\n");
388	}
389	else {
390	    flag = env_envtype("STARTUP");
391	    flag &= ~ENV_FLG_STARTUP_NORUN;
392	    env_setflags("STARTUP",flag);
393	    }
394	}
395    else {
396	if (env_getenv("STARTUP") != NULL) {
397	    /* Don't run the commands in STARTUP */
398	    flag = env_envtype("STARTUP");
399	    flag |= ENV_FLG_STARTUP_NORUN;
400	    env_setflags("STARTUP",flag);
401	    }
402	}
403}
404
405
406