board_late_init.c 2.3 KB

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