board_late_init.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <spl.h>
  8. #include <libfdt.h>
  9. #include <nand.h>
  10. #include <linux/io.h>
  11. #include <../drivers/mtd/nand/denali.h>
  12. #include "boot-mode/boot-device.h"
  13. static void nand_denali_wp_disable(void)
  14. {
  15. #ifdef CONFIG_NAND_DENALI
  16. /*
  17. * Since the boot rom enables the write protection for NAND boot mode,
  18. * it must be disabled somewhere for "nand write", "nand erase", etc.
  19. * The workaround is here to not disturb the Denali NAND controller
  20. * driver just for a really SoC-specific thing.
  21. */
  22. void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE;
  23. writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT);
  24. #endif
  25. }
  26. struct uniphier_fdt_file {
  27. const char *compatible;
  28. const char *file_name;
  29. };
  30. static const struct uniphier_fdt_file uniphier_fdt_files[] = {
  31. { "socionext,ph1-ld4-ref", "uniphier-ph1-ld4-ref.dtb", },
  32. { "socionext,ph1-ld6b-ref", "uniphier-ph1-ld6b-ref.dtb", },
  33. { "socionext,ph1-ld10-ref", "uniphier-ph1-ld10-ref.dtb", },
  34. { "socionext,ph1-pro4-ace", "uniphier-ph1-pro4-ace.dtb", },
  35. { "socionext,ph1-pro4-ref", "uniphier-ph1-pro4-ref.dtb", },
  36. { "socionext,ph1-pro4-sanji", "uniphier-ph1-pro4-sanji.dtb", },
  37. { "socionext,ph1-pro5-4kbox", "uniphier-ph1-pro5-4kbox.dtb", },
  38. { "socionext,ph1-sld3-ref", "uniphier-ph1-sld3-ref.dtb", },
  39. { "socionext,ph1-sld8-ref", "uniphier-ph1-sld8-ref.dtb", },
  40. { "socionext,proxstream2-gentil", "uniphier-proxstream2-gentil.dtb", },
  41. { "socionext,proxstream2-vodka", "uniphier-proxstream2-vodka.dtb", },
  42. };
  43. static void uniphier_set_fdt_file(void)
  44. {
  45. DECLARE_GLOBAL_DATA_PTR;
  46. int i;
  47. /* lookup DTB file name based on the compatible string */
  48. for (i = 0; i < ARRAY_SIZE(uniphier_fdt_files); i++) {
  49. if (!fdt_node_check_compatible(gd->fdt_blob, 0,
  50. uniphier_fdt_files[i].compatible)) {
  51. setenv("fdt_file", uniphier_fdt_files[i].file_name);
  52. return;
  53. }
  54. }
  55. }
  56. int board_late_init(void)
  57. {
  58. puts("MODE: ");
  59. switch (spl_boot_device_raw()) {
  60. case BOOT_DEVICE_MMC1:
  61. printf("eMMC Boot\n");
  62. setenv("bootmode", "emmcboot");
  63. break;
  64. case BOOT_DEVICE_NAND:
  65. printf("NAND Boot\n");
  66. setenv("bootmode", "nandboot");
  67. nand_denali_wp_disable();
  68. break;
  69. case BOOT_DEVICE_NOR:
  70. printf("NOR Boot\n");
  71. setenv("bootmode", "norboot");
  72. break;
  73. case BOOT_DEVICE_USB:
  74. printf("USB Boot\n");
  75. setenv("bootmode", "usbboot");
  76. break;
  77. default:
  78. printf("Unsupported Boot Mode\n");
  79. return -1;
  80. }
  81. uniphier_set_fdt_file();
  82. return 0;
  83. }