arkn141-hjyb.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include <common.h>
  2. #include <dwmmc.h>
  3. #include <malloc.h>
  4. #include <asm/gpio.h>
  5. DECLARE_GLOBAL_DATA_PTR;
  6. #define ARKN141_UPDATE_MAGIC "ada7f0c6-7c86-11e9-8f9e-2a86e4085a59"
  7. #define rSYS_AHB_CLK_EN *((volatile unsigned int *)(0x40408044))
  8. #define rSYS_APB_CLK_EN *((volatile unsigned int *)(0x40408048))
  9. #define rSYS_PER_CLK_EN *((volatile unsigned int *)(0x40408050))
  10. #define rSYS_SD_CLK_CFG *((volatile unsigned int *)(0x40408058))
  11. #define rSYS_SD1_CLK_CFG *((volatile unsigned int *)(0x4040805c))
  12. #define rSYS_DEVICE_CLK_CFG1 *((volatile unsigned int *)(0x40408064))
  13. #define rSYS_SOFT_RSTNA *((volatile unsigned int *)(0x40408074))
  14. #define rSYS_PAD_CTRL03 *((volatile unsigned int *)(0x404081cc))
  15. #define rSYS_PAD_CTRL05 *((volatile unsigned int *)(0x404081d4))
  16. #define rSYS_PAD_CTRL07 *((volatile unsigned int *)(0x404081dc))
  17. #define rSYS_PAD_CTRL08 *((volatile unsigned int *)(0x404081e0))
  18. #define rSYS_PAD_CTRL09 *((volatile unsigned int *)(0x404081e4))
  19. #define rSYS_PAD_CTRL0A *((volatile unsigned int *)(0x404081e8))
  20. #define rSYS_PAD_CTRL0B *((volatile unsigned int *)(0x404081ec))
  21. #define rSYS_PAD_CTRL0F *((volatile unsigned int *)(0x40408180))
  22. #define rSYS_PAD_DRIVE00 *((volatile unsigned int *)(0x404081f4))
  23. #define rSYS_PAD_DRIVE01 *((volatile unsigned int *)(0x404081f8))
  24. static void dwmci_select_pad(void)
  25. {
  26. /* use sd/mmc 0 */
  27. rSYS_PAD_CTRL09 |= 0x7F;
  28. rSYS_SD_CLK_CFG = 0x00000420;
  29. /* use sd/mmc 1 pad sd1_2 */
  30. rSYS_PAD_CTRL0B |= (1 << 5) | (1 << 2);
  31. rSYS_PAD_CTRL05 &= ~(0x1FFFFF << 0);
  32. rSYS_PAD_CTRL05 |= (2 << 18) | (2 << 15) | (2 << 12) | (2 << 9) | (2 << 6) |
  33. (2 << 3) | (2 << 0);
  34. rSYS_SD1_CLK_CFG = 0x00000420;
  35. }
  36. static void dwmci_reset(void)
  37. {
  38. rSYS_AHB_CLK_EN &= ~((1 << 4) | (1 << 3));
  39. rSYS_SOFT_RSTNA &= ~((1 << 31) | (1 << 12));
  40. udelay(100);
  41. rSYS_SOFT_RSTNA |= ((1 << 31) | (1 << 12));
  42. rSYS_AHB_CLK_EN |= ((1 << 4) | (1 << 3));
  43. }
  44. #define ARK_MMC_CLK 24000000
  45. int ark_dwmci_init(char *name,u32 regbase, int bus_width, int index)
  46. {
  47. struct dwmci_host *host = NULL;
  48. host = malloc(sizeof(struct dwmci_host));
  49. if (!host) {
  50. printf("dwmci_host malloc fail!\n");
  51. return 1;
  52. }
  53. memset(host, 0, sizeof(struct dwmci_host));
  54. dwmci_select_pad();
  55. dwmci_reset();
  56. host->name = name;
  57. host->ioaddr = (void *)regbase;
  58. host->buswidth = bus_width;
  59. host->dev_index = index;
  60. host->bus_hz = ARK_MMC_CLK;
  61. host->fifo_mode = 1;
  62. add_dwmci(host, host->bus_hz, 400000);
  63. return 0;
  64. }
  65. int board_mmc_init(bd_t *bis)
  66. {
  67. ark_dwmci_init("ARK_MMC0", 0x60000000, 4, 0);
  68. ark_dwmci_init("ARK_MMC1", 0x68000000, 4, 0);
  69. return 0;
  70. }
  71. int dram_init(void)
  72. {
  73. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  74. CONFIG_SYS_SDRAM_SIZE);
  75. return 0;
  76. }
  77. int board_init(void)
  78. {
  79. unsigned int tmp;
  80. /* SPI pad enable */
  81. tmp = rSYS_PAD_CTRL08;
  82. tmp &= ~(0xFF << 16);
  83. tmp |= (0xA8 << 16);
  84. rSYS_PAD_CTRL08 = tmp;
  85. /* set pad drive */
  86. rSYS_PAD_DRIVE00 = 0;
  87. rSYS_PAD_DRIVE01 = 0;
  88. rSYS_PAD_CTRL0F &= ~(3 << 30); /* 24M OSC drive */
  89. rSYS_PAD_CTRL0F |= 2 << 30;
  90. /* disable unused module clk */
  91. rSYS_AHB_CLK_EN &= ~1;
  92. rSYS_PER_CLK_EN &= ~((1 << 2) | (1 << 3) | (1 << 12) | (1 << 13) | (1 << 24));
  93. return 0;
  94. }
  95. int board_late_init(void)
  96. {
  97. char cmd[128];
  98. char *need_update;
  99. unsigned int loadaddr;
  100. run_command("sf probe", 0);
  101. gpio_direction_input(32);
  102. if (!gpio_get_value(32))
  103. env_set("need_update", "yes");
  104. need_update = env_get("need_update");
  105. if (!strcmp(need_update, "yes")) {
  106. sprintf(cmd, "fatload %s %s %s update-magic", env_get("update_dev"),
  107. env_get("dev_part"), env_get("loadaddr"));
  108. run_command(cmd, 0);
  109. loadaddr = env_get_hex("loadaddr", 0);
  110. if (loadaddr && memcmp((void*)loadaddr, ARKN141_UPDATE_MAGIC,
  111. strlen(ARKN141_UPDATE_MAGIC))) {
  112. printf("Wrong update magic, do not update.\n");
  113. env_set("need_update", "no");
  114. } else {
  115. run_command("sf erase usrdata 0", 0);
  116. run_command("env default -f -a", 0);
  117. }
  118. }
  119. return 0;
  120. }