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