blob: 26e957b21fbf7709c35ac303843cffd669a52971 [file] [log] [blame]
Thomas Gleixner16216332019-05-19 15:51:31 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Ralf Baechle73b43902008-07-16 16:12:25 +01002/*
3 * RouterBoard 500 specific prom routines
4 *
5 * Copyright (C) 2003, Peter Sadik <peter.sadik@idt.com>
6 * Copyright (C) 2005-2006, P.Christeas <p_christ@hol.gr>
7 * Copyright (C) 2007, Gabor Juhos <juhosg@openwrt.org>
8 * Felix Fietkau <nbd@openwrt.org>
9 * Florian Fainelli <florian@openwrt.org>
Ralf Baechle73b43902008-07-16 16:12:25 +010010 */
11
12#include <linux/init.h>
13#include <linux/mm.h>
Paul Gortmaker26dd3e42017-01-28 21:05:57 -050014#include <linux/export.h>
Ralf Baechle73b43902008-07-16 16:12:25 +010015#include <linux/string.h>
16#include <linux/console.h>
Mike Rapoport57c8a662018-10-30 15:09:49 -070017#include <linux/memblock.h>
Ralf Baechle73b43902008-07-16 16:12:25 +010018#include <linux/ioport.h>
19#include <linux/blkdev.h>
20
21#include <asm/bootinfo.h>
22#include <asm/mach-rc32434/ddr.h>
23#include <asm/mach-rc32434/prom.h>
24
Ralf Baechle73b43902008-07-16 16:12:25 +010025unsigned int idt_cpu_freq = 132000000;
26EXPORT_SYMBOL(idt_cpu_freq);
Ralf Baechle73b43902008-07-16 16:12:25 +010027
28static struct resource ddr_reg[] = {
29 {
30 .name = "ddr-reg",
31 .start = DDR0_PHYS_ADDR,
32 .end = DDR0_PHYS_ADDR + sizeof(struct ddr_ram),
33 .flags = IORESOURCE_MEM,
34 }
35};
36
37void __init prom_free_prom_memory(void)
38{
39 /* No prom memory to free */
40}
41
42static inline int match_tag(char *arg, const char *tag)
43{
44 return strncmp(arg, tag, strlen(tag)) == 0;
45}
46
47static inline unsigned long tag2ul(char *arg, const char *tag)
48{
49 char *num;
50
51 num = arg + strlen(tag);
52 return simple_strtoul(num, 0, 10);
53}
54
55void __init prom_setup_cmdline(void)
56{
Dmitri Vorobiev7580c9c2009-10-13 23:43:24 +030057 static char cmd_line[COMMAND_LINE_SIZE] __initdata;
Ralf Baechle73b43902008-07-16 16:12:25 +010058 char *cp, *board;
59 int prom_argc;
Ralf Baechle66315e12012-09-06 10:51:29 +020060 char **prom_argv;
Ralf Baechle73b43902008-07-16 16:12:25 +010061 int i;
62
63 prom_argc = fw_arg0;
64 prom_argv = (char **) fw_arg1;
Ralf Baechle73b43902008-07-16 16:12:25 +010065
66 cp = cmd_line;
67 /* Note: it is common that parameters start
68 * at argv[1] and not argv[0],
69 * however, our elf loader starts at [0] */
70 for (i = 0; i < prom_argc; i++) {
71 if (match_tag(prom_argv[i], FREQ_TAG)) {
72 idt_cpu_freq = tag2ul(prom_argv[i], FREQ_TAG);
73 continue;
74 }
75#ifdef IGNORE_CMDLINE_MEM
76 /* parses out the "mem=xx" arg */
77 if (match_tag(prom_argv[i], MEM_TAG))
78 continue;
79#endif
80 if (i > 0)
81 *(cp++) = ' ';
82 if (match_tag(prom_argv[i], BOARD_TAG)) {
83 board = prom_argv[i] + strlen(BOARD_TAG);
84
85 if (match_tag(board, BOARD_RB532A))
86 mips_machtype = MACH_MIKROTIK_RB532A;
87 else
88 mips_machtype = MACH_MIKROTIK_RB532;
89 }
90
Ralf Baechle73b43902008-07-16 16:12:25 +010091 strcpy(cp, prom_argv[i]);
92 cp += strlen(prom_argv[i]);
93 }
94 *(cp++) = ' ';
95
96 i = strlen(arcs_cmdline);
97 if (i > 0) {
98 *(cp++) = ' ';
99 strcpy(cp, arcs_cmdline);
100 cp += strlen(arcs_cmdline);
101 }
Dmitri Vorobiev7580c9c2009-10-13 23:43:24 +0300102 cmd_line[COMMAND_LINE_SIZE - 1] = '\0';
Ralf Baechle73b43902008-07-16 16:12:25 +0100103
104 strcpy(arcs_cmdline, cmd_line);
105}
106
107void __init prom_init(void)
108{
109 struct ddr_ram __iomem *ddr;
Ralf Baechle15d45cc2014-11-22 00:22:09 +0100110 phys_addr_t memsize;
111 phys_addr_t ddrbase;
Ralf Baechle73b43902008-07-16 16:12:25 +0100112
113 ddr = ioremap_nocache(ddr_reg[0].start,
114 ddr_reg[0].end - ddr_reg[0].start);
115
116 if (!ddr) {
117 printk(KERN_ERR "Unable to remap DDR register\n");
118 return;
119 }
120
Ralf Baechle15d45cc2014-11-22 00:22:09 +0100121 ddrbase = (phys_addr_t)&ddr->ddrbase;
122 memsize = (phys_addr_t)&ddr->ddrmask;
Ralf Baechle73b43902008-07-16 16:12:25 +0100123 memsize = 0 - memsize;
124
125 prom_setup_cmdline();
126
127 /* give all RAM to boot allocator,
128 * except for the first 0x400 and the last 0x200 bytes */
129 add_memory_region(ddrbase + 0x400, memsize - 0x600, BOOT_MEM_RAM);
130}