1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  Board device initialization		File: bcm91480b_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
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 "cfe_smbus.h"
52#include "env_subr.h"
53
54#include "bcm1480_regs.h"
55#include "bcm1480_scd.h"
56#include "bcm1480_mc.h"
57#include "sb1250_genbus.h"
58#include "lib_physio.h"
59
60#include "bcm91480b.h"
61
62#include "dev_newflash.h"
63
64/*  *********************************************************************
65    *  Devices we're importing
66    ********************************************************************* */
67
68extern cfe_driver_t promice_uart;		/* promice serial port */
69extern cfe_driver_t sb1250_uart;		/* SB1250 serial ports */
70extern cfe_driver_t sb1250_ether;		/* SB1250 MACs */
71extern cfe_driver_t newflashdrv;		/* AMD-style flash */
72#if CFG_PCI
73extern void pci_add_devices(int init);
74#endif
75#if CFG_TCP
76extern cfe_driver_t tcpconsole;			/* TCP/IP console */
77#endif
78
79extern cfe_smbus_t sb1250_smbus;       		/* SiByte SMBus host */
80
81extern cfe_driver_t smbus_24lc128;		/* Microchip EEPROM */
82extern cfe_driver_t smbus_m41t81clock;		/* ST Micro clock */
83
84extern cfe_driver_t pcmciadrv;			/* PCMCIA card */
85
86
87/*  *********************************************************************
88    *  Commands we're importing
89    ********************************************************************* */
90
91extern int ui_docommands(char *);
92
93extern void ui_init_cpu1cmds(void);
94extern void ui_init_bcm91480bcmds(void);
95extern int ui_init_soccmds(void);
96extern int ui_init_testcmds(void);
97extern int ui_init_toyclockcmds(void);
98extern int ui_init_tempsensorcmds(void);
99extern int ui_init_memtestcmds(void);
100extern int ui_init_resetcmds(void);
101extern int ui_init_phycmds(void);
102extern int ui_init_spdcmds(void);
103extern int ui_init_disktestcmds(void);
104extern int ui_init_ethertestcmds(void);
105extern int ui_init_flashtestcmds(void);
106#if CFG_LDT
107extern int ui_init_hspcmds(void);
108extern int ui_init_pmcmds(void);
109extern int ui_init_swtrccmds(void);
110extern int ui_init_ccncmds(void);
111#endif
112
113/*  *********************************************************************
114    *  Some other stuff we use
115    ********************************************************************* */
116
117extern void sb1250_show_cpu_type(void);
118
119/*  *********************************************************************
120    *  Some board-specific parameters
121    ********************************************************************* */
122
123/*
124 * Note!  Configure the PROMICE for burst mode zero (one byte per
125 * access).
126 */
127
128#define PROMICE_BASE	(0x1FDFFC00)
129#define PROMICE_WORDSIZE 1
130
131#define REAL_BOOTROM_SIZE	(2*1024*1024)	/* region is 4MB, but rom is 2MB */
132
133/*  *********************************************************************
134    *  SysConfig switch settings and related parameters
135    ********************************************************************* */
136
137static int board_config;
138static int board_rev;
139
140#define PROMICE_CONSOLE		0x00000001
141
142
143
144/*  *********************************************************************
145    *  board_console_init()
146    *
147    *  Add the console device and set it to be the primary
148    *  console.
149    *
150    *  Input parameters:
151    *  	   nothing
152    *
153    *  Return value:
154    *  	   nothing
155    ********************************************************************* */
156
157void board_console_init(void)
158{
159    uint64_t sysrev;
160    uint64_t syscfg;
161
162    sysrev = SBREADCSR(A_SCD_SYSTEM_REVISION);
163    syscfg = SBREADCSR(A_SCD_SYSTEM_CFG);
164
165    /* Console */
166    cfe_add_device(&sb1250_uart,A_BCM1480_DUART(0),0,0);
167    cfe_add_device(&promice_uart,PROMICE_BASE,PROMICE_WORDSIZE,0);
168
169    /*
170     * Read the config switch and decide how we are going to set up
171     * the console.
172     *
173     * Note that the human-readable board revision is the revision
174     * encoded by the revision bits + 1.
175     */
176    board_config = board_get_config();
177    board_rev = (board_config & BOARD_CFG_REV_MASK) + 1;
178
179    cfe_startflags = 0;
180
181    /* Set up CFE start flags based on config switch */
182
183    switch (board_config & BOARD_CFG_CONS_MASK) {
184    case BOARD_CFG_CONS_UART0:
185    default:
186	break;
187
188    case BOARD_CFG_CONS_PROMICE:
189	cfe_startflags |= PROMICE_CONSOLE;
190	break;
191    }
192
193    /* XXX This is a kludge.
194
195       There are not enough config switch bits to deal with HT modes
196       and node configuration options.  However, if the node ID is set
197       to non-zero, HT DMA becomes non-coherent and existing CFE
198       drivers will not work for debices behind the PLX bridge.
199
200       For now, if CFG_INIT_PCI is set, leave the node ID as zero
201       and auto-configure PCI.  Otherwise, assign the node ID
202       according to CFG_NODE_ID and rely on an explicit node_enable
203       call to initialize PCI/HT.
204
205       Unfortunately, late initialization does not install the
206       drivers for a device attached to the otherwise usable
207       PCI-X interface.
208    */
209
210    if ((board_config & BOARD_CFG_INIT_PCI) != 0) {
211	cfe_startflags |= CFE_INIT_PCI;
212	}
213    else {
214	unsigned int node_id = (board_config & BOARD_CFG_NODE_ID ? 5 : 4);
215
216	syscfg &= ~M_BCM1480_SYS_NODEID;
217	syscfg |= V_BCM1480_SYS_NODEID(node_id);
218
219	/* XXX workaround: write value to SCD before updating sys_cfg */
220	SBWRITECSR(A_BCM1480_SCD_SCRATCH, syscfg);
221
222	SBWRITECSR(A_SCD_SYSTEM_CFG, syscfg);
223	}
224
225    /* Configure console */
226
227    if (cfe_startflags & PROMICE_CONSOLE) {
228	cfe_set_console("promice0");
229	}
230    else {
231	cfe_set_console("uart0");
232	}
233
234    /*
235     * SMBus buses - need to be initialized before we attach
236     * devices that use them.
237     */
238
239    cfe_add_smbus(&sb1250_smbus,A_SMB_BASE(0),0);
240    cfe_add_smbus(&sb1250_smbus,A_SMB_BASE(1),0);
241
242    /*
243     * NVRAM (environment variables)
244     */
245
246    cfe_add_device(&smbus_24lc128,BIGEEPROM_SMBUS_CHAN_1,BIGEEPROM_SMBUS_DEV_1,0);
247    cfe_set_envdevice("eeprom0");	/* Connect NVRAM subsystem to EEPROM */
248}
249
250
251/*  *********************************************************************
252    *  board_device_init()
253    *
254    *  Initialize and add other devices.  Add everything you need
255    *  for bootstrap here, like disk drives, flash memory, UARTs,
256    *  network controllers, etc.
257    *
258    *  Input parameters:
259    *  	   nothing
260    *
261    *  Return value:
262    *  	   nothing
263    ********************************************************************* */
264
265void board_device_init(void)
266{
267    uint64_t syscfg;
268    uint64_t mcreg;
269
270    syscfg = SBREADCSR(A_SCD_SYSTEM_CFG);
271
272    /*
273     * Print out the board version number and config straps
274     */
275
276    printf("%s board revision %d\n",CFG_BOARDNAME,board_rev);
277    printf("%s configuration switches: 0x%x\n",CFG_BOARDNAME,board_config);
278
279    /* Enable token ring timeouts.  By default, references to
280       unimplemented south ring addresses will give no response and
281       thus hang the CPU. */
282    phys_write64(A_BCM1480_NC_SR_TIMEOUT_COUNTER_SEL, 0x1);
283
284    /* Similarly for node controller timeouts. */
285    phys_write64(A_BCM1480_NC_TIMEOUT_COUNTER_SEL, 0x1);
286
287    /*
288     * UART channel B on primary DUART
289     */
290
291    cfe_add_device(&sb1250_uart,A_BCM1480_DUART(0),1,0);
292
293    /*
294     * UARTs on second DUART, if enabled
295     */
296
297    if (syscfg & M_BCM1480_SYS_DUART1_ENABLE) {
298	cfe_add_device(&sb1250_uart,A_BCM1480_DUART(2),0,0);
299	cfe_add_device(&sb1250_uart,A_BCM1480_DUART(2),1,0);
300	}
301
302#ifndef _FUNCSIM_
303    /*
304     * Boot ROM, using "new" flash driver
305     */
306
307    cfe_add_device(&newflashdrv,
308		   BOOTROM_PHYS,
309		   REAL_BOOTROM_SIZE | FLASH_FLG_BUS8 | FLASH_FLG_DEV16,
310		   NULL);
311    cfe_add_device(&newflashdrv,
312		   ALT_BOOTROM_PHYS,
313		   REAL_BOOTROM_SIZE | FLASH_FLG_BUS8 | FLASH_FLG_DEV16,
314		   NULL);
315#endif /*_FUNCSIM_*/
316
317    /*
318     * This is the 24LC128 on SMBus0.  CFE doesn't use it for anything,
319     * but you can load data into it and then boot from it by changing a jumper.
320     */
321
322    cfe_add_device(&smbus_24lc128,BIGEEPROM_SMBUS_CHAN,BIGEEPROM_SMBUS_DEV,0);
323
324    /*
325     * MACs - must init after environment, since the hw address is stored there
326     */
327
328#if (!CFG_BOOTRAM && !CFG_L2_RAM)
329    cfe_add_device(&sb1250_ether,A_MAC_BASE_0,0,env_getenv("ETH0_HWADDR"));
330    cfe_add_device(&sb1250_ether,A_MAC_BASE_1,1,env_getenv("ETH1_HWADDR"));
331    cfe_add_device(&sb1250_ether,A_MAC_BASE_2,2,env_getenv("ETH2_HWADDR"));
332#endif
333    cfe_add_device(&sb1250_ether,A_MAC_BASE_3,3,env_getenv("ETH3_HWADDR"));
334
335    /*
336     * PCMCIA support, if enabled
337     */
338
339    if (syscfg & M_BCM1480_SYS_PCMCIA_ENABLE) {
340	cfe_add_device(&pcmciadrv,PCMCIA0_PHYS,0,NULL);
341	if (BCM91480_PCMCIA_MODE == K_PCMCIA_MODE_PCMA_PCMB) {
342	    cfe_add_device(&pcmciadrv,PCMCIA1_PHYS,1,NULL);
343	    }
344	}
345
346#if CFG_PCI
347    pci_add_devices(cfe_startflags & CFE_INIT_PCI);
348#endif
349
350    /*
351     * Real-time clock
352     */
353
354    cfe_add_device(&smbus_m41t81clock,M41T81_SMBUS_CHAN,M41T81_SMBUS_DEV,0);
355
356    /*
357     * Display config register and CPU type
358     */
359
360    sb1250_show_cpu_type();
361
362    mcreg = SBREADCSR(A_BCM1480_MC_REGISTER(0,R_BCM1480_MC_CLOCK_CFG));
363    if (G_BCM1480_MC_CLK_RATIO(mcreg)) {
364	printf("Memory controller #0: %dMHz\n",
365	       (cfe_cpu_speed / 2000000) * 4 / ((int)G_BCM1480_MC_CLK_RATIO(mcreg)));
366	}
367
368    mcreg = SBREADCSR(A_BCM1480_MC_REGISTER(1,R_BCM1480_MC_CLOCK_CFG));
369    if (G_BCM1480_MC_CLK_RATIO(mcreg)) {
370	printf("Memory controller #1: %dMHz\n",
371	       (cfe_cpu_speed / 2000000) * 4 / ((int)G_BCM1480_MC_CLK_RATIO(mcreg)));
372	}
373
374    printf("Switch Clock: %dMHz\n",
375	   (cfe_cpu_speed * 2 / 1000000) / ((int)G_BCM1480_SYS_SW_DIV(syscfg)));
376
377    if (G_BCM1480_SYS_NODEID(syscfg) != 0) {
378	printf("Node Id: %d\n", G_BCM1480_SYS_NODEID(syscfg));
379	}
380
381    /*
382     * Some misc devices go here, mostly for playing.
383     */
384
385#if CFG_TCP
386    cfe_add_device(&tcpconsole,0,0,0);
387#endif
388}
389
390
391
392/*  *********************************************************************
393    *  board_device_reset()
394    *
395    *  Reset devices.  This call is done when the firmware is restarted,
396    *  as might happen when an operating system exits, just before the
397    *  "reset" command is applied to the installed devices.   You can
398    *  do whatever board-specific things are here to keep the system
399    *  stable, like stopping DMA sources, interrupts, etc.
400    *
401    *  Input parameters:
402    *  	   nothing
403    *
404    *  Return value:
405    *  	   nothing
406    ********************************************************************* */
407
408void board_device_reset(void)
409{
410}
411
412
413/*  *********************************************************************
414    *  board_final_init()
415    *
416    *  Do any final initialization, such as adding commands to the
417    *  user interface.
418    *
419    *  If you don't want a user interface, put the startup code here.
420    *  This routine is called just before CFE starts its user interface.
421    *
422    *  Input parameters:
423    *  	   nothing
424    *
425    *  Return value:
426    *  	   nothing
427    ********************************************************************* */
428
429void board_final_init(void)
430{
431    int flag;
432
433    ui_init_cpu1cmds();
434    ui_init_bcm91480bcmds();
435    ui_init_soccmds();
436    ui_init_testcmds();
437    ui_init_toyclockcmds();
438    ui_init_tempsensorcmds();
439    ui_init_memtestcmds();
440    ui_init_resetcmds();
441    ui_init_phycmds();
442    ui_init_spdcmds();
443    ui_init_disktestcmds();
444    ui_init_ethertestcmds();
445    ui_init_flashtestcmds();
446#if CFG_LDT
447    ui_init_hspcmds();
448    ui_init_pmcmds();
449    ui_init_swtrccmds();
450    ui_init_ccncmds();
451#endif
452
453    if ((board_config & BOARD_CFG_DO_STARTUP) != 0) {
454	/* Change STARTUP's flags so it can run or error message if not set */
455	if (env_getenv("STARTUP") == NULL) {
456	    printf("*** STARTUP environment variable not set.\n\n");
457	}
458	else {
459	    flag = env_envtype("STARTUP");
460	    flag &= ~ENV_FLG_STARTUP_NORUN;
461	    env_setflags("STARTUP",flag);
462	    }
463	}
464    else {
465	if (env_getenv("STARTUP") != NULL) {
466	    /* Don't run the commands in STARTUP */
467	    flag = env_envtype("STARTUP");
468	    flag |= ENV_FLG_STARTUP_NORUN;
469	    env_setflags("STARTUP",flag);
470	    }
471	}
472
473}
474
475
476