]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/sandburst/common/sb_common.c
MIPS: mips32/cache.S: use v1 register for indirect function calls
[karo-tx-uboot.git] / board / sandburst / common / sb_common.c
1 /*
2  *  Copyright (C) 2005 Sandburst Corporation
3  *
4  * SPDX-License-Identifier:     GPL-2.0+ 
5  */
6 #include <config.h>
7 #include <common.h>
8 #include <command.h>
9 #include <asm/processor.h>
10 #include <asm/io.h>
11 #include <spd_sdram.h>
12 #include <i2c.h>
13 #include "ppc440gx_i2c.h"
14 #include "sb_common.h"
15
16 DECLARE_GLOBAL_DATA_PTR;
17
18 long int fixed_sdram (void);
19
20 /*************************************************************************
21  *  metrobox_get_master
22  *
23  *  PRI_N - active low signal.  If the GPIO pin is low we are the master
24  *
25  ************************************************************************/
26 int sbcommon_get_master(void)
27 {
28         ppc440_gpio_regs_t *gpio_regs;
29
30         gpio_regs = (ppc440_gpio_regs_t *)CONFIG_SYS_GPIO_BASE;
31
32         if (gpio_regs->in & SBCOMMON_GPIO_PRI_N) {
33                 return 0;
34         }
35         else {
36                 return 1;
37         }
38 }
39
40 /*************************************************************************
41  *  metrobox_secondary_present
42  *
43  *  Figure out if secondary/slave board is present
44  *
45  ************************************************************************/
46 int sbcommon_secondary_present(void)
47 {
48         ppc440_gpio_regs_t *gpio_regs;
49
50         gpio_regs = (ppc440_gpio_regs_t *)CONFIG_SYS_GPIO_BASE;
51
52         if (gpio_regs->in & SBCOMMON_GPIO_SEC_PRES)
53                 return 0;
54         else
55                 return 1;
56 }
57
58 /*************************************************************************
59  *  sbcommon_get_serial_number
60  *
61  *  Retrieve the board serial number via the mac address in eeprom
62  *
63  ************************************************************************/
64 unsigned short sbcommon_get_serial_number(void)
65 {
66         unsigned char buff[0x100];
67         unsigned short sernum;
68
69         /* Get the board serial number from eeprom */
70         /* Initialize I2C */
71         i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
72
73         /* Read 256 bytes in EEPROM */
74         i2c_read (0x50, 0, 1, buff, 0x100);
75
76         memcpy(&sernum, &buff[0xF4], 2);
77         sernum /= 32;
78
79         return (sernum);
80 }
81
82 /*************************************************************************
83  *  sbcommon_fans
84  *
85  *  Spin up fans 2 & 3 to get some air moving.  OS will take care
86  *  of the rest.  This is mostly a precaution...
87  *
88  *  Assumes i2c bus 1 is ready.
89  *
90  ************************************************************************/
91 void sbcommon_fans(void)
92 {
93         /*
94          * Attempt to turn on 2 of the fans...
95          * Need to go through the bridge
96          */
97         puts ("FANS:  ");
98
99         /* select fan4 through the bridge */
100         i2c_reg_write1(0x73, /* addr */
101                        0x00, /* reg */
102                        0x08); /* val = bus 4 */
103
104         /* Turn on FAN 4 */
105         i2c_reg_write1(0x2e,
106                        1,
107                        0x80);
108
109         i2c_reg_write1(0x2e,
110                        0,
111                        0x19);
112
113         /* Deselect bus 4 on the bridge */
114         i2c_reg_write1(0x73,
115                        0x00,
116                        0x00);
117
118         /* select fan3 through the bridge */
119         i2c_reg_write1(0x73, /* addr */
120                        0x00, /* reg */
121                        0x04); /* val = bus 3 */
122
123         /* Turn on FAN 3 */
124         i2c_reg_write1(0x2e,
125                        1,
126                        0x80);
127
128         i2c_reg_write1(0x2e,
129                        0,
130                        0x19);
131
132         /* Deselect bus 3 on the bridge */
133         i2c_reg_write1(0x73,
134                        0x00,
135                        0x00);
136
137         /* select fan2 through the bridge */
138         i2c_reg_write1(0x73, /* addr */
139                        0x00, /* reg */
140                        0x02); /* val = bus 4 */
141
142         /* Turn on FAN 2 */
143         i2c_reg_write1(0x2e,
144                        1,
145                        0x80);
146
147         i2c_reg_write1(0x2e,
148                        0,
149                        0x19);
150
151         /* Deselect bus 2 on the bridge */
152         i2c_reg_write1(0x73,
153                        0x00,
154                        0x00);
155
156         /* select fan1 through the bridge */
157         i2c_reg_write1(0x73, /* addr */
158                        0x00, /* reg */
159                        0x01); /* val = bus 0 */
160
161         /* Turn on FAN 1 */
162         i2c_reg_write1(0x2e,
163                        1,
164                        0x80);
165
166         i2c_reg_write1(0x2e,
167                        0,
168                        0x19);
169
170         /* Deselect bus 1 on the bridge */
171         i2c_reg_write1(0x73,
172                        0x00,
173                        0x00);
174
175         puts ("on\n");
176
177         return;
178
179 }
180
181 /*************************************************************************
182  *  initdram
183  *
184  *  Initialize sdram
185  *
186  ************************************************************************/
187 phys_size_t initdram (int board_type)
188 {
189         long dram_size = 0;
190
191 #if defined(CONFIG_SPD_EEPROM)
192         dram_size = spd_sdram ();
193 #else
194         dram_size = fixed_sdram ();
195 #endif
196         return dram_size;
197 }
198
199
200 /*************************************************************************
201  *  testdram
202  *
203  *
204  ************************************************************************/
205 #if defined(CONFIG_SYS_DRAM_TEST)
206 int testdram (void)
207 {
208         uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
209         uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
210         uint *p;
211
212         printf("Testing SDRAM: ");
213         for (p = pstart; p < pend; p++)
214                 *p = 0xaaaaaaaa;
215
216         for (p = pstart; p < pend; p++) {
217                 if (*p != 0xaaaaaaaa) {
218                         printf ("SDRAM test fails at: %08x\n", (uint) p);
219                         return 1;
220                 }
221         }
222
223         for (p = pstart; p < pend; p++)
224                 *p = 0x55555555;
225
226         for (p = pstart; p < pend; p++) {
227                 if (*p != 0x55555555) {
228                         printf ("SDRAM test fails at: %08x\n", (uint) p);
229                         return 1;
230                 }
231         }
232
233         printf("OK\n");
234         return 0;
235 }
236 #endif
237
238 #if !defined(CONFIG_SPD_EEPROM)
239 /*************************************************************************
240  *  fixed sdram init -- doesn't use serial presence detect.
241  *
242  *  Assumes:    128 MB, non-ECC, non-registered
243  *              PLB @ 133 MHz
244  *
245  ************************************************************************/
246 long int fixed_sdram (void)
247 {
248         uint reg;
249
250         /*--------------------------------------------------------------------
251          * Setup some default
252          *------------------------------------------------------------------*/
253         mtsdram (SDRAM0_UABBA, 0x00000000);     /* ubba=0 (default)             */
254         mtsdram (SDRAM0_SLIO, 0x00000000);              /* rdre=0 wrre=0 rarw=0         */
255         mtsdram (SDRAM0_DEVOPT, 0x00000000);    /* dll=0 ds=0 (normal)          */
256         mtsdram (SDRAM0_WDDCTR, 0x00000000);    /* wrcp=0 dcd=0                 */
257         mtsdram (SDRAM0_CLKTR, 0x40000000);     /* clkp=1 (90 deg wr) dcdt=0    */
258
259         /*--------------------------------------------------------------------
260          * Setup for board-specific specific mem
261          *------------------------------------------------------------------*/
262         /*
263          * Following for CAS Latency = 2.5 @ 133 MHz PLB
264          */
265         mtsdram (SDRAM0_B0CR, 0x000a4001); /* SDBA=0x000 128MB, Mode 3, enabled */
266         mtsdram (SDRAM0_TR0, 0x410a4012);       /* WR=2  WD=1 CL=2.5 PA=3 CP=4 LD=2 */
267         /* RA=10 RD=3                       */
268         mtsdram (SDRAM0_TR1, 0x8080082f);       /* SS=T2 SL=STAGE 3 CD=1 CT=0x02f   */
269         mtsdram (SDRAM0_RTR, 0x08200000);       /* Rate 15.625 ns @ 133 MHz PLB     */
270         mtsdram (SDRAM0_CFG1, 0x00000000); /* Self-refresh exit, disable PM    */
271         udelay (400);                   /* Delay 200 usecs (min)            */
272
273         /*--------------------------------------------------------------------
274          * Enable the controller, then wait for DCEN to complete
275          *------------------------------------------------------------------*/
276         mtsdram (SDRAM0_CFG0, 0x86000000); /* DCEN=1, PMUD=1, 64-bit        */
277         for (;;) {
278                 mfsdram (SDRAM0_MCSTS, reg);
279                 if (reg & 0x80000000)
280                         break;
281         }
282
283         return (128 * 1024 * 1024);     /* 128 MB                           */
284 }
285 #endif  /* !defined(CONFIG_SPD_EEPROM) */
286
287 /*************************************************************************
288  *  board_get_enetaddr
289  *
290  *  Get the ethernet MAC address for the management ethernet from the
291  *  strap EEPROM.  Note that is the BASE address for the range of
292  *  external ethernet MACs on the board.  The base + 31 is the actual
293  *  mgmt mac address.
294  *
295  ************************************************************************/
296
297 void board_get_enetaddr(int macaddr_idx, uchar *enet)
298 {
299         int i;
300         unsigned short tmp;
301         unsigned char buff[0x100], *cp;
302
303         if (0 == macaddr_idx) {
304
305                 /* Initialize I2C */
306                 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
307
308                 /* Read 256 bytes in EEPROM */
309                 i2c_read (0x50, 0, 1, buff, 0x100);
310
311                 cp = &buff[0xF0];
312
313                 for (i = 0; i < 6; i++,cp++)
314                         enet[i] = *cp;
315
316                 memcpy(&tmp, &enet[4], 2);
317                 tmp += 31;
318                 memcpy(&enet[4], &tmp, 2);
319
320         } else {
321                 enet[0] = 0x02;
322                 enet[1] = 0x00;
323                 enet[2] = 0x00;
324                 enet[3] = 0x00;
325                 enet[4] = 0x00;
326                 if (1 == sbcommon_get_master() ) {
327                         /* Master/Primary card */
328                         enet[5] = 0x01;
329                 } else {
330                         /* Slave/Secondary card */
331                         enet [5] = 0x02;
332                 }
333         }
334
335         return;
336 }
337
338 #ifdef CONFIG_POST
339 /*
340  * Returns 1 if keys pressed to start the power-on long-running tests
341  * Called from board_init_f().
342  */
343 int post_hotkeys_pressed(void)
344 {
345
346         return (ctrlc());
347 }
348 #endif