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