boot.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * OMAP3 boot
  4. *
  5. * Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr>
  6. */
  7. #include <common.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/sys_proto.h>
  10. #include <spl.h>
  11. static u32 boot_devices[] = {
  12. BOOT_DEVICE_ONENAND,
  13. BOOT_DEVICE_NAND,
  14. BOOT_DEVICE_ONENAND,
  15. BOOT_DEVICE_MMC2,
  16. BOOT_DEVICE_ONENAND,
  17. BOOT_DEVICE_MMC2,
  18. BOOT_DEVICE_MMC1,
  19. BOOT_DEVICE_XIP,
  20. BOOT_DEVICE_XIPWAIT,
  21. BOOT_DEVICE_MMC2,
  22. BOOT_DEVICE_XIP,
  23. BOOT_DEVICE_XIPWAIT,
  24. BOOT_DEVICE_NAND,
  25. BOOT_DEVICE_XIP,
  26. BOOT_DEVICE_XIPWAIT,
  27. BOOT_DEVICE_NAND,
  28. BOOT_DEVICE_ONENAND,
  29. BOOT_DEVICE_MMC2,
  30. BOOT_DEVICE_MMC1,
  31. BOOT_DEVICE_XIP,
  32. BOOT_DEVICE_XIPWAIT,
  33. BOOT_DEVICE_NAND,
  34. BOOT_DEVICE_ONENAND,
  35. BOOT_DEVICE_MMC2,
  36. BOOT_DEVICE_MMC1,
  37. BOOT_DEVICE_XIP,
  38. BOOT_DEVICE_XIPWAIT,
  39. BOOT_DEVICE_NAND,
  40. BOOT_DEVICE_MMC2_2,
  41. };
  42. u32 omap_sys_boot_device(void)
  43. {
  44. struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
  45. u32 sys_boot;
  46. /* Grab the first 5 bits of the status register for SYS_BOOT. */
  47. sys_boot = readl(&ctrl_base->status) & ((1 << 5) - 1);
  48. if (sys_boot >= (sizeof(boot_devices) / sizeof(u32)))
  49. return BOOT_DEVICE_NONE;
  50. return boot_devices[sys_boot];
  51. }
  52. int omap_reboot_mode(char *mode, unsigned int length)
  53. {
  54. u32 reboot_mode;
  55. char c;
  56. if (length < 2)
  57. return -1;
  58. reboot_mode = readl((u32 *)(OMAP34XX_SCRATCHPAD +
  59. OMAP_REBOOT_REASON_OFFSET));
  60. c = (reboot_mode >> 24) & 0xff;
  61. if (c != 'B')
  62. return -1;
  63. c = (reboot_mode >> 16) & 0xff;
  64. if (c != 'M')
  65. return -1;
  66. c = reboot_mode & 0xff;
  67. mode[0] = c;
  68. mode[1] = '\0';
  69. return 0;
  70. }
  71. int omap_reboot_mode_clear(void)
  72. {
  73. writel(0, (u32 *)(OMAP34XX_SCRATCHPAD + OMAP_REBOOT_REASON_OFFSET));
  74. return 0;
  75. }
  76. int omap_reboot_mode_store(char *mode)
  77. {
  78. u32 reboot_mode;
  79. reboot_mode = 'B' << 24 | 'M' << 16 | mode[0];
  80. writel(reboot_mode, (u32 *)(OMAP34XX_SCRATCHPAD +
  81. OMAP_REBOOT_REASON_OFFSET));
  82. return 0;
  83. }