common: Drop image.h from common header
[platform/kernel/u-boot.git] / board / renesas / rcar-common / common.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * board/renesas/rcar-common/common.c
4  *
5  * Copyright (C) 2013 Renesas Electronics Corporation
6  * Copyright (C) 2013 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
7  * Copyright (C) 2015 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
8  */
9
10 #include <common.h>
11 #include <dm.h>
12 #include <dm/uclass-internal.h>
13 #include <asm/arch/rmobile.h>
14 #include <linux/libfdt.h>
15
16 #ifdef CONFIG_RCAR_GEN3
17
18 DECLARE_GLOBAL_DATA_PTR;
19
20 /* If the firmware passed a device tree use it for U-Boot DRAM setup. */
21 extern u64 rcar_atf_boot_args[];
22
23 int dram_init(void)
24 {
25         const void *atf_fdt_blob = (const void *)(rcar_atf_boot_args[1]);
26         const void *blob;
27
28         /* Check if ATF passed us DTB. If not, fall back to builtin DTB. */
29         if (fdt_magic(atf_fdt_blob) == FDT_MAGIC)
30                 blob = atf_fdt_blob;
31         else
32                 blob = gd->fdt_blob;
33
34         return fdtdec_setup_mem_size_base_fdt(blob);
35 }
36
37 int dram_init_banksize(void)
38 {
39         const void *atf_fdt_blob = (const void *)(rcar_atf_boot_args[1]);
40         const void *blob;
41
42         /* Check if ATF passed us DTB. If not, fall back to builtin DTB. */
43         if (fdt_magic(atf_fdt_blob) == FDT_MAGIC)
44                 blob = atf_fdt_blob;
45         else
46                 blob = gd->fdt_blob;
47
48         fdtdec_setup_memory_banksize_fdt(blob);
49
50         return 0;
51 }
52
53 #if CONFIG_IS_ENABLED(OF_BOARD_SETUP) && CONFIG_IS_ENABLED(PCI)
54 int ft_board_setup(void *blob, bd_t *bd)
55 {
56         struct udevice *dev;
57         struct uclass *uc;
58         fdt_addr_t regs_addr;
59         int i, off, ret;
60
61         ret = uclass_get(UCLASS_PCI, &uc);
62         if (ret)
63                 return ret;
64
65         uclass_foreach_dev(dev, uc) {
66                 struct pci_controller hose = { 0 };
67
68                 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
69                         if (hose.region_count == MAX_PCI_REGIONS) {
70                                 printf("maximum number of regions parsed, aborting\n");
71                                 break;
72                         }
73
74                         if (bd->bi_dram[i].size) {
75                                 pci_set_region(&hose.regions[hose.region_count++],
76                                                bd->bi_dram[i].start,
77                                                bd->bi_dram[i].start,
78                                                bd->bi_dram[i].size,
79                                                PCI_REGION_MEM |
80                                                PCI_REGION_PREFETCH |
81                                                PCI_REGION_SYS_MEMORY);
82                         }
83                 }
84
85                 regs_addr = devfdt_get_addr_index(dev, 0);
86                 off = fdt_node_offset_by_compat_reg(blob,
87                                 "renesas,pcie-rcar-gen3", regs_addr);
88                 if (off < 0) {
89                         printf("Failed to find PCIe node@%llx\n", regs_addr);
90                         return off;
91                 }
92
93                 fdt_pci_dma_ranges(blob, off, &hose);
94         }
95
96         return 0;
97 }
98 #endif
99 #endif