common.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #include <common.h>
  10. #include <dm.h>
  11. #include <init.h>
  12. #include <dm/uclass-internal.h>
  13. #include <asm/arch/rmobile.h>
  14. #include <linux/libfdt.h>
  15. #ifdef CONFIG_RCAR_GEN3
  16. DECLARE_GLOBAL_DATA_PTR;
  17. /* If the firmware passed a device tree use it for U-Boot DRAM setup. */
  18. extern u64 rcar_atf_boot_args[];
  19. int fdtdec_board_setup(const void *fdt_blob)
  20. {
  21. void *atf_fdt_blob = (void *)(rcar_atf_boot_args[1]);
  22. if (fdt_magic(atf_fdt_blob) == FDT_MAGIC)
  23. fdt_overlay_apply_node((void *)fdt_blob, 0, atf_fdt_blob, 0);
  24. return 0;
  25. }
  26. int dram_init(void)
  27. {
  28. return fdtdec_setup_mem_size_base();
  29. }
  30. int dram_init_banksize(void)
  31. {
  32. fdtdec_setup_memory_banksize();
  33. return 0;
  34. }
  35. #if CONFIG_IS_ENABLED(OF_BOARD_SETUP) && CONFIG_IS_ENABLED(PCI)
  36. int ft_board_setup(void *blob, struct bd_info *bd)
  37. {
  38. struct udevice *dev;
  39. struct uclass *uc;
  40. fdt_addr_t regs_addr;
  41. int i, off, ret;
  42. ret = uclass_get(UCLASS_PCI, &uc);
  43. if (ret)
  44. return ret;
  45. uclass_foreach_dev(dev, uc) {
  46. struct pci_controller hose = { 0 };
  47. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  48. if (hose.region_count == MAX_PCI_REGIONS) {
  49. printf("maximum number of regions parsed, aborting\n");
  50. break;
  51. }
  52. if (bd->bi_dram[i].size) {
  53. pci_set_region(&hose.regions[hose.region_count++],
  54. bd->bi_dram[i].start,
  55. bd->bi_dram[i].start,
  56. bd->bi_dram[i].size,
  57. PCI_REGION_MEM |
  58. PCI_REGION_PREFETCH |
  59. PCI_REGION_SYS_MEMORY);
  60. }
  61. }
  62. regs_addr = devfdt_get_addr_index(dev, 0);
  63. off = fdt_node_offset_by_compat_reg(blob,
  64. "renesas,pcie-rcar-gen3", regs_addr);
  65. if (off < 0) {
  66. printf("Failed to find PCIe node@%llx\n", regs_addr);
  67. return off;
  68. }
  69. fdt_pci_dma_ranges(blob, off, &hose);
  70. }
  71. return 0;
  72. }
  73. #endif
  74. #endif