spl_board.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2016 Socionext Inc.
  3. * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <spl.h>
  9. #include <linux/io.h>
  10. #include <asm/processor.h>
  11. #include "../soc-info.h"
  12. void spl_board_announce_boot_device(void)
  13. {
  14. printf("eMMC");
  15. }
  16. struct uniphier_romfunc_table {
  17. void *mmc_send_cmd;
  18. void *mmc_card_blockaddr;
  19. void *mmc_switch_part;
  20. void *mmc_load_image;
  21. };
  22. static const struct uniphier_romfunc_table uniphier_ld11_romfunc_table = {
  23. .mmc_send_cmd = (void *)0x20d8,
  24. .mmc_card_blockaddr = (void *)0x1b68,
  25. .mmc_switch_part = (void *)0x1c38,
  26. .mmc_load_image = (void *)0x2e48,
  27. };
  28. static const struct uniphier_romfunc_table uniphier_ld20_romfunc_table = {
  29. .mmc_send_cmd = (void *)0x2130,
  30. .mmc_card_blockaddr = (void *)0x1ba0,
  31. .mmc_switch_part = (void *)0x1c70,
  32. .mmc_load_image = (void *)0x2ef0,
  33. };
  34. int uniphier_rom_get_mmc_funcptr(int (**send_cmd)(u32, u32),
  35. int (**card_blockaddr)(u32),
  36. int (**switch_part)(int),
  37. int (**load_image)(u32, uintptr_t, u32))
  38. {
  39. const struct uniphier_romfunc_table *table;
  40. switch (uniphier_get_soc_type()) {
  41. case SOC_UNIPHIER_LD11:
  42. table = &uniphier_ld11_romfunc_table;
  43. break;
  44. case SOC_UNIPHIER_LD20:
  45. table = &uniphier_ld20_romfunc_table;
  46. break;
  47. default:
  48. printf("unsupported SoC\n");
  49. return -EINVAL;
  50. }
  51. *send_cmd = table->mmc_send_cmd;
  52. *card_blockaddr = table->mmc_card_blockaddr;
  53. *switch_part = table->mmc_switch_part;
  54. *load_image = table->mmc_load_image;
  55. return 0;
  56. }
  57. int spl_board_load_image(void)
  58. {
  59. int (*send_cmd)(u32 cmd, u32 arg);
  60. int (*card_blockaddr)(u32 rca);
  61. int (*switch_part)(int part);
  62. int (*load_image)(u32 dev_addr, uintptr_t load_addr, u32 block_cnt);
  63. u32 dev_addr = CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR;
  64. const u32 rca = 0x1000; /* RCA assigned by Boot ROM */
  65. int ret;
  66. ret = uniphier_rom_get_mmc_funcptr(&send_cmd, &card_blockaddr,
  67. &switch_part, &load_image);
  68. if (ret)
  69. return ret;
  70. /*
  71. * deselect card before SEND_CSD command.
  72. * Do not check the return code. It fails, but it is OK.
  73. */
  74. (*send_cmd)(0x071a0000, 0); /* CMD7 (arg=0) */
  75. /* reset CMD Line */
  76. writeb(0x6, 0x5a00022f);
  77. while (readb(0x5a00022f))
  78. cpu_relax();
  79. ret = (*card_blockaddr)(rca);
  80. if (ret) {
  81. debug("card is block addressing\n");
  82. } else {
  83. debug("card is byte addressing\n");
  84. dev_addr *= 512;
  85. }
  86. ret = (*send_cmd)(0x071a0000, rca << 16); /* CMD7: select card again */
  87. if (ret)
  88. printf("failed to select card\n");
  89. ret = (*switch_part)(1); /* Switch to Boot Partition 1 */
  90. if (ret)
  91. printf("failed to switch partition\n");
  92. ret = (*load_image)(dev_addr, CONFIG_SYS_TEXT_BASE, 1);
  93. if (ret) {
  94. printf("failed to load image\n");
  95. return ret;
  96. }
  97. ret = spl_parse_image_header(&spl_image, (void *)CONFIG_SYS_TEXT_BASE);
  98. if (ret)
  99. return ret;
  100. ret = (*load_image)(dev_addr, spl_image.load_addr,
  101. spl_image.size / 512);
  102. if (ret) {
  103. printf("failed to load image\n");
  104. return ret;
  105. }
  106. return 0;
  107. }