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