prom.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * RouterBoard 500 specific prom routines
  3. *
  4. * Copyright (C) 2003, Peter Sadik <peter.sadik@idt.com>
  5. * Copyright (C) 2005-2006, P.Christeas <p_christ@hol.gr>
  6. * Copyright (C) 2007, Gabor Juhos <juhosg@openwrt.org>
  7. * Felix Fietkau <nbd@openwrt.org>
  8. * Florian Fainelli <florian@openwrt.org>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the
  22. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  23. * Boston, MA 02110-1301, USA.
  24. *
  25. */
  26. #include <linux/init.h>
  27. #include <linux/mm.h>
  28. #include <linux/module.h>
  29. #include <linux/string.h>
  30. #include <linux/console.h>
  31. #include <linux/bootmem.h>
  32. #include <linux/ioport.h>
  33. #include <linux/blkdev.h>
  34. #include <asm/bootinfo.h>
  35. #include <asm/mach-rc32434/ddr.h>
  36. #include <asm/mach-rc32434/prom.h>
  37. extern void __init setup_serial_port(void);
  38. unsigned int idt_cpu_freq = 132000000;
  39. EXPORT_SYMBOL(idt_cpu_freq);
  40. unsigned int gpio_bootup_state;
  41. EXPORT_SYMBOL(gpio_bootup_state);
  42. static struct resource ddr_reg[] = {
  43. {
  44. .name = "ddr-reg",
  45. .start = DDR0_PHYS_ADDR,
  46. .end = DDR0_PHYS_ADDR + sizeof(struct ddr_ram),
  47. .flags = IORESOURCE_MEM,
  48. }
  49. };
  50. void __init prom_free_prom_memory(void)
  51. {
  52. /* No prom memory to free */
  53. }
  54. static inline int match_tag(char *arg, const char *tag)
  55. {
  56. return strncmp(arg, tag, strlen(tag)) == 0;
  57. }
  58. static inline unsigned long tag2ul(char *arg, const char *tag)
  59. {
  60. char *num;
  61. num = arg + strlen(tag);
  62. return simple_strtoul(num, 0, 10);
  63. }
  64. void __init prom_setup_cmdline(void)
  65. {
  66. char cmd_line[CL_SIZE];
  67. char *cp, *board;
  68. int prom_argc;
  69. char **prom_argv, **prom_envp;
  70. int i;
  71. prom_argc = fw_arg0;
  72. prom_argv = (char **) fw_arg1;
  73. prom_envp = (char **) fw_arg2;
  74. cp = cmd_line;
  75. /* Note: it is common that parameters start
  76. * at argv[1] and not argv[0],
  77. * however, our elf loader starts at [0] */
  78. for (i = 0; i < prom_argc; i++) {
  79. if (match_tag(prom_argv[i], FREQ_TAG)) {
  80. idt_cpu_freq = tag2ul(prom_argv[i], FREQ_TAG);
  81. continue;
  82. }
  83. #ifdef IGNORE_CMDLINE_MEM
  84. /* parses out the "mem=xx" arg */
  85. if (match_tag(prom_argv[i], MEM_TAG))
  86. continue;
  87. #endif
  88. if (i > 0)
  89. *(cp++) = ' ';
  90. if (match_tag(prom_argv[i], BOARD_TAG)) {
  91. board = prom_argv[i] + strlen(BOARD_TAG);
  92. if (match_tag(board, BOARD_RB532A))
  93. mips_machtype = MACH_MIKROTIK_RB532A;
  94. else
  95. mips_machtype = MACH_MIKROTIK_RB532;
  96. }
  97. if (match_tag(prom_argv[i], GPIO_TAG))
  98. gpio_bootup_state = tag2ul(prom_argv[i], GPIO_TAG);
  99. strcpy(cp, prom_argv[i]);
  100. cp += strlen(prom_argv[i]);
  101. }
  102. *(cp++) = ' ';
  103. i = strlen(arcs_cmdline);
  104. if (i > 0) {
  105. *(cp++) = ' ';
  106. strcpy(cp, arcs_cmdline);
  107. cp += strlen(arcs_cmdline);
  108. }
  109. if (gpio_bootup_state & 0x02)
  110. strcpy(cp, GPIO_INIT_NOBUTTON);
  111. else
  112. strcpy(cp, GPIO_INIT_BUTTON);
  113. cmd_line[CL_SIZE-1] = '\0';
  114. strcpy(arcs_cmdline, cmd_line);
  115. }
  116. void __init prom_init(void)
  117. {
  118. struct ddr_ram __iomem *ddr;
  119. phys_t memsize;
  120. phys_t ddrbase;
  121. ddr = ioremap_nocache(ddr_reg[0].start,
  122. ddr_reg[0].end - ddr_reg[0].start);
  123. if (!ddr) {
  124. printk(KERN_ERR "Unable to remap DDR register\n");
  125. return;
  126. }
  127. ddrbase = (phys_t)&ddr->ddrbase;
  128. memsize = (phys_t)&ddr->ddrmask;
  129. memsize = 0 - memsize;
  130. prom_setup_cmdline();
  131. /* give all RAM to boot allocator,
  132. * except for the first 0x400 and the last 0x200 bytes */
  133. add_memory_region(ddrbase + 0x400, memsize - 0x600, BOOT_MEM_RAM);
  134. }