2 * Copyright (C) 2010 Scott Nicholas <neutronscott@scottn.us>
4 * based on work of rb532 prom.c
5 * Copyright (C) 2003, Peter Sadik <peter.sadik@idt.com>
6 * Copyright (C) 2005-2006, P.Christeas <p_christ@hol.gr>
7 * Copyright (C) 2007, Gabor Juhos <juhosg@openwrt.org>
8 * Felix Fietkau <nbd@openwrt.org>
9 * Florian Fainelli <florian@openwrt.org>
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/types.h>
19 #include <linux/console.h>
20 #include <linux/string.h>
21 #include <linux/serial_core.h>
22 #include <asm/bootinfo.h>
26 register volatile struct global_data *gd asm ("k0");
28 #ifdef CONFIG_SERIAL_ADM8668_CONSOLE
29 static inline unsigned int adm_uart_readl(unsigned int offset)
31 return (*(volatile unsigned int *)(0xbe400000 + offset));
34 static inline void adm_uart_writel(unsigned int value, unsigned int offset)
36 (*((volatile unsigned int *)(0xbe400000 + offset))) = value;
39 static void prom_putchar(char c)
41 adm_uart_writel(c, UART_DR_REG);
42 while ((adm_uart_readl(UART_FR_REG) & UART_TX_FIFO_FULL) != 0)
47 early_console_write(struct console *con, const char *s, unsigned n)
57 static struct console early_console __initdata = {
59 .write = early_console_write,
66 void __init prom_free_prom_memory(void)
68 /* No prom memory to free */
71 static inline int match_tag(char *arg, const char *tag)
73 return strncmp(arg, tag, strlen(tag)) == 0;
76 static inline unsigned long tag2ul(char *arg, const char *tag)
80 num = arg + strlen(tag);
81 return simple_strtoul(num, 0, 10);
84 void __init prom_setup_cmdline(void)
92 prom_argv = (char **)KSEG0ADDR(fw_arg1);
94 cp = &(arcs_cmdline[0]);
95 for (i = 1; i < prom_argc; i++) {
96 prom_argv[i] = (char *)KSEG0ADDR(prom_argv[i]);
98 /* default bootargs has "console=/dev/ttyS0" yet console won't
99 * show up at all if you do this ... */
100 if (match_tag(prom_argv[i], "console=/dev/")) {
101 char *ptr = prom_argv[i] + strlen("console=/dev/");
103 strcpy(cp, "console=");
104 cp += strlen("console=");
110 strcpy(cp, prom_argv[i]);
111 cp += strlen(prom_argv[i]);
115 --cp; /* trailing space */
120 void __init prom_init(void)
125 #ifdef CONFIG_SERIAL_ADM8668_CONSOLE
126 register_console(&early_console);
129 memsize = bd->bi_memsize;
130 printk("Board info:\n");
131 printk(" Board ID: %#lx\n", bd->bi_arch_number);
132 printk(" RAM size: %d MB\n", (int)memsize/(1024*1024));
133 printk(" NOR start: %#lx\n", bd->bi_flashstart);
134 printk(" NOR size: %#lx\n", bd->bi_flashsize);
136 prom_setup_cmdline();
137 add_memory_region(0, memsize, BOOT_MEM_RAM);