6b92548243ee452d5fa0d0023e8f66c2c3298bf8
[pandora-u-boot.git] / include / common.h
1 /*
2  * (C) Copyright 2000-2004
3  * Wolfgang Denk, DENX Software Engineering, wd@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 #ifndef __COMMON_H_
25 #define __COMMON_H_     1
26
27 #undef  _LINUX_CONFIG_H
28 #define _LINUX_CONFIG_H 1       /* avoid reading Linux autoconf.h file  */
29
30 typedef unsigned char           uchar;
31 typedef volatile unsigned long  vu_long;
32 typedef volatile unsigned short vu_short;
33 typedef volatile unsigned char  vu_char;
34
35 #include <config.h>
36 #include <linux/bitops.h>
37 #include <linux/types.h>
38 #include <linux/string.h>
39 #include <asm/ptrace.h>
40 #include <stdarg.h>
41 #if defined(CONFIG_PCI) && defined(CONFIG_440)
42 #include <pci.h>
43 #endif
44 #ifdef  CONFIG_8xx
45 #include <asm/8xx_immap.h>
46 #ifdef CONFIG_MPC860
47 #define CONFIG_MPC86x 1
48 #endif
49 #ifdef CONFIG_MPC860T
50 #define CONFIG_MPC86x 1
51 #endif
52 #if defined(CONFIG_MPC852)      || defined(CONFIG_MPC852T)      || \
53     defined(CONFIG_MPC859)      || defined(CONFIG_MPC859T)      || \
54     defined(CONFIG_MPC859DSL)   || \
55     defined(CONFIG_MPC866)      || defined(CONFIG_MPC866T)      || \
56     defined(CONFIG_MPC866P)
57 #define CONFIG_MPC866_et_al 1
58 #define CONFIG_MPC86x 1
59 #endif
60 #elif defined(CONFIG_5xx)
61 #include <asm/5xx_immap.h>
62 #elif defined(CONFIG_8260)
63 #include <asm/immap_8260.h>
64 #endif
65 #ifdef CONFIG_MPC85xx
66 #include <mpc85xx.h>
67 #include <asm/immap_85xx.h>
68 #endif
69 #ifdef  CONFIG_4xx
70 #include <ppc4xx.h>
71 #endif
72 #ifdef CONFIG_HYMOD
73 #include <board/hymod/hymod.h>
74 #endif
75 #ifdef CONFIG_ARM
76 #define asmlinkage      /* nothing */
77 #endif
78
79 #include <part.h>
80 #include <flash.h>
81 #include <image.h>
82
83 #ifdef  DEBUG
84 #define debug(fmt,args...)      printf (fmt ,##args)
85 #define debugX(level,fmt,args...) if (DEBUG>=level) printf(fmt,##args);
86 #else
87 #define debug(fmt,args...)
88 #define debugX(level,fmt,args...)
89 #endif  /* DEBUG */
90
91 typedef void (interrupt_handler_t)(void *);
92
93 #include <asm/u-boot.h> /* boot information for Linux kernel */
94 #include <asm/global_data.h>    /* global data used for startup functions */
95
96 /*
97  * enable common handling for all TQM8xxL/M boards:
98  * - CONFIG_TQM8xxM will be defined for all TQM8xxM boards
99  * - CONFIG_TQM8xxL will be defined for all TQM8xxL _and_ TQM8xxM boards
100  */
101 #if defined(CONFIG_TQM823M) || defined(CONFIG_TQM850M) || \
102     defined(CONFIG_TQM855M) || defined(CONFIG_TQM860M) || \
103     defined(CONFIG_TQM862M) || defined(CONFIG_TQM866M)
104 # ifndef CONFIG_TQM8xxM
105 #  define CONFIG_TQM8xxM
106 # endif
107 #endif
108 #if defined(CONFIG_TQM823L) || defined(CONFIG_TQM850L) || \
109     defined(CONFIG_TQM855L) || defined(CONFIG_TQM860L) || \
110     defined(CONFIG_TQM862L) || defined(CONFIG_TQM8xxM)
111 # ifndef CONFIG_TQM8xxL
112 #  define CONFIG_TQM8xxL
113 # endif
114 #endif
115
116
117 /*
118  * General Purpose Utilities
119  */
120 #define min(X, Y)                               \
121         ({ typeof (X) __x = (X), __y = (Y);     \
122                 (__x < __y) ? __x : __y; })
123
124 #define max(X, Y)                               \
125         ({ typeof (X) __x = (X), __y = (Y);     \
126                 (__x > __y) ? __x : __y; })
127
128
129 /*
130  * Function Prototypes
131  */
132
133 #if CONFIG_SERIAL_SOFTWARE_FIFO
134 void    serial_buffered_init (void);
135 void    serial_buffered_putc (const char);
136 void    serial_buffered_puts (const char *);
137 int     serial_buffered_getc (void);
138 int     serial_buffered_tstc (void);
139 #endif /* CONFIG_SERIAL_SOFTWARE_FIFO */
140
141 void    hang          (void) __attribute__ ((noreturn));
142
143 /* */
144 long int initdram (int);
145 int     display_options (void);
146 void    print_size (ulong, const char *);
147
148 /* common/main.c */
149 void    main_loop       (void);
150 int     run_command     (const char *cmd, int flag);
151 int     readline        (const char *const prompt);
152 void    init_cmd_timeout(void);
153 void    reset_cmd_timeout(void);
154
155 /* lib_$(ARCH)/board.c */
156 void    board_init_f  (ulong);
157 void    board_init_r  (gd_t *, ulong);
158 int     checkboard    (void);
159 int     checkflash    (void);
160 int     checkdram     (void);
161 char *  strmhz(char *buf, long hz);
162 int     last_stage_init(void);
163 extern ulong monitor_flash_len;
164
165 /* common/flash.c */
166 void flash_perror (int);
167
168 /* common/cmd_autoscript.c */
169 int     autoscript (ulong addr);
170
171 /* common/cmd_bootm.c */
172 void    print_image_hdr (image_header_t *hdr);
173
174 extern ulong load_addr;         /* Default Load Address */
175
176 /* common/cmd_nvedit.c */
177 int     env_init     (void);
178 void    env_relocate (void);
179 char    *getenv      (uchar *);
180 int     getenv_r     (uchar *name, uchar *buf, unsigned len);
181 int     saveenv      (void);
182 #ifdef CONFIG_PPC               /* ARM version to be fixed! */
183 void inline setenv   (char *, char *);
184 #else
185 void    setenv       (char *, char *);
186 #endif /* CONFIG_PPC */
187 #ifdef CONFIG_ARM
188 # include <asm/setup.h>
189 # include <asm/u-boot-arm.h>    /* ARM version to be fixed! */
190 #endif /* CONFIG_ARM */
191 #ifdef CONFIG_I386              /* x86 version to be fixed! */
192 # include <asm/u-boot-i386.h>
193 #endif /* CONFIG_I386 */
194
195 void    pci_init      (void);
196 void    pci_init_board(void);
197 void    pciinfo       (int, int);
198
199 #if defined(CONFIG_PCI) && defined(CONFIG_440)
200 #   if defined(CFG_PCI_PRE_INIT)
201     int    pci_pre_init        (struct pci_controller * );
202 #   endif
203 #   if defined(CFG_PCI_TARGET_INIT)
204         void    pci_target_init      (struct pci_controller *);
205 #   endif
206 #   if defined(CFG_PCI_MASTER_INIT)
207         void    pci_master_init      (struct pci_controller *);
208 #   endif
209     int     is_pci_host         (struct pci_controller *);
210 #endif
211
212 int     misc_init_f   (void);
213 int     misc_init_r   (void);
214
215 /* common/exports.c */
216 void    jumptable_init(void);
217
218 /* $(BOARD)/$(BOARD).c */
219 void    reset_phy     (void);
220 void    fdc_hw_init   (void);
221
222 /* $(BOARD)/eeprom.c */
223 void eeprom_init  (void);
224 #ifndef CONFIG_SPI
225 int  eeprom_probe (unsigned dev_addr, unsigned offset);
226 #endif
227 int  eeprom_read  (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
228 int  eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
229 #ifdef CONFIG_LWMON
230 extern uchar pic_read  (uchar reg);
231 extern void  pic_write (uchar reg, uchar val);
232 #endif
233
234 /*
235  * Set this up regardless of board
236  * type, to prevent errors.
237  */
238 #if defined(CONFIG_SPI) || !defined(CFG_I2C_EEPROM_ADDR)
239 # define CFG_DEF_EEPROM_ADDR 0
240 #else
241 # define CFG_DEF_EEPROM_ADDR CFG_I2C_EEPROM_ADDR
242 #endif /* CONFIG_SPI || !defined(CFG_I2C_EEPROM_ADDR) */
243
244 #if defined(CONFIG_SPI)
245 extern void spi_init_f (void);
246 extern void spi_init_r (void);
247 extern ssize_t spi_read  (uchar *, int, uchar *, int);
248 extern ssize_t spi_write (uchar *, int, uchar *, int);
249 #endif
250
251 #ifdef CONFIG_RPXCLASSIC
252 void rpxclassic_init (void);
253 #endif
254
255 #ifdef CONFIG_MBX
256 /* $(BOARD)/mbx8xx.c */
257 void    mbx_init (void);
258 void    board_serial_init (void);
259 void    board_ether_init (void);
260 #endif
261
262 #if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_MBX) || defined(CONFIG_IAD210)
263 void    board_get_enetaddr (uchar *addr);
264 #endif
265
266 #ifdef CONFIG_HERMES
267 /* $(BOARD)/hermes.c */
268 void hermes_start_lxt980 (int speed);
269 #endif
270
271 #ifdef CONFIG_EVB64260
272 void  evb64260_init(void);
273 void  debug_led(int, int);
274 void  display_mem_map(void);
275 void  perform_soft_reset(void);
276 #endif
277
278 void    load_sernum_ethaddr (void);
279
280 /* $(BOARD)/$(BOARD).c */
281 int board_pre_init (void);
282 int board_post_init (void);
283 int board_postclk_init (void); /* after clocks/timebase, before env/serial */
284 void board_poweroff (void);
285
286 #if defined(CFG_DRAM_TEST)
287 int testdram(void);
288 #endif /* CFG_DRAM_TEST */
289
290 /* $(CPU)/start.S */
291 #if defined(CONFIG_5xx) || \
292     defined(CONFIG_8xx)
293 uint    get_immr      (uint);
294 #endif
295 uint    get_pir       (void);
296 uint    get_pvr       (void);
297 uint    rd_ic_cst     (void);
298 void    wr_ic_cst     (uint);
299 void    wr_ic_adr     (uint);
300 uint    rd_dc_cst     (void);
301 void    wr_dc_cst     (uint);
302 void    wr_dc_adr     (uint);
303 int     icache_status (void);
304 void    icache_enable (void);
305 void    icache_disable(void);
306 int     dcache_status (void);
307 void    dcache_enable (void);
308 void    dcache_disable(void);
309 void    relocate_code (ulong, gd_t *, ulong);
310 ulong   get_endaddr   (void);
311 void    trap_init     (ulong);
312 #if defined (CONFIG_4xx)        || \
313     defined (CONFIG_74xx_7xx)   || \
314     defined (CONFIG_74x)        || \
315     defined (CONFIG_75x)        || \
316     defined (CONFIG_74xx)
317 unsigned char   in8(unsigned int);
318 void            out8(unsigned int, unsigned char);
319 unsigned short  in16(unsigned int);
320 unsigned short  in16r(unsigned int);
321 void            out16(unsigned int, unsigned short value);
322 void            out16r(unsigned int, unsigned short value);
323 unsigned long   in32(unsigned int);
324 unsigned long   in32r(unsigned int);
325 void            out32(unsigned int, unsigned long value);
326 void            out32r(unsigned int, unsigned long value);
327 void            ppcDcbf(unsigned long value);
328 void            ppcDcbi(unsigned long value);
329 void            ppcSync(void);
330 #endif
331
332 /* $(CPU)/cpu.c */
333 int     checkcpu      (void);
334 int     checkicache   (void);
335 int     checkdcache   (void);
336 void    upmconfig     (unsigned int, unsigned int *, unsigned int);
337 ulong   get_tbclk     (void);
338
339 /* $(CPU)/serial.c */
340 int     serial_init   (void);
341 void    serial_setbrg (void);
342 void    serial_putc   (const char);
343 void    serial_puts   (const char *);
344 void    serial_addr   (unsigned int);
345 int     serial_getc   (void);
346 int     serial_tstc   (void);
347
348 /* $(CPU)/speed.c */
349 int     get_clocks (void);
350 #if defined(CONFIG_8260)
351 int     prt_8260_clks (void);
352 #endif
353 #if defined(CONFIG_MPC5XXX)
354 int     prt_mpc5xxx_clks (void);
355 #endif
356 #ifdef CONFIG_4xx
357 ulong   get_OPB_freq (void);
358 ulong   get_PCI_freq (void);
359 #endif
360 #if defined(CONFIG_S3C2400) || defined(CONFIG_S3C2410)
361 ulong   get_FCLK (void);
362 ulong   get_HCLK (void);
363 ulong   get_PCLK (void);
364 ulong   get_UCLK (void);
365 #endif
366 #if defined CONFIG_INCA_IP
367 uint    incaip_get_cpuclk (void);
368 #endif
369 ulong   get_bus_freq  (ulong);
370
371 #if defined(CONFIG_MPC85xx)
372 typedef MPC85xx_SYS_INFO sys_info_t;
373 void    get_sys_info  ( sys_info_t * );
374 #endif
375
376 #if defined(CONFIG_4xx) || defined(CONFIG_IOP480)
377 #  if defined(CONFIG_440)
378     typedef PPC440_SYS_INFO sys_info_t;
379 #  else
380     typedef PPC405_SYS_INFO sys_info_t;
381 #  endif
382 void    get_sys_info  ( sys_info_t * );
383 #endif
384
385 /* $(CPU)/cpu_init.c */
386 #if defined(CONFIG_8xx) || defined(CONFIG_8260)
387 void    cpu_init_f    (volatile immap_t *immr);
388 #endif
389 #if defined(CONFIG_4xx) || defined(CONFIG_MPC85xx)
390 void    cpu_init_f    (void);
391 #endif
392 int     cpu_init_r    (void);
393 #if defined(CONFIG_8260)
394 int     prt_8260_rsr  (void);
395 #endif
396
397 /* $(CPU)/interrupts.c */
398 int     interrupt_init     (void);
399 void    timer_interrupt    (struct pt_regs *);
400 void    external_interrupt (struct pt_regs *);
401 void    irq_install_handler(int, interrupt_handler_t *, void *);
402 void    irq_free_handler   (int);
403 void    reset_timer        (void);
404 ulong   get_timer          (ulong base);
405 void    set_timer          (ulong t);
406 void    enable_interrupts  (void);
407 int     disable_interrupts (void);
408
409 /* $(CPU)/.../commproc.c */
410 int     dpram_init (void);
411 uint    dpram_base(void);
412 uint    dpram_base_align(uint align);
413 uint    dpram_alloc(uint size);
414 uint    dpram_alloc_align(uint size,uint align);
415 void    post_word_store (ulong);
416 ulong   post_word_load (void);
417 void    bootcount_store (ulong);
418 ulong   bootcount_load (void);
419 #define BOOTCOUNT_MAGIC         0xB001C041
420
421 /* $(CPU)/.../<eth> */
422 void mii_init (void);
423
424 /* $(CPU)/.../lcd.c */
425 ulong   lcd_setmem (ulong);
426
427 /* $(CPU)/.../vfd.c */
428 ulong   vfd_setmem (ulong);
429
430 /* $(CPU)/.../video.c */
431 ulong   video_setmem (ulong);
432
433 /* ppc/cache.c */
434 void    flush_cache   (unsigned long, unsigned long);
435
436
437 /* lib_$(ARCH)/ticks.S */
438 unsigned long long get_ticks(void);
439 void    wait_ticks    (unsigned long);
440
441 /* lib_$(ARCH)/time.c */
442 void    udelay        (unsigned long);
443 ulong   usec2ticks    (unsigned long usec);
444 ulong   ticks2usec    (unsigned long ticks);
445 int     init_timebase (void);
446
447 /* lib_generic/vsprintf.c */
448 ulong   simple_strtoul(const char *cp,char **endp,unsigned int base);
449 long    simple_strtol(const char *cp,char **endp,unsigned int base);
450 void    panic(const char *fmt, ...);
451 int     sprintf(char * buf, const char *fmt, ...);
452 int     vsprintf(char *buf, const char *fmt, va_list args);
453
454 /* lib_generic/crc32.c */
455 ulong crc32 (ulong, const unsigned char *, uint);
456 ulong crc32_no_comp (ulong, const unsigned char *, uint);
457
458 /* common/console.c */
459 int     console_init_f(void);   /* Before relocation; uses the serial  stuff    */
460 int     console_init_r(void);   /* After  relocation; uses the console stuff    */
461 int     console_assign (int file, char *devname);       /* Assign the console   */
462 int     ctrlc (void);
463 int     had_ctrlc (void);       /* have we had a Control-C since last clear? */
464 void    clear_ctrlc (void);     /* clear the Control-C condition */
465 int     disable_ctrlc (int);    /* 1 to disable, 0 to enable Control-C detect */
466
467 /*
468  * STDIO based functions (can always be used)
469  */
470
471 /* serial stuff */
472 void    serial_printf (const char *fmt, ...);
473
474 /* stdin */
475 int     getc(void);
476 int     tstc(void);
477
478 /* stdout */
479 void    putc(const char c);
480 void    puts(const char *s);
481 void    printf(const char *fmt, ...);
482 void    vprintf(const char *fmt, va_list args);
483
484 /* stderr */
485 #define eputc(c)                fputc(stderr, c)
486 #define eputs(s)                fputs(stderr, s)
487 #define eprintf(fmt,args...)    fprintf(stderr,fmt ,##args)
488
489 /*
490  * FILE based functions (can only be used AFTER relocation!)
491  */
492
493 #define stdin           0
494 #define stdout          1
495 #define stderr          2
496 #define MAX_FILES       3
497
498 void    fprintf(int file, const char *fmt, ...);
499 void    fputs(int file, const char *s);
500 void    fputc(int file, const char c);
501 int     ftstc(int file);
502 int     fgetc(int file);
503
504 int     pcmcia_init (void);
505
506 #ifdef CONFIG_SHOW_BOOT_PROGRESS
507 void    show_boot_progress (int status);
508 #endif
509
510 #endif  /* __COMMON_H_ */