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