blob: 73a5a2e880638d9cbc56c9180e9128672449f4e7 [file] [log] [blame]
wdenke2211742002-11-02 23:30:20 +00001/*
wdenkd4ca31c2004-01-02 14:00:00 +00002 * (C) Copyright 2000-2004
wdenke2211742002-11-02 23:30:20 +00003 * 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
30typedef unsigned char uchar;
31typedef volatile unsigned long vu_long;
32typedef volatile unsigned short vu_short;
33typedef 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>
wdenk2535d602003-07-17 23:16:40 +000046#ifdef CONFIG_MPC860
47#define CONFIG_MPC86x 1
48#endif
49#ifdef CONFIG_MPC860T
50#define CONFIG_MPC86x 1
51#endif
wdenkd4ca31c2004-01-02 14:00:00 +000052#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)
wdenk2535d602003-07-17 23:16:40 +000057#define CONFIG_MPC866_et_al 1
58#define CONFIG_MPC86x 1
59#endif
wdenk0db5bca2003-03-31 17:27:09 +000060#elif defined(CONFIG_5xx)
61#include <asm/5xx_immap.h>
wdenke2211742002-11-02 23:30:20 +000062#elif defined(CONFIG_8260)
63#include <asm/immap_8260.h>
64#endif
wdenk42d1f032003-10-15 23:53:47 +000065#ifdef CONFIG_MPC85xx
66#include <mpc85xx.h>
67#include <asm/immap_85xx.h>
68#endif
wdenke2211742002-11-02 23:30:20 +000069#ifdef CONFIG_4xx
70#include <ppc4xx.h>
71#endif
72#ifdef CONFIG_HYMOD
wdenk6dd652f2003-06-19 23:40:20 +000073#include <board/hymod/hymod.h>
wdenke2211742002-11-02 23:30:20 +000074#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)
wdenk52f52c12003-06-19 23:04:19 +000085#define debugX(level,fmt,args...) if (DEBUG>=level) printf(fmt,##args);
wdenke2211742002-11-02 23:30:20 +000086#else
87#define debug(fmt,args...)
wdenk52f52c12003-06-19 23:04:19 +000088#define debugX(level,fmt,args...)
wdenke2211742002-11-02 23:30:20 +000089#endif /* DEBUG */
90
91typedef 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
wdenk71f95112003-06-15 22:40:42 +000096/*
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) || \
wdenkd4ca31c2004-01-02 14:00:00 +0000103 defined(CONFIG_TQM862M) || defined(CONFIG_TQM866M)
wdenk71f95112003-06-15 22:40:42 +0000104# ifndef CONFIG_TQM8xxM
105# define CONFIG_TQM8xxM
106# endif
107#endif
wdenke2211742002-11-02 23:30:20 +0000108#if defined(CONFIG_TQM823L) || defined(CONFIG_TQM850L) || \
wdenkd126bfb2003-04-10 11:18:18 +0000109 defined(CONFIG_TQM855L) || defined(CONFIG_TQM860L) || \
wdenk71f95112003-06-15 22:40:42 +0000110 defined(CONFIG_TQM862L) || defined(CONFIG_TQM8xxM)
wdenke2211742002-11-02 23:30:20 +0000111# ifndef CONFIG_TQM8xxL
112# define CONFIG_TQM8xxL
113# endif
114#endif
115
116
117/*
wdenkc7de8292002-11-19 11:04:11 +0000118 * 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/*
wdenke2211742002-11-02 23:30:20 +0000130 * Function Prototypes
131 */
132
133#if CONFIG_SERIAL_SOFTWARE_FIFO
134void serial_buffered_init (void);
135void serial_buffered_putc (const char);
136void serial_buffered_puts (const char *);
137int serial_buffered_getc (void);
138int serial_buffered_tstc (void);
139#endif /* CONFIG_SERIAL_SOFTWARE_FIFO */
140
141void hang (void) __attribute__ ((noreturn));
142
143/* */
144long int initdram (int);
145int display_options (void);
146void print_size (ulong, const char *);
147
148/* common/main.c */
149void main_loop (void);
150int run_command (const char *cmd, int flag);
151int readline (const char *const prompt);
wdenk6dd652f2003-06-19 23:40:20 +0000152void init_cmd_timeout(void);
wdenke2211742002-11-02 23:30:20 +0000153void reset_cmd_timeout(void);
154
wdenk15647dc2003-10-09 19:00:25 +0000155/* lib_$(ARCH)/board.c */
wdenke2211742002-11-02 23:30:20 +0000156void board_init_f (ulong);
157void board_init_r (gd_t *, ulong);
158int checkboard (void);
159int checkflash (void);
160int checkdram (void);
161char * strmhz(char *buf, long hz);
162int last_stage_init(void);
wdenk3b57fe02003-05-30 12:48:29 +0000163extern ulong monitor_flash_len;
wdenke2211742002-11-02 23:30:20 +0000164
165/* common/flash.c */
166void flash_perror (int);
167
wdenkb0fce992003-06-29 21:03:46 +0000168/* common/cmd_autoscript.c */
169int autoscript (ulong addr);
170
wdenke2211742002-11-02 23:30:20 +0000171/* common/cmd_bootm.c */
wdenkb0fce992003-06-29 21:03:46 +0000172void print_image_hdr (image_header_t *hdr);
wdenke2211742002-11-02 23:30:20 +0000173
174extern ulong load_addr; /* Default Load Address */
175
176/* common/cmd_nvedit.c */
177int env_init (void);
178void env_relocate (void);
179char *getenv (uchar *);
180int getenv_r (uchar *name, uchar *buf, unsigned len);
181int saveenv (void);
182#ifdef CONFIG_PPC /* ARM version to be fixed! */
183void inline setenv (char *, char *);
wdenk2262cfe2002-11-18 00:14:45 +0000184#else
185void setenv (char *, char *);
wdenke2211742002-11-02 23:30:20 +0000186#endif /* CONFIG_PPC */
187#ifdef CONFIG_ARM
188# include <asm/u-boot-arm.h> /* ARM version to be fixed! */
189#endif /* CONFIG_ARM */
wdenk2262cfe2002-11-18 00:14:45 +0000190#ifdef CONFIG_I386 /* x86 version to be fixed! */
wdenk8bde7f72003-06-27 21:31:46 +0000191# include <asm/u-boot-i386.h>
wdenk2262cfe2002-11-18 00:14:45 +0000192#endif /* CONFIG_I386 */
wdenke2211742002-11-02 23:30:20 +0000193
194void pci_init (void);
stroesead10dd92003-02-14 11:21:23 +0000195void pci_init_board(void);
wdenke2211742002-11-02 23:30:20 +0000196void pciinfo (int, int);
197
198#if defined(CONFIG_PCI) && defined(CONFIG_440)
199# if defined(CFG_PCI_PRE_INIT)
200 int pci_pre_init (struct pci_controller * );
201# endif
202# if defined(CFG_PCI_TARGET_INIT)
203 void pci_target_init (struct pci_controller *);
204# endif
205# if defined(CFG_PCI_MASTER_INIT)
206 void pci_master_init (struct pci_controller *);
207# endif
208 int is_pci_host (struct pci_controller *);
209#endif
210
211int misc_init_f (void);
212int misc_init_r (void);
213
wdenk27b207f2003-07-24 23:38:38 +0000214/* common/exports.c */
215void jumptable_init(void);
216
wdenke2211742002-11-02 23:30:20 +0000217/* $(BOARD)/$(BOARD).c */
218void reset_phy (void);
wdenk7f6c2cb2002-11-10 22:06:23 +0000219void fdc_hw_init (void);
wdenke2211742002-11-02 23:30:20 +0000220
221/* $(BOARD)/eeprom.c */
222void eeprom_init (void);
wdenk6dd652f2003-06-19 23:40:20 +0000223#ifndef CONFIG_SPI
224int eeprom_probe (unsigned dev_addr, unsigned offset);
225#endif
wdenke2211742002-11-02 23:30:20 +0000226int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
227int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
228#ifdef CONFIG_LWMON
229extern uchar pic_read (uchar reg);
230extern void pic_write (uchar reg, uchar val);
231#endif
232
233/*
234 * Set this up regardless of board
235 * type, to prevent errors.
236 */
237#if defined(CONFIG_SPI) || !defined(CFG_I2C_EEPROM_ADDR)
238# define CFG_DEF_EEPROM_ADDR 0
239#else
240# define CFG_DEF_EEPROM_ADDR CFG_I2C_EEPROM_ADDR
241#endif /* CONFIG_SPI || !defined(CFG_I2C_EEPROM_ADDR) */
242
wdenkbdccc4f2003-08-05 17:43:17 +0000243#if defined(CONFIG_SPI)
wdenke2211742002-11-02 23:30:20 +0000244extern void spi_init_f (void);
245extern void spi_init_r (void);
246extern ssize_t spi_read (uchar *, int, uchar *, int);
247extern ssize_t spi_write (uchar *, int, uchar *, int);
248#endif
249
250#ifdef CONFIG_RPXCLASSIC
251void rpxclassic_init (void);
252#endif
253
254#ifdef CONFIG_MBX
255/* $(BOARD)/mbx8xx.c */
256void mbx_init (void);
257void board_serial_init (void);
258void board_ether_init (void);
259#endif
260
261#if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_MBX) || defined(CONFIG_IAD210)
262void board_get_enetaddr (uchar *addr);
263#endif
264
265#ifdef CONFIG_HERMES
266/* $(BOARD)/hermes.c */
267void hermes_start_lxt980 (int speed);
268#endif
269
270#ifdef CONFIG_EVB64260
271void evb64260_init(void);
272void debug_led(int, int);
273void display_mem_map(void);
274void perform_soft_reset(void);
275#endif
276
277void load_sernum_ethaddr (void);
278
279/* $(BOARD)/$(BOARD).c */
280int board_pre_init (void);
wdenk71f95112003-06-15 22:40:42 +0000281int board_post_init (void);
wdenke2211742002-11-02 23:30:20 +0000282int board_postclk_init (void); /* after clocks/timebase, before env/serial */
283void board_poweroff (void);
284
285#if defined(CFG_DRAM_TEST)
286int testdram(void);
287#endif /* CFG_DRAM_TEST */
288
289/* $(CPU)/start.S */
wdenk0db5bca2003-03-31 17:27:09 +0000290#if defined(CONFIG_5xx) || \
291 defined(CONFIG_8xx)
wdenke2211742002-11-02 23:30:20 +0000292uint get_immr (uint);
293#endif
wdenk42d1f032003-10-15 23:53:47 +0000294uint get_pir (void);
wdenke2211742002-11-02 23:30:20 +0000295uint get_pvr (void);
296uint rd_ic_cst (void);
297void wr_ic_cst (uint);
298void wr_ic_adr (uint);
299uint rd_dc_cst (void);
300void wr_dc_cst (uint);
301void wr_dc_adr (uint);
302int icache_status (void);
303void icache_enable (void);
304void icache_disable(void);
305int dcache_status (void);
306void dcache_enable (void);
307void dcache_disable(void);
308void relocate_code (ulong, gd_t *, ulong);
309ulong get_endaddr (void);
310void trap_init (ulong);
311#if defined (CONFIG_4xx) || \
312 defined (CONFIG_74xx_7xx) || \
313 defined (CONFIG_74x) || \
314 defined (CONFIG_75x) || \
315 defined (CONFIG_74xx)
316unsigned char in8(unsigned int);
317void out8(unsigned int, unsigned char);
318unsigned short in16(unsigned int);
319unsigned short in16r(unsigned int);
320void out16(unsigned int, unsigned short value);
321void out16r(unsigned int, unsigned short value);
322unsigned long in32(unsigned int);
323unsigned long in32r(unsigned int);
324void out32(unsigned int, unsigned long value);
325void out32r(unsigned int, unsigned long value);
326void ppcDcbf(unsigned long value);
327void ppcDcbi(unsigned long value);
328void ppcSync(void);
329#endif
330
331/* $(CPU)/cpu.c */
332int checkcpu (void);
333int checkicache (void);
334int checkdcache (void);
335void upmconfig (unsigned int, unsigned int *, unsigned int);
336ulong get_tbclk (void);
337
338/* $(CPU)/serial.c */
339int serial_init (void);
340void serial_setbrg (void);
341void serial_putc (const char);
342void serial_puts (const char *);
343void serial_addr (unsigned int);
344int serial_getc (void);
345int serial_tstc (void);
346
347/* $(CPU)/speed.c */
348int get_clocks (void);
349#if defined(CONFIG_8260)
350int prt_8260_clks (void);
351#endif
wdenk945af8d2003-07-16 21:53:01 +0000352#if defined(CONFIG_MPC5XXX)
353int prt_mpc5xxx_clks (void);
354#endif
wdenke2211742002-11-02 23:30:20 +0000355#ifdef CONFIG_4xx
356ulong get_OPB_freq (void);
357ulong get_PCI_freq (void);
358#endif
359#if defined(CONFIG_S3C2400) || defined(CONFIG_S3C2410)
360ulong get_FCLK (void);
361ulong get_HCLK (void);
362ulong get_PCLK (void);
363ulong get_UCLK (void);
364#endif
wdenk7cb22f92003-12-27 19:24:54 +0000365#if defined CONFIG_INCA_IP
366uint incaip_get_cpuclk (void);
367#endif
wdenke2211742002-11-02 23:30:20 +0000368ulong get_bus_freq (ulong);
369
wdenk42d1f032003-10-15 23:53:47 +0000370#if defined(CONFIG_MPC85xx)
371typedef MPC85xx_SYS_INFO sys_info_t;
372void get_sys_info ( sys_info_t * );
373#endif
374
wdenke2211742002-11-02 23:30:20 +0000375#if defined(CONFIG_4xx) || defined(CONFIG_IOP480)
376# if defined(CONFIG_440)
377 typedef PPC440_SYS_INFO sys_info_t;
378# else
379 typedef PPC405_SYS_INFO sys_info_t;
380# endif
381void get_sys_info ( sys_info_t * );
382#endif
383
384/* $(CPU)/cpu_init.c */
385#if defined(CONFIG_8xx) || defined(CONFIG_8260)
386void cpu_init_f (volatile immap_t *immr);
387#endif
wdenk42d1f032003-10-15 23:53:47 +0000388#if defined(CONFIG_4xx) || defined(CONFIG_MPC85xx)
wdenke2211742002-11-02 23:30:20 +0000389void cpu_init_f (void);
390#endif
391int cpu_init_r (void);
392#if defined(CONFIG_8260)
393int prt_8260_rsr (void);
394#endif
395
396/* $(CPU)/interrupts.c */
397int interrupt_init (void);
398void timer_interrupt (struct pt_regs *);
399void external_interrupt (struct pt_regs *);
400void irq_install_handler(int, interrupt_handler_t *, void *);
401void irq_free_handler (int);
402void reset_timer (void);
403ulong get_timer (ulong base);
404void set_timer (ulong t);
405void enable_interrupts (void);
406int disable_interrupts (void);
407
408/* $(CPU)/.../commproc.c */
409int dpram_init (void);
410uint dpram_base(void);
411uint dpram_base_align(uint align);
412uint dpram_alloc(uint size);
413uint dpram_alloc_align(uint size,uint align);
414void post_word_store (ulong);
415ulong post_word_load (void);
wdenkbdccc4f2003-08-05 17:43:17 +0000416void bootcount_store (ulong);
417ulong bootcount_load (void);
418#define BOOTCOUNT_MAGIC 0xB001C041
wdenke2211742002-11-02 23:30:20 +0000419
420/* $(CPU)/.../<eth> */
421void mii_init (void);
422
423/* $(CPU)/.../lcd.c */
424ulong lcd_setmem (ulong);
425
426/* $(CPU)/.../vfd.c */
427ulong vfd_setmem (ulong);
428
429/* $(CPU)/.../video.c */
430ulong video_setmem (ulong);
431
432/* ppc/cache.c */
433void flush_cache (unsigned long, unsigned long);
434
wdenk0db5bca2003-03-31 17:27:09 +0000435
wdenk15647dc2003-10-09 19:00:25 +0000436/* lib_$(ARCH)/ticks.S */
wdenke2211742002-11-02 23:30:20 +0000437unsigned long long get_ticks(void);
438void wait_ticks (unsigned long);
439
wdenk15647dc2003-10-09 19:00:25 +0000440/* lib_$(ARCH)/time.c */
wdenke2211742002-11-02 23:30:20 +0000441void udelay (unsigned long);
442ulong usec2ticks (unsigned long usec);
443ulong ticks2usec (unsigned long ticks);
444int init_timebase (void);
445
wdenk15647dc2003-10-09 19:00:25 +0000446/* lib_generic/vsprintf.c */
wdenke2211742002-11-02 23:30:20 +0000447ulong simple_strtoul(const char *cp,char **endp,unsigned int base);
448long simple_strtol(const char *cp,char **endp,unsigned int base);
449void panic(const char *fmt, ...);
450int sprintf(char * buf, const char *fmt, ...);
451int vsprintf(char *buf, const char *fmt, va_list args);
452
wdenk15647dc2003-10-09 19:00:25 +0000453/* lib_generic/crc32.c */
wdenke2211742002-11-02 23:30:20 +0000454ulong crc32 (ulong, const unsigned char *, uint);
455ulong crc32_no_comp (ulong, const unsigned char *, uint);
456
457/* common/console.c */
wdenke2211742002-11-02 23:30:20 +0000458int console_init_f(void); /* Before relocation; uses the serial stuff */
459int console_init_r(void); /* After relocation; uses the console stuff */
460int console_assign (int file, char *devname); /* Assign the console */
461int ctrlc (void);
462int had_ctrlc (void); /* have we had a Control-C since last clear? */
463void clear_ctrlc (void); /* clear the Control-C condition */
464int disable_ctrlc (int); /* 1 to disable, 0 to enable Control-C detect */
465
466/*
467 * STDIO based functions (can always be used)
468 */
469
470/* serial stuff */
471void serial_printf (const char *fmt, ...);
472
473/* stdin */
474int getc(void);
475int tstc(void);
476
477/* stdout */
478void putc(const char c);
479void puts(const char *s);
480void printf(const char *fmt, ...);
wdenk6dd652f2003-06-19 23:40:20 +0000481void vprintf(const char *fmt, va_list args);
wdenke2211742002-11-02 23:30:20 +0000482
483/* stderr */
484#define eputc(c) fputc(stderr, c)
485#define eputs(s) fputs(stderr, s)
486#define eprintf(fmt,args...) fprintf(stderr,fmt ,##args)
487
488/*
489 * FILE based functions (can only be used AFTER relocation!)
490 */
491
492#define stdin 0
493#define stdout 1
494#define stderr 2
495#define MAX_FILES 3
496
497void fprintf(int file, const char *fmt, ...);
498void fputs(int file, const char *s);
499void fputc(int file, const char c);
500int ftstc(int file);
501int fgetc(int file);
502
503int pcmcia_init (void);
504
505#ifdef CONFIG_SHOW_BOOT_PROGRESS
506void show_boot_progress (int status);
507#endif
508
509#endif /* __COMMON_H_ */