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