of.c 2.0 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>
24
#include <asm/mach-ralink/ralink_regs.h>
J
John Crispin 已提交
25 26 27 28 29

#include "common.h"

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

__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);

44 45
	of_node_put(np);

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

51
	return ioremap(res.start, resource_size(&res));
J
John Crispin 已提交
52 53 54 55
}

void __init plat_mem_setup(void)
{
56
	void *dtb;
57

J
John Crispin 已提交
58 59 60 61
	set_io_port_base(KSEG1);

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

67
	if (early_init_dt_scan_memory())
68 69 70
		return;

	if (soc_info.mem_detect)
71
		soc_info.mem_detect();
72
	else if (soc_info.mem_size)
73
		memblock_add(soc_info.mem_base, soc_info.mem_size * SZ_1M);
74 75 76 77
	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 已提交
78 79 80 81
}

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

84
	/* make sure that the reset controller is setup early */
85 86
	if (ralink_soc != MT762X_SOC_MT7621AT)
		ralink_rst_init();
87

J
John Crispin 已提交
88 89 90 91
	return 0;
}

arch_initcall(plat_of_setup);