xref: /openbmc/u-boot/include/common.h (revision 2b208f53)
1 /*
2  * (C) Copyright 2000-2004
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 #if defined(CONFIG_8xx)
45 #include <asm/8xx_immap.h>
46 #if defined(CONFIG_MPC852)	|| defined(CONFIG_MPC852T)	|| \
47     defined(CONFIG_MPC859)	|| defined(CONFIG_MPC859T)	|| \
48     defined(CONFIG_MPC859DSL)	|| \
49     defined(CONFIG_MPC866)	|| defined(CONFIG_MPC866T)	|| \
50     defined(CONFIG_MPC866P)
51 # define CONFIG_MPC866_FAMILY 1
52 #elif defined(CONFIG_MPC870) \
53    || defined(CONFIG_MPC875) \
54    || defined(CONFIG_MPC880) \
55    || defined(CONFIG_MPC885)
56 # define CONFIG_MPC885_FAMILY   1
57 #endif
58 #if   defined(CONFIG_MPC860)	   \
59    || defined(CONFIG_MPC860T)	   \
60    || defined(CONFIG_MPC866_FAMILY) \
61    || defined(CONFIG_MPC885_FAMILY)
62 # define CONFIG_MPC86x 1
63 #endif
64 #elif defined(CONFIG_5xx)
65 #include <asm/5xx_immap.h>
66 #elif defined(CONFIG_MPC5xxx)
67 #include <mpc5xxx.h>
68 #elif defined(CONFIG_MPC8220)
69 #include <asm/immap_8220.h>
70 #elif defined(CONFIG_8260)
71 #if   defined(CONFIG_MPC8247) \
72    || defined(CONFIG_MPC8248) \
73    || defined(CONFIG_MPC8271) \
74    || defined(CONFIG_MPC8272)
75 #define CONFIG_MPC8272_FAMILY	1
76 #endif
77 #if defined(CONFIG_MPC8272_FAMILY)
78 #define CONFIG_MPC8260	1
79 #endif
80 #include <asm/immap_8260.h>
81 #endif
82 #ifdef CONFIG_MPC85xx
83 #include <mpc85xx.h>
84 #include <asm/immap_85xx.h>
85 #endif
86 #ifdef CONFIG_MPC83XX
87 #include <mpc83xx.h>
88 #include <asm/immap_83xx.h>
89 #endif
90 #ifdef	CONFIG_4xx
91 #include <ppc4xx.h>
92 #endif
93 #ifdef CONFIG_HYMOD
94 #include <board/hymod/hymod.h>
95 #endif
96 #ifdef CONFIG_ARM
97 #define asmlinkage	/* nothing */
98 #endif
99 
100 #include <part.h>
101 #include <flash.h>
102 #include <image.h>
103 
104 #ifdef	DEBUG
105 #define debug(fmt,args...)	printf (fmt ,##args)
106 #define debugX(level,fmt,args...) if (DEBUG>=level) printf(fmt,##args);
107 #else
108 #define debug(fmt,args...)
109 #define debugX(level,fmt,args...)
110 #endif	/* DEBUG */
111 
112 #define BUG() do { \
113 	printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
114 	panic("BUG!"); \
115 } while (0)
116 #define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
117 
118 typedef void (interrupt_handler_t)(void *);
119 
120 #include <asm/u-boot.h> /* boot information for Linux kernel */
121 #include <asm/global_data.h>	/* global data used for startup functions */
122 
123 /*
124  * enable common handling for all TQM8xxL/M boards:
125  * - CONFIG_TQM8xxM will be defined for all TQM8xxM and TQM885D boards
126  * - CONFIG_TQM8xxL will be defined for all TQM8xxL _and_ TQM8xxM boards
127  */
128 #if defined(CONFIG_TQM823M) || defined(CONFIG_TQM850M) || \
129     defined(CONFIG_TQM855M) || defined(CONFIG_TQM860M) || \
130     defined(CONFIG_TQM862M) || defined(CONFIG_TQM866M) || \
131     defined(CONFIG_TQM885D)
132 # ifndef CONFIG_TQM8xxM
133 #  define CONFIG_TQM8xxM
134 # endif
135 #endif
136 #if defined(CONFIG_TQM823L) || defined(CONFIG_TQM850L) || \
137     defined(CONFIG_TQM855L) || defined(CONFIG_TQM860L) || \
138     defined(CONFIG_TQM862L) || defined(CONFIG_TQM8xxM)
139 # ifndef CONFIG_TQM8xxL
140 #  define CONFIG_TQM8xxL
141 # endif
142 #endif
143 
144 #ifndef CONFIG_SERIAL_MULTI
145 
146 #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2) \
147  || defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) \
148  || defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
149 
150 #define CONFIG_SERIAL_MULTI	1
151 
152 #endif
153 
154 #endif /* CONFIG_SERIAL_MULTI */
155 
156 /*
157  * General Purpose Utilities
158  */
159 #define min(X, Y)				\
160 	({ typeof (X) __x = (X), __y = (Y);	\
161 		(__x < __y) ? __x : __y; })
162 
163 #define max(X, Y)				\
164 	({ typeof (X) __x = (X), __y = (Y);	\
165 		(__x > __y) ? __x : __y; })
166 
167 
168 /*
169  * Function Prototypes
170  */
171 
172 #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
173 void	serial_buffered_init (void);
174 void	serial_buffered_putc (const char);
175 void	serial_buffered_puts (const char *);
176 int	serial_buffered_getc (void);
177 int	serial_buffered_tstc (void);
178 #endif /* CONFIG_SERIAL_SOFTWARE_FIFO */
179 
180 void	hang		(void) __attribute__ ((noreturn));
181 
182 /* */
183 long int initdram (int);
184 int	display_options (void);
185 void	print_size (ulong, const char *);
186 
187 /* common/main.c */
188 void	main_loop	(void);
189 int	run_command	(const char *cmd, int flag);
190 int	readline	(const char *const prompt);
191 void	init_cmd_timeout(void);
192 void	reset_cmd_timeout(void);
193 
194 /* lib_$(ARCH)/board.c */
195 void	board_init_f  (ulong);
196 void	board_init_r  (gd_t *, ulong);
197 int	checkboard    (void);
198 int	checkflash    (void);
199 int	checkdram     (void);
200 char *	strmhz(char *buf, long hz);
201 int	last_stage_init(void);
202 extern ulong monitor_flash_len;
203 
204 /* common/flash.c */
205 void flash_perror (int);
206 
207 /* common/cmd_autoscript.c */
208 int	autoscript (ulong addr);
209 
210 /* common/cmd_bootm.c */
211 void	print_image_hdr (image_header_t *hdr);
212 
213 extern ulong load_addr;		/* Default Load Address */
214 
215 /* common/cmd_nvedit.c */
216 int	env_init     (void);
217 void	env_relocate (void);
218 char	*getenv	     (char *);
219 int	getenv_r     (char *name, char *buf, unsigned len);
220 int	saveenv	     (void);
221 #ifdef CONFIG_PPC		/* ARM version to be fixed! */
222 void inline setenv   (char *, char *);
223 #else
224 void	setenv	     (char *, char *);
225 #endif /* CONFIG_PPC */
226 #ifdef CONFIG_ARM
227 # include <asm/mach-types.h>
228 # include <asm/setup.h>
229 # include <asm/u-boot-arm.h>	/* ARM version to be fixed! */
230 #endif /* CONFIG_ARM */
231 #ifdef CONFIG_I386		/* x86 version to be fixed! */
232 # include <asm/u-boot-i386.h>
233 #endif /* CONFIG_I386 */
234 
235 #ifdef CONFIG_AUTO_COMPLETE
236 int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf);
237 #endif
238 
239 void	pci_init      (void);
240 void	pci_init_board(void);
241 void	pciinfo	      (int, int);
242 
243 #if defined(CONFIG_PCI) && defined(CONFIG_440)
244 #   if defined(CFG_PCI_PRE_INIT)
245     int	   pci_pre_init	       (struct pci_controller * );
246 #   endif
247 #   if defined(CFG_PCI_TARGET_INIT)
248 	void	pci_target_init	     (struct pci_controller *);
249 #   endif
250 #   if defined(CFG_PCI_MASTER_INIT)
251 	void	pci_master_init	     (struct pci_controller *);
252 #   endif
253     int	    is_pci_host		(struct pci_controller *);
254 #if defined(CONFIG_440SPE)
255    void pcie_setup_hoses(void);
256 #endif
257 #endif
258 
259 int	misc_init_f   (void);
260 int	misc_init_r   (void);
261 
262 /* common/exports.c */
263 void	jumptable_init(void);
264 
265 /* common/memsize.c */
266 int	get_ram_size  (volatile long *, long);
267 
268 /* $(BOARD)/$(BOARD).c */
269 void	reset_phy     (void);
270 void	fdc_hw_init   (void);
271 
272 /* $(BOARD)/eeprom.c */
273 void eeprom_init  (void);
274 #ifndef CONFIG_SPI
275 int  eeprom_probe (unsigned dev_addr, unsigned offset);
276 #endif
277 int  eeprom_read  (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
278 int  eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
279 #ifdef CONFIG_LWMON
280 extern uchar pic_read  (uchar reg);
281 extern void  pic_write (uchar reg, uchar val);
282 #endif
283 
284 /*
285  * Set this up regardless of board
286  * type, to prevent errors.
287  */
288 #if defined(CONFIG_SPI) || !defined(CFG_I2C_EEPROM_ADDR)
289 # define CFG_DEF_EEPROM_ADDR 0
290 #else
291 # define CFG_DEF_EEPROM_ADDR CFG_I2C_EEPROM_ADDR
292 #endif /* CONFIG_SPI || !defined(CFG_I2C_EEPROM_ADDR) */
293 
294 #if defined(CONFIG_SPI)
295 extern void spi_init_f (void);
296 extern void spi_init_r (void);
297 extern ssize_t spi_read	 (uchar *, int, uchar *, int);
298 extern ssize_t spi_write (uchar *, int, uchar *, int);
299 #endif
300 
301 #ifdef CONFIG_RPXCLASSIC
302 void rpxclassic_init (void);
303 #endif
304 
305 void rpxlite_init (void);
306 
307 #ifdef CONFIG_MBX
308 /* $(BOARD)/mbx8xx.c */
309 void	mbx_init (void);
310 void	board_serial_init (void);
311 void	board_ether_init (void);
312 #endif
313 
314 #if defined(CONFIG_RPXCLASSIC)	|| defined(CONFIG_MBX) || \
315     defined(CONFIG_IAD210)	|| defined(CONFIG_XPEDITE1K) || \
316     defined(CONFIG_METROBOX)    || defined(CONFIG_KAREF)
317 void	board_get_enetaddr (uchar *addr);
318 #endif
319 
320 #ifdef CONFIG_HERMES
321 /* $(BOARD)/hermes.c */
322 void hermes_start_lxt980 (int speed);
323 #endif
324 
325 #ifdef CONFIG_EVB64260
326 void  evb64260_init(void);
327 void  debug_led(int, int);
328 void  display_mem_map(void);
329 void  perform_soft_reset(void);
330 #endif
331 
332 void	load_sernum_ethaddr (void);
333 
334 /* $(BOARD)/$(BOARD).c */
335 int board_early_init_f (void);
336 int board_late_init (void);
337 int board_postclk_init (void); /* after clocks/timebase, before env/serial */
338 int board_early_init_r (void);
339 void board_poweroff (void);
340 
341 #if defined(CFG_DRAM_TEST)
342 int testdram(void);
343 #endif /* CFG_DRAM_TEST */
344 
345 /* $(CPU)/start.S */
346 #if defined(CONFIG_5xx) || \
347     defined(CONFIG_8xx)
348 uint	get_immr      (uint);
349 #endif
350 uint	get_pir	      (void);
351 #if defined(CONFIG_MPC5xxx)
352 uint	get_svr       (void);
353 #endif
354 uint	get_pvr	      (void);
355 uint	get_svr	      (void);
356 uint	rd_ic_cst     (void);
357 void	wr_ic_cst     (uint);
358 void	wr_ic_adr     (uint);
359 uint	rd_dc_cst     (void);
360 void	wr_dc_cst     (uint);
361 void	wr_dc_adr     (uint);
362 int	icache_status (void);
363 void	icache_enable (void);
364 void	icache_disable(void);
365 int	dcache_status (void);
366 void	dcache_enable (void);
367 void	dcache_disable(void);
368 void	relocate_code (ulong, gd_t *, ulong);
369 ulong	get_endaddr   (void);
370 void	trap_init     (ulong);
371 #if defined (CONFIG_4xx)	|| \
372     defined (CONFIG_MPC5xxx)	|| \
373     defined (CONFIG_74xx_7xx)	|| \
374     defined (CONFIG_74x)	|| \
375     defined (CONFIG_75x)	|| \
376     defined (CONFIG_74xx)	|| \
377     defined (CONFIG_MPC8220)	|| \
378     defined (CONFIG_MPC85xx)	|| \
379     defined (CONFIG_MPC83XX)
380 unsigned char	in8(unsigned int);
381 void		out8(unsigned int, unsigned char);
382 unsigned short	in16(unsigned int);
383 unsigned short	in16r(unsigned int);
384 void		out16(unsigned int, unsigned short value);
385 void		out16r(unsigned int, unsigned short value);
386 unsigned long	in32(unsigned int);
387 unsigned long	in32r(unsigned int);
388 void		out32(unsigned int, unsigned long value);
389 void		out32r(unsigned int, unsigned long value);
390 void		ppcDcbf(unsigned long value);
391 void		ppcDcbi(unsigned long value);
392 void		ppcSync(void);
393 void		ppcDcbz(unsigned long value);
394 #endif
395 
396 /* $(CPU)/cpu.c */
397 int	checkcpu      (void);
398 int	checkicache   (void);
399 int	checkdcache   (void);
400 void	upmconfig     (unsigned int, unsigned int *, unsigned int);
401 ulong	get_tbclk     (void);
402 void	reset_cpu     (ulong addr);
403 
404 /* $(CPU)/serial.c */
405 int	serial_init   (void);
406 void	serial_addr   (unsigned int);
407 void	serial_setbrg (void);
408 void	serial_putc   (const char);
409 void	serial_putc_raw(const char);
410 void	serial_puts   (const char *);
411 int	serial_getc   (void);
412 int	serial_tstc   (void);
413 
414 void	_serial_setbrg (const int);
415 void	_serial_putc   (const char, const int);
416 void	_serial_putc_raw(const char, const int);
417 void	_serial_puts   (const char *, const int);
418 int	_serial_getc   (const int);
419 int	_serial_tstc   (const int);
420 
421 /* $(CPU)/speed.c */
422 int	get_clocks (void);
423 int	get_clocks_866 (void);
424 int	sdram_adjust_866 (void);
425 int	adjust_sdram_tbs_8xx (void);
426 #if defined(CONFIG_8260)
427 int	prt_8260_clks (void);
428 #elif defined(CONFIG_MPC83XX)
429 int print_clock_conf(void);
430 #elif defined(CONFIG_MPC5xxx)
431 int	prt_mpc5xxx_clks (void);
432 #endif
433 #if defined(CONFIG_MPC8220)
434 int	prt_mpc8220_clks (void);
435 #endif
436 #ifdef CONFIG_4xx
437 ulong	get_OPB_freq (void);
438 ulong	get_PCI_freq (void);
439 #endif
440 #if defined(CONFIG_S3C2400) || defined(CONFIG_S3C2410) || defined(CONFIG_LH7A40X)
441 ulong	get_FCLK (void);
442 ulong	get_HCLK (void);
443 ulong	get_PCLK (void);
444 ulong	get_UCLK (void);
445 #endif
446 #if defined(CONFIG_LH7A40X)
447 ulong	get_PLLCLK (void);
448 #endif
449 #if defined CONFIG_INCA_IP
450 uint	incaip_get_cpuclk (void);
451 #endif
452 #if defined(CONFIG_IMX)
453 ulong get_systemPLLCLK(void);
454 ulong get_FCLK(void);
455 ulong get_HCLK(void);
456 ulong get_BCLK(void);
457 ulong get_PERCLK1(void);
458 ulong get_PERCLK2(void);
459 ulong get_PERCLK3(void);
460 #endif
461 ulong	get_bus_freq  (ulong);
462 
463 #if defined(CONFIG_MPC85xx)
464 typedef MPC85xx_SYS_INFO sys_info_t;
465 void	get_sys_info  ( sys_info_t * );
466 #endif
467 
468 #if defined(CONFIG_4xx) || defined(CONFIG_IOP480)
469 #  if defined(CONFIG_440)
470     typedef PPC440_SYS_INFO sys_info_t;
471 #	if defined(CONFIG_440SPE)
472 	 unsigned long determine_sysper(void);
473 	 unsigned long determine_pci_clock_per(void);
474 	 int ppc440spe_revB(void);
475 #	endif
476 #  else
477     typedef PPC405_SYS_INFO sys_info_t;
478 #  endif
479 void	get_sys_info  ( sys_info_t * );
480 #endif
481 
482 /* $(CPU)/cpu_init.c */
483 #if defined(CONFIG_8xx) || defined(CONFIG_8260)
484 void	cpu_init_f    (volatile immap_t *immr);
485 #endif
486 #if defined(CONFIG_4xx) || defined(CONFIG_MPC85xx) || defined(CONFIG_MCF52x2)
487 void	cpu_init_f    (void);
488 #endif
489 
490 int	cpu_init_r    (void);
491 #if defined(CONFIG_8260)
492 int	prt_8260_rsr  (void);
493 #endif
494 
495 /* $(CPU)/interrupts.c */
496 int	interrupt_init	   (void);
497 void	timer_interrupt	   (struct pt_regs *);
498 void	external_interrupt (struct pt_regs *);
499 void	irq_install_handler(int, interrupt_handler_t *, void *);
500 void	irq_free_handler   (int);
501 void	reset_timer	   (void);
502 ulong	get_timer	   (ulong base);
503 void	set_timer	   (ulong t);
504 void	enable_interrupts  (void);
505 int	disable_interrupts (void);
506 
507 /* $(CPU)/.../commproc.c */
508 int	dpram_init (void);
509 uint	dpram_base(void);
510 uint	dpram_base_align(uint align);
511 uint	dpram_alloc(uint size);
512 uint	dpram_alloc_align(uint size,uint align);
513 void	post_word_store (ulong);
514 ulong	post_word_load (void);
515 void	bootcount_store (ulong);
516 ulong	bootcount_load (void);
517 #define BOOTCOUNT_MAGIC		0xB001C041
518 
519 /* $(CPU)/.../<eth> */
520 void mii_init (void);
521 
522 /* $(CPU)/.../lcd.c */
523 ulong	lcd_setmem (ulong);
524 
525 /* $(CPU)/.../vfd.c */
526 ulong	vfd_setmem (ulong);
527 
528 /* $(CPU)/.../video.c */
529 ulong	video_setmem (ulong);
530 
531 /* lib_$(ARCH)/cache.c */
532 void	flush_cache   (unsigned long, unsigned long);
533 
534 
535 /* lib_$(ARCH)/ticks.S */
536 unsigned long long get_ticks(void);
537 void	wait_ticks    (unsigned long);
538 
539 /* lib_$(ARCH)/time.c */
540 void	udelay	      (unsigned long);
541 ulong	usec2ticks    (unsigned long usec);
542 ulong	ticks2usec    (unsigned long ticks);
543 int	init_timebase (void);
544 
545 /* lib_generic/vsprintf.c */
546 ulong	simple_strtoul(const char *cp,char **endp,unsigned int base);
547 #ifdef CFG_64BIT_VSPRINTF
548 unsigned long long	simple_strtoull(const char *cp,char **endp,unsigned int base);
549 #endif
550 long	simple_strtol(const char *cp,char **endp,unsigned int base);
551 void	panic(const char *fmt, ...);
552 int	sprintf(char * buf, const char *fmt, ...);
553 int	vsprintf(char *buf, const char *fmt, va_list args);
554 
555 /* lib_generic/crc32.c */
556 ulong crc32 (ulong, const unsigned char *, uint);
557 ulong crc32_no_comp (ulong, const unsigned char *, uint);
558 
559 /* common/console.c */
560 int	console_init_f(void);	/* Before relocation; uses the serial  stuff	*/
561 int	console_init_r(void);	/* After  relocation; uses the console stuff	*/
562 int	console_assign (int file, char *devname);	/* Assign the console	*/
563 int	ctrlc (void);
564 int	had_ctrlc (void);	/* have we had a Control-C since last clear? */
565 void	clear_ctrlc (void);	/* clear the Control-C condition */
566 int	disable_ctrlc (int);	/* 1 to disable, 0 to enable Control-C detect */
567 
568 /*
569  * STDIO based functions (can always be used)
570  */
571 
572 /* serial stuff */
573 void	serial_printf (const char *fmt, ...);
574 
575 /* stdin */
576 int	getc(void);
577 int	tstc(void);
578 
579 /* stdout */
580 void	putc(const char c);
581 void	puts(const char *s);
582 void	printf(const char *fmt, ...);
583 void	vprintf(const char *fmt, va_list args);
584 
585 /* stderr */
586 #define eputc(c)		fputc(stderr, c)
587 #define eputs(s)		fputs(stderr, s)
588 #define eprintf(fmt,args...)	fprintf(stderr,fmt ,##args)
589 
590 /*
591  * FILE based functions (can only be used AFTER relocation!)
592  */
593 
594 #define stdin		0
595 #define stdout		1
596 #define stderr		2
597 #define MAX_FILES	3
598 
599 void	fprintf(int file, const char *fmt, ...);
600 void	fputs(int file, const char *s);
601 void	fputc(int file, const char c);
602 int	ftstc(int file);
603 int	fgetc(int file);
604 
605 int	pcmcia_init (void);
606 
607 #ifdef CONFIG_SHOW_BOOT_PROGRESS
608 void	show_boot_progress (int status);
609 #endif
610 
611 #ifdef CONFIG_INIT_CRITICAL
612 #error CONFIG_INIT_CRITICAL is deprecated!
613 #error Read section CONFIG_SKIP_LOWLEVEL_INIT in README.
614 #endif
615 
616 #endif	/* __COMMON_H_ */
617