surprise :p
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / prom.c
1 /*
2 * Atheros AR71xx SoC specific prom routines
3 *
4 * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 */
11
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/io.h>
15 #include <linux/serial_reg.h>
16
17 #include <asm/bootinfo.h>
18 #include <asm/addrspace.h>
19
20 #include <asm/mach-ar71xx/ar71xx.h>
21
22 struct board_rec {
23 char *name;
24 unsigned long mach_type;
25 };
26
27 static int prom_argc __initdata;
28 static char **prom_argv __initdata;
29 static char **prom_envp __initdata;
30
31 static struct board_rec boards[] __initdata = {
32 {
33 .name = "411",
34 .mach_type = MACH_AR71XX_RB_411,
35 }, {
36 .name = "433",
37 .mach_type = MACH_AR71XX_RB_433,
38 }, {
39 .name = "450",
40 .mach_type = MACH_AR71XX_RB_450,
41 }
42 };
43
44 char *(*prom_getenv)(const char *envname) __initdata;
45
46 static __init char *dummy_getenv(const char *envname)
47 {
48 return NULL;
49 }
50
51 static void __init routerboot_printargs(void)
52 {
53 int i;
54
55 for (i = 0; i < prom_argc; i++)
56 printk(KERN_DEBUG "prom: routerboot envp[%d]: %s\n",
57 i, prom_envp[i]);
58 }
59
60 static __init char *routerboot_getenv(const char *envname)
61 {
62 char **env;
63 int i = strlen(envname);
64
65 for (env = prom_envp; *env != NULL; env++)
66 if (strncmp(envname, *env, i) == 0 && (*env)[i] == '=')
67 return *env + i + 1;
68
69 return NULL;
70 }
71
72 static __init unsigned long find_board_byname(char *name)
73 {
74 int i;
75
76 for (i = 0; i < ARRAY_SIZE(boards); i++)
77 if (strcmp(name, boards[i].name) == 0)
78 return boards[i].mach_type;
79
80 return MACH_AR71XX_GENERIC;
81 }
82
83 void __init prom_init(void)
84 {
85 char *board;
86
87 printk(KERN_DEBUG "prom: fw_arg0=%08x, fw_arg1=%08x, "
88 "fw_arg2=%08x, fw_arg3=%08x\n",
89 (unsigned int)fw_arg0, (unsigned int)fw_arg1,
90 (unsigned int)fw_arg2, (unsigned int)fw_arg3);
91
92 prom_getenv = dummy_getenv;
93
94 if ((fw_arg0 == 7) && (fw_arg2 == 0)) {
95 prom_argc = fw_arg0;
96 prom_envp = (char **)fw_arg1;
97 prom_getenv = routerboot_getenv;
98 routerboot_printargs();
99 }
100
101 board = prom_getenv("board");
102 if (board)
103 mips_machtype = find_board_byname(board);
104 else
105 mips_machtype = MACH_AR71XX_GENERIC;
106
107 ar71xx_print_cmdline();
108 }
109
110 void __init prom_free_prom_memory(void)
111 {
112 /* We do not have to prom memory to free */
113 }
114
115 #define UART_READ(r) \
116 __raw_readl((void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4 * (r)))
117
118 #define UART_WRITE(r, v) \
119 __raw_writel((v), (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE) + 4*(r)))
120
121 void prom_putchar(unsigned char ch)
122 {
123 while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);
124 UART_WRITE(UART_TX, ch);
125 while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);
126 }