]> git.sur5r.net Git - u-boot/blob - board/muas3001/muas3001.c
0ec451fbd5515a2827dd7cc00582b164e8446711
[u-boot] / board / muas3001 / muas3001.c
1 /*
2  * (C) Copyright 2008
3  * Heiko Schocher, DENX Software Engineering, hs@denx.de.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <mpc8260.h>
26 #include <ioports.h>
27
28 #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
29 #include <libfdt.h>
30 #endif
31
32 /*
33  * I/O Port configuration table
34  *
35  * if conf is 1, then that port pin will be configured at boot time
36  * according to the five values podr/pdir/ppar/psor/pdat for that entry
37  */
38 const iop_conf_t iop_conf_tab[4][32] = {
39
40     /* Port A */
41     {   /*            conf      ppar psor pdir podr pdat */
42         /* PA31 */ { 0,          0,   0,   0,   0,   0 }, /* PA31            */
43         /* PA30 */ { 0,          0,   0,   0,   0,   0 }, /* PA30            */
44         /* PA29 */ { 1,          1,   1,   1,   0,   0 }, /* FCC1 TXER */
45         /* PA28 */ { 1,          1,   1,   1,   0,   0 }, /* FCC1 TXEN */
46         /* PA27 */ { 1,          1,   1,   0,   0,   0 }, /* FCC1 RXDV */
47         /* PA26 */ { 1,          1,   1,   0,   0,   0 }, /* FCC1 RXER */
48         /* PA25 */ { 1,          0,   0,   1,   0,   0 }, /* ETH_PWRDWN      */
49         /* PA24 */ { 1,          0,   0,   1,   0,   1 }, /* ETH_RESET       */
50         /* PA23 */ { 0,          0,   0,   0,   0,   0 }, /* PA23            */
51         /* PA22 */ { 0,          0,   0,   0,   0,   0 }, /* PA22            */
52         /* PA21 */ { 1,          1,   0,   1,   0,   0 }, /* FCC1 TXD3 */
53         /* PA20 */ { 1,          1,   0,   1,   0,   0 }, /* FCC1 TXD2 */
54         /* PA19 */ { 1,          1,   0,   1,   0,   0 }, /* FCC1 TXD1 */
55         /* PA18 */ { 1,          1,   0,   1,   0,   0 }, /* FCC1 TXD0 */
56         /* PA17 */ { 1,          1,   0,   0,   0,   0 }, /* FCC1 RXD0 */
57         /* PA16 */ { 1,          1,   0,   0,   0,   0 }, /* FCC1 RXD1 */
58         /* PA15 */ { 1,          1,   0,   0,   0,   0 }, /* FCC1 RXD2 */
59         /* PA14 */ { 1,          1,   0,   0,   0,   0 }, /* FCC1 RXD3 */
60         /* PA13 */ { 0,          0,   0,   0,   0,   0 }, /* PA13            */
61         /* PA12 */ { 1,          0,   0,   1,   0,   0 }, /* ETH_SLEEP       */
62         /* PA11 */ { 0,          0,   0,   0,   0,   0 }, /* PA11            */
63         /* PA10 */ { 1,          0,   0,   1,   0,   0 }, /* MDIO            */
64         /* PA9  */ { 1,          0,   0,   1,   0,   0 }, /* MDC             */
65         /* PA8  */ { 1,          1,   0,   0,   0,   0 }, /* SMC2 RxD        */
66         /* PA7  */ { 0,          0,   0,   0,   0,   0 }, /* PA7             */
67         /* PA6  */ { 0,          0,   0,   0,   0,   0 }, /* PA6             */
68         /* PA5  */ { 0,          0,   0,   0,   0,   0 }, /* PA5             */
69         /* PA4  */ { 0,          0,   0,   0,   0,   0 }, /* PA4             */
70         /* PA3  */ { 0,          0,   0,   0,   0,   0 }, /* PA3             */
71         /* PA2  */ { 0,          0,   0,   0,   0,   0 }, /* PA2             */
72         /* PA1  */ { 0,          0,   0,   0,   0,   0 }, /* PA1             */
73         /* PA0  */ { 0,          0,   0,   0,   0,   0 }  /* PA0             */
74     },
75
76     /* Port B */
77     {   /*            conf      ppar psor pdir podr pdat */
78         /* PB31 */ { 0,          0,   0,   0,   0,   0 }, /* PB31            */
79         /* PB30 */ { 0,          0,   0,   0,   0,   0 }, /* PB30            */
80         /* PB29 */ { 0,          0,   0,   0,   0,   0 }, /* PB29            */
81         /* PB28 */ { 1,          1,   1,   1,   0,   0 }, /* SCC1 TxD        */
82         /* PB27 */ { 0,          0,   0,   0,   0,   0 }, /* PB27            */
83         /* PB26 */ { 0,          0,   0,   0,   0,   0 }, /* PB26            */
84         /* PB25 */ { 0,          0,   0,   0,   0,   0 }, /* PB25            */
85         /* PB24 */ { 0,          0,   0,   0,   0,   0 }, /* PB24            */
86         /* PB23 */ { 0,          0,   0,   0,   0,   0 }, /* PB23            */
87         /* PB22 */ { 0,          0,   0,   0,   0,   0 }, /* PB22            */
88         /* PB21 */ { 0,          0,   0,   0,   0,   0 }, /* PB21            */
89         /* PB20 */ { 0,          0,   0,   0,   0,   0 }, /* PB20            */
90         /* PB19 */ { 0,          0,   0,   0,   0,   0 }, /* PB19            */
91         /* PB18 */ { 0,          0,   0,   0,   0,   0 }, /* PB18            */
92         /* PB17 */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
93         /* PB16 */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
94         /* PB15 */ { 1,          1,   0,   0,   0,   0 }, /* SCC2 RxD        */
95         /* PB14 */ { 1,          1,   0,   0,   0,   0 }, /* SCC3 RxD        */
96         /* PB13 */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
97         /* PB12 */ { 1,          1,   1,   1,   0,   0 }, /* SCC2 TxD        */
98         /* PB11 */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
99         /* PB10 */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
100         /* PB9  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
101         /* PB8  */ { 1,          1,   1,   1,   0,   0 }, /* SCC3 TxD        */
102         /* PB7  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
103         /* PB6  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
104         /* PB5  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
105         /* PB4  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
106         /* PB3  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
107         /* PB2  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
108         /* PB1  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
109         /* PB0  */ { 0,          0,   0,   0,   0,   0 }  /* non-existent    */
110     },
111
112     /* Port C */
113     {   /*            conf      ppar psor pdir podr pdat */
114         /* PC31 */ { 0,          0,   0,   0,   0,   0 }, /* PC31            */
115         /* PC30 */ { 1,          1,   1,   1,   0,   0 }, /* Timer1 OUT      */
116         /* PC29 */ { 0,          0,   0,   0,   0,   0 }, /* PC29            */
117         /* PC28 */ { 0,          0,   0,   0,   0,   0 }, /* PC28            */
118         /* PC27 */ { 0,          0,   0,   0,   0,   0 }, /* PC27            */
119         /* PC26 */ { 0,          0,   0,   0,   0,   0 }, /* PC26            */
120         /* PC25 */ { 0,          0,   0,   0,   0,   0 }, /* PC25            */
121         /* PC24 */ { 0,          0,   0,   0,   0,   0 }, /* PC24            */
122         /* PC23 */ { 0,          0,   0,   0,   0,   0 }, /* PC23            */
123         /* PC22 */ { 0,          0,   0,   0,   0,   0 }, /* PC22            */
124         /* PC21 */ { 1,          1,   0,   0,   0,   0 }, /* FCC RxCLK 11    */
125         /* PC20 */ { 1,          1,   0,   0,   0,   0 }, /* FCC TxCLK 12    */
126         /* PC19 */ { 0,          0,   0,   0,   0,   0 }, /* PC19            */
127         /* PC18 */ { 0,          0,   0,   0,   0,   0 }, /* PC18            */
128         /* PC17 */ { 0,          0,   0,   0,   0,   0 }, /* PC17            */
129         /* PC16 */ { 0,          0,   0,   0,   0,   0 }, /* PC16            */
130         /* PC15 */ { 1,          1,   0,   1,   0,   0 }, /* SMC2 TxD        */
131         /* PC14 */ { 0,          0,   0,   0,   0,   0 }, /* PC14            */
132         /* PC13 */ { 0,          0,   0,   0,   0,   0 }, /* PC13            */
133         /* PC12 */ { 1,          0,   0,   1,   0,   0 }, /* TX OUTPUT SLEW1 */
134         /* PC11 */ { 1,          0,   0,   1,   0,   0 }, /* TX OUTPUT SLEW0 */
135         /* PC10 */ { 0,          0,   0,   0,   0,   0 }, /* PC10            */
136         /* PC9  */ { 1,          0,   0,   1,   0,   1 }, /* SPA_TX_EN       */
137         /* PC8  */ { 0,          0,   0,   0,   0,   0 }, /* PC8             */
138         /* PC7  */ { 0,          0,   0,   0,   0,   0 }, /* PC7             */
139         /* PC6  */ { 0,          0,   0,   0,   0,   0 }, /* PC6             */
140         /* PC5  */ { 0,          0,   0,   0,   0,   0 }, /* PC5             */
141         /* PC4  */ { 0,          0,   0,   0,   0,   0 }, /* PC4             */
142         /* PC3  */ { 0,          0,   0,   0,   0,   0 }, /* PC3             */
143         /* PC2  */ { 0,          0,   0,   0,   0,   0 }, /* PC2             */
144         /* PC1  */ { 0,          0,   0,   0,   0,   0 }, /* PC1             */
145         /* PC0  */ { 0,          0,   0,   0,   0,   0 }, /* PC0             */
146     },
147
148     /* Port D */
149     {   /*            conf      ppar psor pdir podr pdat */
150         /* PD31 */ { 1,          1,   0,   0,   0,   0 }, /* SCC1 RxD        */
151         /* PD30 */ { 0,          0,   0,   0,   0,   0 }, /* PD30            */
152         /* PD29 */ { 0,          0,   0,   0,   0,   0 }, /* PD29            */
153         /* PD28 */ { 0,          0,   0,   0,   0,   0 }, /* PD28            */
154         /* PD27 */ { 0,          0,   0,   0,   0,   0 }, /* PD27            */
155         /* PD26 */ { 0,          0,   0,   0,   0,   0 }, /* PD26            */
156         /* PD25 */ { 0,          0,   0,   0,   0,   0 }, /* PD25            */
157         /* PD24 */ { 0,          0,   0,   0,   0,   0 }, /* PD24            */
158         /* PD23 */ { 0,          0,   0,   0,   0,   0 }, /* PD23            */
159         /* PD22 */ { 1,          1,   0,   0,   0,   0 }, /* SCC4: RXD       */
160         /* PD21 */ { 1,          1,   0,   1,   0,   0 }, /* SCC4: TXD       */
161         /* PD20 */ { 0,          0,   0,   0,   0,   0 }, /* PD18            */
162         /* PD19 */ { 0,          0,   0,   0,   0,   0 }, /* PD19            */
163         /* PD18 */ { 0,          0,   0,   0,   0,   0 }, /* PD18            */
164         /* PD17 */ { 0,          0,   0,   0,   0,   0 }, /* PD17            */
165         /* PD16 */ { 0,          0,   0,   0,   0,   0 }, /* PD16            */
166         /* PD15 */ { 1,          1,   1,   0,   0,   0 }, /* I2C SDA         */
167         /* PD14 */ { 1,          1,   1,   0,   0,   0 }, /* I2C SCL         */
168         /* PD13 */ { 0,          0,   0,   0,   0,   0 }, /* PD13            */
169         /* PD12 */ { 0,          0,   0,   0,   0,   0 }, /* PD12            */
170         /* PD11 */ { 0,          0,   0,   0,   0,   0 }, /* PD11            */
171         /* PD10 */ { 0,          0,   0,   0,   0,   0 }, /* PD10            */
172         /* PD9  */ { 1,          1,   0,   1,   0,   0 }, /* SMC1 TxD        */
173         /* PD8  */ { 1,          1,   0,   0,   0,   0 }, /* SMC1 RxD        */
174         /* PD7  */ { 0,          0,   0,   0,   0,   0 }, /* PD7             */
175         /* PD6  */ { 0,          0,   0,   0,   0,   0 }, /* PD6             */
176         /* PD5  */ { 0,          0,   0,   0,   0,   0 }, /* PD5             */
177         /* PD4  */ { 0,          0,   0,   0,   0,   0 }, /* PD4             */
178         /* PD3  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
179         /* PD2  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
180         /* PD1  */ { 0,          0,   0,   0,   0,   0 }, /* non-existent    */
181         /* PD0  */ { 0,          0,   0,   0,   0,   0 }  /* non-existent    */
182     }
183 };
184
185 /* Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
186  *
187  * This routine performs standard 8260 initialization sequence
188  * and calculates the available memory size. It may be called
189  * several times to try different SDRAM configurations on both
190  * 60x and local buses.
191  */
192 static long int try_init (volatile memctl8260_t * memctl, ulong sdmr,
193                                                   ulong orx, volatile uchar * base)
194 {
195         volatile uchar c = 0xff;
196         volatile uint *sdmr_ptr;
197         volatile uint *orx_ptr;
198         ulong maxsize, size;
199         int i;
200
201         /* We must be able to test a location outsize the maximum legal size
202          * to find out THAT we are outside; but this address still has to be
203          * mapped by the controller. That means, that the initial mapping has
204          * to be (at least) twice as large as the maximum expected size.
205          */
206         maxsize = (1 + (~orx | 0x7fff))/* / 2*/;
207
208         sdmr_ptr = &memctl->memc_psdmr;
209         orx_ptr = &memctl->memc_or1;
210
211         *orx_ptr = orx;
212
213         /*
214          * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
215          *
216          * "At system reset, initialization software must set up the
217          *  programmable parameters in the memory controller banks registers
218          *  (ORx, BRx, P/LSDMR). After all memory parameters are configured,
219          *  system software should execute the following initialization sequence
220          *  for each SDRAM device.
221          *
222          *  1. Issue a PRECHARGE-ALL-BANKS command
223          *  2. Issue eight CBR REFRESH commands
224          *  3. Issue a MODE-SET command to initialize the mode register
225          *
226          *  The initial commands are executed by setting P/LSDMR[OP] and
227          *  accessing the SDRAM with a single-byte transaction."
228          *
229          * The appropriate BRx/ORx registers have already been set when we
230          * get here. The SDRAM can be accessed at the address CFG_SDRAM_BASE.
231          */
232
233         *sdmr_ptr = sdmr | PSDMR_OP_PREA;
234         *base = c;
235
236         *sdmr_ptr = sdmr | PSDMR_OP_CBRR;
237         for (i = 0; i < 8; i++)
238                 *base = c;
239
240         *sdmr_ptr = sdmr | PSDMR_OP_MRW;
241         *(base + CFG_MRS_OFFS) = c;     /* setting MR on address lines */
242
243         *sdmr_ptr = sdmr | PSDMR_OP_NORM | PSDMR_RFEN;
244         *base = c;
245
246         size = get_ram_size ((long *)base, maxsize);
247         *orx_ptr = orx | ~(size - 1);
248
249         return (size);
250 }
251
252 phys_size_t initdram (int board_type)
253 {
254         volatile immap_t *immap = (immap_t *) CFG_IMMR;
255         volatile memctl8260_t *memctl = &immap->im_memctl;
256         long psize;
257 #ifndef CFG_RAMBOOT
258         long sizelittle, sizebig;
259 #endif
260
261         memctl->memc_psrt = CFG_PSRT;
262         memctl->memc_mptpr = CFG_MPTPR;
263
264 #ifndef CFG_RAMBOOT
265         /* 60x SDRAM setup:
266          */
267         sizelittle = try_init (memctl, CFG_PSDMR_LITTLE, CFG_OR1_LITTLE,
268                                                   (uchar *) CFG_SDRAM_BASE);
269         sizebig = try_init (memctl, CFG_PSDMR_BIG, CFG_OR1_BIG,
270                                                   (uchar *) CFG_SDRAM_BASE);
271         if (sizelittle < sizebig) {
272                 psize = sizebig;
273         } else {
274                 psize = try_init (memctl, CFG_PSDMR_LITTLE, CFG_OR1_LITTLE,
275                                                   (uchar *) CFG_SDRAM_BASE);
276         }
277 #endif /* CFG_RAMBOOT */
278
279         icache_enable ();
280
281         return (psize);
282 }
283
284 int checkboard (void)
285 {
286         puts ("Board: MUAS3001\n");
287
288         return 0;
289 }
290
291 /*
292  * Early board initalization.
293  */
294 int board_early_init_r (void)
295 {
296         return 0;
297 }
298
299 #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
300 /*
301  * update "memory" property in the blob
302  */
303 void ft_blob_update (void *blob, bd_t *bd)
304 {
305         int ret, nodeoffset = 0;
306         ulong memory_data[2] = {0};
307         ulong flash_data[4] = {0};
308         ulong freq = 0;
309         ulong   speed = 0;
310
311         memory_data[0] = cpu_to_be32 (bd->bi_memstart);
312         memory_data[1] = cpu_to_be32 (bd->bi_memsize);
313
314         nodeoffset = fdt_path_offset (blob, "/memory");
315         if (nodeoffset >= 0) {
316                 ret = fdt_setprop (blob, nodeoffset, "reg", memory_data,
317                                         sizeof(memory_data));
318         if (ret < 0)
319                 printf ("ft_blob_update): cannot set /memory/reg "
320                         "property err:%s\n", fdt_strerror (ret));
321         } else {
322                 /* memory node is required in dts */
323                 printf ("ft_blob_update(): cannot find /memory node "
324                         "err:%s\n", fdt_strerror(nodeoffset));
325         }
326         /* update Flash addr, size */
327         flash_data[2] = cpu_to_be32 (CFG_FLASH_BASE);
328         flash_data[3] = cpu_to_be32 (CFG_FLASH_SIZE);
329         nodeoffset = fdt_path_offset (blob, "/localbus");
330         if (nodeoffset >= 0) {
331                 ret = fdt_setprop (blob, nodeoffset, "ranges", flash_data,
332                                         sizeof (flash_data));
333         if (ret < 0)
334                 printf ("ft_blob_update): cannot set /localbus/ranges "
335                         "property err:%s\n", fdt_strerror(ret));
336         } else {
337                 /* memory node is required in dts */
338                 printf ("ft_blob_update(): cannot find /localbus node "
339                         "err:%s\n", fdt_strerror (nodeoffset));
340         }
341         /* MAC Adresse */
342         nodeoffset = fdt_path_offset (blob, "/soc/cpm/ethernet");
343         if (nodeoffset >= 0) {
344                 ret = fdt_setprop (blob, nodeoffset, "mac-address", bd->bi_enetaddr,
345                                         sizeof (uchar) * 6);
346         if (ret < 0)
347                 printf ("ft_blob_update): cannot set /soc/cpm/ethernet/mac-address "
348                         "property err:%s\n", fdt_strerror (ret));
349         } else {
350                 /* memory node is required in dts */
351                 printf ("ft_blob_update(): cannot find /soc/cpm/ethernet node "
352                         "err:%s\n", fdt_strerror (nodeoffset));
353         }
354
355         /* brg clock */
356         nodeoffset = fdt_path_offset (blob, "/soc/cpm/brg");
357         if (nodeoffset >= 0) {
358                 freq = cpu_to_be32 (bd->bi_brgfreq);
359                 ret = fdt_setprop (blob, nodeoffset, "clock-frequency", &freq,
360                                         sizeof (unsigned long));
361         if (ret < 0)
362                 printf ("ft_blob_update): cannot set /soc/cpm/brg/clock-frequency "
363                         "property err:%s\n", fdt_strerror (ret));
364         } else {
365                 /* memory node is required in dts */
366                 printf ("ft_blob_update(): cannot find /soc/cpm/brg/clock-frequency node "
367                         "err:%s\n", fdt_strerror (nodeoffset));
368         }
369
370         /* baudrate */
371         nodeoffset = fdt_path_offset (blob, "/soc/cpm/serial");
372         if (nodeoffset >= 0) {
373                 speed = cpu_to_be32 (bd->bi_baudrate);
374                 ret = fdt_setprop (blob, nodeoffset, "current-speed", &speed,
375                                         sizeof (unsigned long));
376         if (ret < 0)
377                 printf ("ft_blob_update): cannot set /soc/cpm/serial/current-speed "
378                         "property err:%s\n", fdt_strerror (ret));
379         } else {
380                 /* baudrate is required in dts */
381                 printf ("ft_blob_update(): cannot find /soc/cpm/smc2/current-speed node "
382                         "err:%s\n", fdt_strerror (nodeoffset));
383         }
384 }
385
386 void ft_board_setup (void *blob, bd_t *bd)
387 {
388         ft_cpu_setup (blob, bd);
389         ft_blob_update (blob, bd);
390 }
391 #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */