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