board_late_init.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2014 Panasonic Corporation
  3. * Copyright (C) 2015-2016 Socionext Inc.
  4. * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <spl.h>
  10. #include <libfdt.h>
  11. #include <nand.h>
  12. #include <linux/io.h>
  13. #include <../drivers/mtd/nand/denali.h>
  14. #include "init.h"
  15. static void nand_denali_wp_disable(void)
  16. {
  17. #ifdef CONFIG_NAND_DENALI
  18. /*
  19. * Since the boot rom enables the write protection for NAND boot mode,
  20. * it must be disabled somewhere for "nand write", "nand erase", etc.
  21. * The workaround is here to not disturb the Denali NAND controller
  22. * driver just for a really SoC-specific thing.
  23. */
  24. void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE;
  25. writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT);
  26. #endif
  27. }
  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 = sizeof(dtb_name);
  34. if (env_get("fdt_file"))
  35. return 0; /* do nothing if it is already set */
  36. compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
  37. if (!compat)
  38. return -EINVAL;
  39. /* rip off the vendor prefix "socionext," */
  40. compat = strchr(compat, ',');
  41. if (!compat)
  42. return -EINVAL;
  43. compat++;
  44. strncpy(dtb_name, compat, buf_len);
  45. buf_len -= strlen(compat);
  46. strncat(dtb_name, ".dtb", buf_len);
  47. return env_set("fdt_file", dtb_name);
  48. }
  49. int board_late_init(void)
  50. {
  51. puts("MODE: ");
  52. switch (uniphier_boot_device_raw()) {
  53. case BOOT_DEVICE_MMC1:
  54. printf("eMMC Boot");
  55. env_set("bootmode", "emmcboot");
  56. break;
  57. case BOOT_DEVICE_NAND:
  58. printf("NAND Boot");
  59. env_set("bootmode", "nandboot");
  60. nand_denali_wp_disable();
  61. break;
  62. case BOOT_DEVICE_NOR:
  63. printf("NOR Boot");
  64. env_set("bootmode", "norboot");
  65. break;
  66. case BOOT_DEVICE_USB:
  67. printf("USB Boot");
  68. env_set("bootmode", "usbboot");
  69. break;
  70. default:
  71. printf("Unknown");
  72. break;
  73. }
  74. if (uniphier_have_internal_stm())
  75. printf(" (STM: %s)",
  76. uniphier_boot_from_backend() ? "OFF" : "ON");
  77. printf("\n");
  78. if (uniphier_set_fdt_file())
  79. printf("fdt_file environment was not set correctly\n");
  80. return 0;
  81. }