prom.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. unsigned int idt_cpu_freq = 132000000;
  38. EXPORT_SYMBOL(idt_cpu_freq);
  39. static struct resource ddr_reg[] = {
  40. {
  41. .name = "ddr-reg",
  42. .start = DDR0_PHYS_ADDR,
  43. .end = DDR0_PHYS_ADDR + sizeof(struct ddr_ram),
  44. .flags = IORESOURCE_MEM,
  45. }
  46. };
  47. void __init prom_free_prom_memory(void)
  48. {
  49. /* No prom memory to free */
  50. }
  51. static inline int match_tag(char *arg, const char *tag)
  52. {
  53. return strncmp(arg, tag, strlen(tag)) == 0;
  54. }
  55. static inline unsigned long tag2ul(char *arg, const char *tag)
  56. {
  57. char *num;
  58. num = arg + strlen(tag);
  59. return simple_strtoul(num, 0, 10);
  60. }
  61. void __init prom_setup_cmdline(void)
  62. {
  63. static char cmd_line[COMMAND_LINE_SIZE] __initdata;
  64. char *cp, *board;
  65. int prom_argc;
  66. char **prom_argv;
  67. int i;
  68. prom_argc = fw_arg0;
  69. prom_argv = (char **) fw_arg1;
  70. cp = cmd_line;
  71. /* Note: it is common that parameters start
  72. * at argv[1] and not argv[0],
  73. * however, our elf loader starts at [0] */
  74. for (i = 0; i < prom_argc; i++) {
  75. if (match_tag(prom_argv[i], FREQ_TAG)) {
  76. idt_cpu_freq = tag2ul(prom_argv[i], FREQ_TAG);
  77. continue;
  78. }
  79. #ifdef IGNORE_CMDLINE_MEM
  80. /* parses out the "mem=xx" arg */
  81. if (match_tag(prom_argv[i], MEM_TAG))
  82. continue;
  83. #endif
  84. if (i > 0)
  85. *(cp++) = ' ';
  86. if (match_tag(prom_argv[i], BOARD_TAG)) {
  87. board = prom_argv[i] + strlen(BOARD_TAG);
  88. if (match_tag(board, BOARD_RB532A))
  89. mips_machtype = MACH_MIKROTIK_RB532A;
  90. else
  91. mips_machtype = MACH_MIKROTIK_RB532;
  92. }
  93. strcpy(cp, prom_argv[i]);
  94. cp += strlen(prom_argv[i]);
  95. }
  96. *(cp++) = ' ';
  97. i = strlen(arcs_cmdline);
  98. if (i > 0) {
  99. *(cp++) = ' ';
  100. strcpy(cp, arcs_cmdline);
  101. cp += strlen(arcs_cmdline);
  102. }
  103. cmd_line[COMMAND_LINE_SIZE - 1] = '\0';
  104. strcpy(arcs_cmdline, cmd_line);
  105. }
  106. void __init prom_init(void)
  107. {
  108. struct ddr_ram __iomem *ddr;
  109. phys_addr_t memsize;
  110. phys_addr_t ddrbase;
  111. ddr = ioremap_nocache(ddr_reg[0].start,
  112. ddr_reg[0].end - ddr_reg[0].start);
  113. if (!ddr) {
  114. printk(KERN_ERR "Unable to remap DDR register\n");
  115. return;
  116. }
  117. ddrbase = (phys_addr_t)&ddr->ddrbase;
  118. memsize = (phys_addr_t)&ddr->ddrmask;
  119. memsize = 0 - memsize;
  120. prom_setup_cmdline();
  121. /* give all RAM to boot allocator,
  122. * except for the first 0x400 and the last 0x200 bytes */
  123. add_memory_region(ddrbase + 0x400, memsize - 0x600, BOOT_MEM_RAM);
  124. }