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