board_late_init.c 2.0 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. #define VENDOR_PREFIX "socionext,"
  27. #define DTB_FILE_PREFIX "uniphier-"
  28. static int uniphier_set_fdt_file(void)
  29. {
  30. DECLARE_GLOBAL_DATA_PTR;
  31. const char *compat;
  32. char dtb_name[256];
  33. int buf_len = 256;
  34. int ret;
  35. ret = fdt_get_string(gd->fdt_blob, 0, "compatible", &compat);
  36. if (ret)
  37. return -EINVAL;
  38. if (strncmp(compat, VENDOR_PREFIX, strlen(VENDOR_PREFIX)))
  39. return -EINVAL;
  40. compat += strlen(VENDOR_PREFIX);
  41. strncat(dtb_name, DTB_FILE_PREFIX, buf_len);
  42. buf_len -= strlen(DTB_FILE_PREFIX);
  43. strncat(dtb_name, compat, buf_len);
  44. buf_len -= strlen(compat);
  45. strncat(dtb_name, ".dtb", buf_len);
  46. setenv("fdt_file", dtb_name);
  47. return 0;
  48. }
  49. int board_late_init(void)
  50. {
  51. puts("MODE: ");
  52. switch (spl_boot_device_raw()) {
  53. case BOOT_DEVICE_MMC1:
  54. printf("eMMC Boot\n");
  55. setenv("bootmode", "emmcboot");
  56. break;
  57. case BOOT_DEVICE_NAND:
  58. printf("NAND Boot\n");
  59. setenv("bootmode", "nandboot");
  60. nand_denali_wp_disable();
  61. break;
  62. case BOOT_DEVICE_NOR:
  63. printf("NOR Boot\n");
  64. setenv("bootmode", "norboot");
  65. break;
  66. case BOOT_DEVICE_USB:
  67. printf("USB Boot\n");
  68. setenv("bootmode", "usbboot");
  69. break;
  70. default:
  71. printf("Unknown\n");
  72. break;
  73. }
  74. if (uniphier_set_fdt_file())
  75. printf("fdt_file environment was not set correctly\n");
  76. return 0;
  77. }