of.c 1.9 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-only
J
John Crispin 已提交
2 3 4 5
/*
 *
 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
J
John Crispin 已提交
6
 * Copyright (C) 2013 John Crispin <john@phrozen.org>
J
John Crispin 已提交
7 8 9 10
 */

#include <linux/io.h>
#include <linux/clk.h>
11
#include <linux/export.h>
J
John Crispin 已提交
12
#include <linux/init.h>
13
#include <linux/sizes.h>
J
John Crispin 已提交
14 15
#include <linux/of_fdt.h>
#include <linux/kernel.h>
M
Mike Rapoport 已提交
16
#include <linux/memblock.h>
J
John Crispin 已提交
17 18 19 20 21 22
#include <linux/of_platform.h>
#include <linux/of_address.h>

#include <asm/reboot.h>
#include <asm/bootinfo.h>
#include <asm/addrspace.h>
23
#include <asm/prom.h>
J
John Crispin 已提交
24 25 26 27 28

#include "common.h"

__iomem void *rt_sysc_membase;
__iomem void *rt_memc_membase;
29
EXPORT_SYMBOL_GPL(rt_sysc_membase);
J
John Crispin 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42

__iomem void *plat_of_remap_node(const char *node)
{
	struct resource res;
	struct device_node *np;

	np = of_find_compatible_node(NULL, NULL, node);
	if (!np)
		panic("Failed to find %s node", node);

	if (of_address_to_resource(np, 0, &res))
		panic("Failed to get resource for %s", node);

43
	if (!request_mem_region(res.start,
J
John Crispin 已提交
44
				resource_size(&res),
45
				res.name))
J
John Crispin 已提交
46 47
		panic("Failed to request resources for %s", node);

48
	return ioremap(res.start, resource_size(&res));
J
John Crispin 已提交
49 50 51 52
}

void __init plat_mem_setup(void)
{
53
	void *dtb;
54

J
John Crispin 已提交
55 56 57 58
	set_io_port_base(KSEG1);

	/*
	 * Load the builtin devicetree. This causes the chosen node to be
59
	 * parsed resulting in our memory appearing.
J
John Crispin 已提交
60
	 */
61
	dtb = get_fdt();
62
	__dt_setup_arch(dtb);
63

64 65 66 67
	if (!early_init_dt_scan_memory())
		return;

	if (soc_info.mem_detect)
68
		soc_info.mem_detect();
69
	else if (soc_info.mem_size)
70
		memblock_add(soc_info.mem_base, soc_info.mem_size * SZ_1M);
71 72 73 74
	else
		detect_memory_region(soc_info.mem_base,
				     soc_info.mem_size_min * SZ_1M,
				     soc_info.mem_size_max * SZ_1M);
J
John Crispin 已提交
75 76 77 78
}

static int __init plat_of_setup(void)
{
79
	__dt_register_buses(soc_info.compatible, "palmbus");
J
John Crispin 已提交
80

81
	/* make sure that the reset controller is setup early */
82 83
	ralink_rst_init();

J
John Crispin 已提交
84 85 86 87
	return 0;
}

arch_initcall(plat_of_setup);