summaryrefslogtreecommitdiff
path: root/arch/arm/mach-uniphier/fdt-fixup.c
blob: dfa32fdd48b3c49d73277ab23d35fec65cc242c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2016-2018 Socionext Inc.
 *   Author: Masahiro Yamada <yamada.masahiro@socionext.com>
 */

#include <fdt_support.h>
#include <fdtdec.h>
#include <jffs2/load_kernel.h>
#include <mtd_node.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/printk.h>

#include "soc-info.h"

/*
 * The DRAM PHY requires 64 byte scratch area in each DRAM channel
 * for its dynamic PHY training feature.
 */
static int uniphier_ld20_fdt_mem_rsv(void *fdt, struct bd_info *bd)
{
	unsigned long rsv_addr;
	const unsigned long rsv_size = 64;
	int i, ret;

	if (!IS_ENABLED(CONFIG_ARCH_UNIPHIER_LD20) ||
	    uniphier_get_soc_id() != UNIPHIER_LD20_ID)
		return 0;

	for (i = 0; i < ARRAY_SIZE(bd->bi_dram); i++) {
		if (!bd->bi_dram[i].size)
			continue;

		rsv_addr = bd->bi_dram[i].start + bd->bi_dram[i].size;
		rsv_addr -= rsv_size;

		ret = fdt_add_mem_rsv(fdt, rsv_addr, rsv_size);
		if (ret)
			return -ENOSPC;

		pr_notice("   Reserved memory region for DRAM PHY training: addr=%lx size=%lx\n",
			  rsv_addr, rsv_size);
	}

	return 0;
}

int ft_board_setup(void *fdt, struct bd_info *bd)
{
	static const struct node_info nodes[] = {
		{ "socionext,uniphier-denali-nand-v5a", MTD_DEV_TYPE_NAND },
		{ "socionext,uniphier-denali-nand-v5b", MTD_DEV_TYPE_NAND },
	};
	int ret;

	fdt_fixup_mtdparts(fdt, nodes, ARRAY_SIZE(nodes));

	ret = uniphier_ld20_fdt_mem_rsv(fdt, bd);
	if (ret)
		return ret;

	return 0;
}