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/export.h>
  25. #include <linux/string.h>
  26. #include <linux/io.h>
  27. #include <asm/bootinfo.h>
  28. #include <asm/setup.h>
  29. #include <asm/mach-ar7/ar7.h>
  30. #include <asm/mach-ar7/prom.h>
  31. #define MAX_ENTRY 80
  32. struct env_var {
  33. char *name;
  34. char *value;
  35. };
  36. static struct env_var adam2_env[MAX_ENTRY];
  37. char *prom_getenv(const char *name)
  38. {
  39. int i;
  40. for (i = 0; (i < MAX_ENTRY) && adam2_env[i].name; i++)
  41. if (!strcmp(name, adam2_env[i].name))
  42. return adam2_env[i].value;
  43. return NULL;
  44. }
  45. EXPORT_SYMBOL(prom_getenv);
  46. static void __init ar7_init_cmdline(int argc, char *argv[])
  47. {
  48. int i;
  49. for (i = 1; i < argc; i++) {
  50. strlcat(arcs_cmdline, argv[i], COMMAND_LINE_SIZE);
  51. if (i < (argc - 1))
  52. strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
  53. }
  54. }
  55. struct psbl_rec {
  56. u32 psbl_size;
  57. u32 env_base;
  58. u32 env_size;
  59. u32 ffs_base;
  60. u32 ffs_size;
  61. };
  62. static const char psp_env_version[] __initconst = "TIENV0.8";
  63. struct psp_env_chunk {
  64. u8 num;
  65. u8 ctrl;
  66. u16 csum;
  67. u8 len;
  68. char data[11];
  69. } __packed;
  70. struct psp_var_map_entry {
  71. u8 num;
  72. char *value;
  73. };
  74. static const struct psp_var_map_entry psp_var_map[] = {
  75. { 1, "cpufrequency" },
  76. { 2, "memsize" },
  77. { 3, "flashsize" },
  78. { 4, "modetty0" },
  79. { 5, "modetty1" },
  80. { 8, "maca" },
  81. { 9, "macb" },
  82. { 28, "sysfrequency" },
  83. { 38, "mipsfrequency" },
  84. };
  85. /*
  86. Well-known variable (num is looked up in table above for matching variable name)
  87. Example: cpufrequency=211968000
  88. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  89. | 01 |CTRL|CHECKSUM | 01 | _2 | _1 | _1 | _9 | _6 | _8 | _0 | _0 | _0 | \0 | FF
  90. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  91. Name=Value pair in a single chunk
  92. Example: NAME=VALUE
  93. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  94. | 00 |CTRL|CHECKSUM | 01 | _N | _A | _M | _E | _0 | _V | _A | _L | _U | _E | \0
  95. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  96. Name=Value pair in 2 chunks (len is the number of chunks)
  97. Example: bootloaderVersion=1.3.7.15
  98. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  99. | 00 |CTRL|CHECKSUM | 02 | _b | _o | _o | _t | _l | _o | _a | _d | _e | _r | _V
  100. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  101. | _e | _r | _s | _i | _o | _n | \0 | _1 | _. | _3 | _. | _7 | _. | _1 | _5 | \0
  102. +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
  103. Data is padded with 0xFF
  104. */
  105. #define PSP_ENV_SIZE 4096
  106. static char psp_env_data[PSP_ENV_SIZE] = { 0, };
  107. static char * __init lookup_psp_var_map(u8 num)
  108. {
  109. int i;
  110. for (i = 0; i < ARRAY_SIZE(psp_var_map); i++)
  111. if (psp_var_map[i].num == num)
  112. return psp_var_map[i].value;
  113. return NULL;
  114. }
  115. static void __init add_adam2_var(char *name, char *value)
  116. {
  117. int i;
  118. for (i = 0; i < MAX_ENTRY; i++) {
  119. if (!adam2_env[i].name) {
  120. adam2_env[i].name = name;
  121. adam2_env[i].value = value;
  122. return;
  123. } else if (!strcmp(adam2_env[i].name, name)) {
  124. adam2_env[i].value = value;
  125. return;
  126. }
  127. }
  128. }
  129. static int __init parse_psp_env(void *psp_env_base)
  130. {
  131. int i, n;
  132. char *name, *value;
  133. struct psp_env_chunk *chunks = (struct psp_env_chunk *)psp_env_data;
  134. memcpy_fromio(chunks, psp_env_base, PSP_ENV_SIZE);
  135. i = 1;
  136. n = PSP_ENV_SIZE / sizeof(struct psp_env_chunk);
  137. while (i < n) {
  138. if ((chunks[i].num == 0xff) || ((i + chunks[i].len) > n))
  139. break;
  140. value = chunks[i].data;
  141. if (chunks[i].num) {
  142. name = lookup_psp_var_map(chunks[i].num);
  143. } else {
  144. name = value;
  145. value += strlen(name) + 1;
  146. }
  147. if (name)
  148. add_adam2_var(name, value);
  149. i += chunks[i].len;
  150. }
  151. return 0;
  152. }
  153. static void __init ar7_init_env(struct env_var *env)
  154. {
  155. int i;
  156. struct psbl_rec *psbl = (struct psbl_rec *)(KSEG1ADDR(0x14000300));
  157. void *psp_env = (void *)KSEG1ADDR(psbl->env_base);
  158. if (strcmp(psp_env, psp_env_version) == 0) {
  159. parse_psp_env(psp_env);
  160. } else {
  161. for (i = 0; i < MAX_ENTRY; i++, env++)
  162. if (env->name)
  163. add_adam2_var(env->name, env->value);
  164. }
  165. }
  166. static void __init console_config(void)
  167. {
  168. #ifdef CONFIG_SERIAL_8250_CONSOLE
  169. char console_string[40];
  170. int baud = 0;
  171. char parity = '\0', bits = '\0', flow = '\0';
  172. char *s, *p;
  173. if (strstr(arcs_cmdline, "console="))
  174. return;
  175. s = prom_getenv("modetty0");
  176. if (s) {
  177. baud = simple_strtoul(s, &p, 10);
  178. s = p;
  179. if (*s == ',')
  180. s++;
  181. if (*s)
  182. parity = *s++;
  183. if (*s == ',')
  184. s++;
  185. if (*s)
  186. bits = *s++;
  187. if (*s == ',')
  188. s++;
  189. if (*s == 'h')
  190. flow = 'r';
  191. }
  192. if (baud == 0)
  193. baud = 38400;
  194. if (parity != 'n' && parity != 'o' && parity != 'e')
  195. parity = 'n';
  196. if (bits != '7' && bits != '8')
  197. bits = '8';
  198. if (flow == 'r')
  199. sprintf(console_string, " console=ttyS0,%d%c%c%c", baud,
  200. parity, bits, flow);
  201. else
  202. sprintf(console_string, " console=ttyS0,%d%c%c", baud, parity,
  203. bits);
  204. strlcat(arcs_cmdline, console_string, COMMAND_LINE_SIZE);
  205. #endif
  206. }
  207. void __init prom_init(void)
  208. {
  209. ar7_init_cmdline(fw_arg0, (char **)fw_arg1);
  210. ar7_init_env((struct env_var *)fw_arg2);
  211. console_config();
  212. }
  213. #define PORT(offset) (KSEG1ADDR(AR7_REGS_UART0 + (offset * 4)))
  214. static inline unsigned int serial_in(int offset)
  215. {
  216. return readl((void *)PORT(offset));
  217. }
  218. static inline void serial_out(int offset, int value)
  219. {
  220. writel(value, (void *)PORT(offset));
  221. }
  222. void prom_putchar(char c)
  223. {
  224. while ((serial_in(UART_LSR) & UART_LSR_TEMT) == 0)
  225. ;
  226. serial_out(UART_TX, c);
  227. }