prom.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  4. *
  5. * This program is free software; you can distribute it and/or modify it
  6. * under the terms of the GNU General Public License (Version 2) as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  17. *
  18. * Putting things on the screen/serial line using YAMONs facilities.
  19. */
  20. #include <linux/init.h>
  21. #include <linux/kernel.h>
  22. #include <linux/serial_reg.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/module.h>
  25. #include <linux/string.h>
  26. #include <linux/io.h>
  27. #include <asm/bootinfo.h>
  28. #include <asm/mach-ar7/ar7.h>
  29. #include <asm/mach-ar7/prom.h>
  30. #define MAX_ENTRY 80
  31. struct env_var {
  32. char *name;
  33. char *value;
  34. };
  35. static struct env_var adam2_env[MAX_ENTRY];
  36. char *prom_getenv(const char *name)
  37. {
  38. int i;
  39. for (i = 0; (i < MAX_ENTRY) && adam2_env[i].name; i++)
  40. if (!strcmp(name, adam2_env[i].name))
  41. return adam2_env[i].value;
  42. return NULL;
  43. }
  44. EXPORT_SYMBOL(prom_getenv);
  45. static void __init ar7_init_cmdline(int argc, char *argv[])
  46. {
  47. int i;
  48. for (i = 1; i < argc; i++) {
  49. strlcat(arcs_cmdline, argv[i], COMMAND_LINE_SIZE);
  50. if (i < (argc - 1))
  51. strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
  52. }
  53. }
  54. struct psbl_rec {
  55. u32 psbl_size;
  56. u32 env_base;
  57. u32 env_size;
  58. u32 ffs_base;
  59. u32 ffs_size;
  60. };
  61. static const char psp_env_version[] __initconst = "TIENV0.8";
  62. struct psp_env_chunk {
  63. u8 num;
  64. u8 ctrl;
  65. u16 csum;
  66. u8 len;
  67. char data[11];
  68. } __packed;
  69. struct psp_var_map_entry {
  70. u8 num;
  71. char *value;
  72. };
  73. static const struct psp_var_map_entry psp_var_map[] = {
  74. { 1, "cpufrequency" },
  75. { 2, "memsize" },
  76. { 3, "flashsize" },
  77. { 4, "modetty0" },
  78. { 5, "modetty1" },
  79. { 8, "maca" },
  80. { 9, "macb" },
  81. { 28, "sysfrequency" },
  82. { 38, "mipsfrequency" },
  83. };
  84. /*
  85. Well-known variable (num is looked up in table above for matching variable name)
  86. Example: cpufrequency=211968000
  87. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  88. | 01 |CTRL|CHECKSUM | 01 | _2 | _1 | _1 | _9 | _6 | _8 | _0 | _0 | _0 | \0 | FF
  89. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  90. Name=Value pair in a single chunk
  91. Example: NAME=VALUE
  92. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  93. | 00 |CTRL|CHECKSUM | 01 | _N | _A | _M | _E | _0 | _V | _A | _L | _U | _E | \0
  94. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  95. Name=Value pair in 2 chunks (len is the number of chunks)
  96. Example: bootloaderVersion=1.3.7.15
  97. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  98. | 00 |CTRL|CHECKSUM | 02 | _b | _o | _o | _t | _l | _o | _a | _d | _e | _r | _V
  99. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  100. | _e | _r | _s | _i | _o | _n | \0 | _1 | _. | _3 | _. | _7 | _. | _1 | _5 | \0
  101. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  102. Data is padded with 0xFF
  103. */
  104. #define PSP_ENV_SIZE 4096
  105. static char psp_env_data[PSP_ENV_SIZE] = { 0, };
  106. static char * __init lookup_psp_var_map(u8 num)
  107. {
  108. int i;
  109. for (i = 0; i < ARRAY_SIZE(psp_var_map); i++)
  110. if (psp_var_map[i].num == num)
  111. return psp_var_map[i].value;
  112. return NULL;
  113. }
  114. static void __init add_adam2_var(char *name, char *value)
  115. {
  116. int i;
  117. for (i = 0; i < MAX_ENTRY; i++) {
  118. if (!adam2_env[i].name) {
  119. adam2_env[i].name = name;
  120. adam2_env[i].value = value;
  121. return;
  122. } else if (!strcmp(adam2_env[i].name, name)) {
  123. adam2_env[i].value = value;
  124. return;
  125. }
  126. }
  127. }
  128. static int __init parse_psp_env(void *psp_env_base)
  129. {
  130. int i, n;
  131. char *name, *value;
  132. struct psp_env_chunk *chunks = (struct psp_env_chunk *)psp_env_data;
  133. memcpy_fromio(chunks, psp_env_base, PSP_ENV_SIZE);
  134. i = 1;
  135. n = PSP_ENV_SIZE / sizeof(struct psp_env_chunk);
  136. while (i < n) {
  137. if ((chunks[i].num == 0xff) || ((i + chunks[i].len) > n))
  138. break;
  139. value = chunks[i].data;
  140. if (chunks[i].num) {
  141. name = lookup_psp_var_map(chunks[i].num);
  142. } else {
  143. name = value;
  144. value += strlen(name) + 1;
  145. }
  146. if (name)
  147. add_adam2_var(name, value);
  148. i += chunks[i].len;
  149. }
  150. return 0;
  151. }
  152. static void __init ar7_init_env(struct env_var *env)
  153. {
  154. int i;
  155. struct psbl_rec *psbl = (struct psbl_rec *)(KSEG1ADDR(0x14000300));
  156. void *psp_env = (void *)KSEG1ADDR(psbl->env_base);
  157. if (strcmp(psp_env, psp_env_version) == 0) {
  158. parse_psp_env(psp_env);
  159. } else {
  160. for (i = 0; i < MAX_ENTRY; i++, env++)
  161. if (env->name)
  162. add_adam2_var(env->name, env->value);
  163. }
  164. }
  165. static void __init console_config(void)
  166. {
  167. #ifdef CONFIG_SERIAL_8250_CONSOLE
  168. char console_string[40];
  169. int baud = 0;
  170. char parity = '\0', bits = '\0', flow = '\0';
  171. char *s, *p;
  172. if (strstr(arcs_cmdline, "console="))
  173. return;
  174. s = prom_getenv("modetty0");
  175. if (s) {
  176. baud = simple_strtoul(s, &p, 10);
  177. s = p;
  178. if (*s == ',')
  179. s++;
  180. if (*s)
  181. parity = *s++;
  182. if (*s == ',')
  183. s++;
  184. if (*s)
  185. bits = *s++;
  186. if (*s == ',')
  187. s++;
  188. if (*s == 'h')
  189. flow = 'r';
  190. }
  191. if (baud == 0)
  192. baud = 38400;
  193. if (parity != 'n' && parity != 'o' && parity != 'e')
  194. parity = 'n';
  195. if (bits != '7' && bits != '8')
  196. bits = '8';
  197. if (flow == 'r')
  198. sprintf(console_string, " console=ttyS0,%d%c%c%c", baud,
  199. parity, bits, flow);
  200. else
  201. sprintf(console_string, " console=ttyS0,%d%c%c", baud, parity,
  202. bits);
  203. strlcat(arcs_cmdline, console_string, COMMAND_LINE_SIZE);
  204. #endif
  205. }
  206. void __init prom_init(void)
  207. {
  208. ar7_init_cmdline(fw_arg0, (char **)fw_arg1);
  209. ar7_init_env((struct env_var *)fw_arg2);
  210. console_config();
  211. }
  212. #define PORT(offset) (KSEG1ADDR(AR7_REGS_UART0 + (offset * 4)))
  213. static inline unsigned int serial_in(int offset)
  214. {
  215. return readl((void *)PORT(offset));
  216. }
  217. static inline void serial_out(int offset, int value)
  218. {
  219. writel(value, (void *)PORT(offset));
  220. }
  221. int prom_putchar(char c)
  222. {
  223. while ((serial_in(UART_LSR) & UART_LSR_TEMT) == 0)
  224. ;
  225. serial_out(UART_TX, c);
  226. return 1;
  227. }