wb50n.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. */
  4. #include <common.h>
  5. #include <asm/io.h>
  6. #include <asm/arch/sama5_sfr.h>
  7. #include <asm/arch/sama5d3_smc.h>
  8. #include <asm/arch/at91_common.h>
  9. #include <asm/arch/at91_pmc.h>
  10. #include <asm/arch/at91_rstc.h>
  11. #include <asm/arch/gpio.h>
  12. #include <asm/arch/clk.h>
  13. #include <micrel.h>
  14. #include <net.h>
  15. #include <netdev.h>
  16. #include <spl.h>
  17. #include <asm/arch/atmel_mpddrc.h>
  18. #include <asm/arch/at91_wdt.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. /* ------------------------------------------------------------------------- */
  21. /*
  22. * Miscelaneous platform dependent initialisations
  23. */
  24. void wb50n_nand_hw_init(void)
  25. {
  26. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  27. at91_periph_clk_enable(ATMEL_ID_SMC);
  28. /* Configure SMC CS3 for NAND/SmartMedia */
  29. writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(1) |
  30. AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(1),
  31. &smc->cs[3].setup);
  32. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(5) |
  33. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(5),
  34. &smc->cs[3].pulse);
  35. writel(AT91_SMC_CYCLE_NWE(8) | AT91_SMC_CYCLE_NRD(8),
  36. &smc->cs[3].cycle);
  37. writel(AT91_SMC_TIMINGS_TCLR(3) | AT91_SMC_TIMINGS_TADL(10) |
  38. AT91_SMC_TIMINGS_TAR(3) | AT91_SMC_TIMINGS_TRR(4) |
  39. AT91_SMC_TIMINGS_TWB(5) | AT91_SMC_TIMINGS_RBNSEL(3) |
  40. AT91_SMC_TIMINGS_NFSEL(1), &smc->cs[3].timings);
  41. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  42. AT91_SMC_MODE_EXNW_DISABLE |
  43. AT91_SMC_MODE_DBW_8 |
  44. AT91_SMC_MODE_TDF_CYCLE(3), &smc->cs[3].mode);
  45. /* Disable Flash Write Protect Line */
  46. at91_set_pio_output(AT91_PIO_PORTE, 14, 1);
  47. }
  48. int board_early_init_f(void)
  49. {
  50. at91_periph_clk_enable(ATMEL_ID_PIOA);
  51. at91_periph_clk_enable(ATMEL_ID_PIOB);
  52. at91_periph_clk_enable(ATMEL_ID_PIOC);
  53. at91_periph_clk_enable(ATMEL_ID_PIOD);
  54. at91_periph_clk_enable(ATMEL_ID_PIOE);
  55. at91_seriald_hw_init();
  56. return 0;
  57. }
  58. int board_init(void)
  59. {
  60. /* adress of boot parameters */
  61. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  62. wb50n_nand_hw_init();
  63. at91_macb_hw_init();
  64. return 0;
  65. }
  66. int dram_init(void)
  67. {
  68. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  69. CONFIG_SYS_SDRAM_SIZE);
  70. return 0;
  71. }
  72. int board_phy_config(struct phy_device *phydev)
  73. {
  74. /* rx data delay */
  75. ksz9021_phy_extended_write(phydev,
  76. MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW, 0x2222);
  77. /* tx data delay */
  78. ksz9021_phy_extended_write(phydev,
  79. MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW, 0x2222);
  80. /* rx/tx clock delay */
  81. ksz9021_phy_extended_write(phydev,
  82. MII_KSZ9021_EXT_RGMII_CLOCK_SKEW, 0xf2f4);
  83. return 0;
  84. }
  85. int board_eth_init(bd_t *bis)
  86. {
  87. int rc = 0;
  88. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
  89. return rc;
  90. }
  91. #ifdef CONFIG_BOARD_LATE_INIT
  92. #include <linux/ctype.h>
  93. int board_late_init(void)
  94. {
  95. #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
  96. const char *LAIRD_NAME = "lrd_name";
  97. char name[32], *p;
  98. strcpy(name, get_cpu_name());
  99. for (p = name; *p != '\0'; *p = tolower(*p), p++)
  100. ;
  101. strcat(name, "-wb50n");
  102. env_set(LAIRD_NAME, name);
  103. #endif
  104. return 0;
  105. }
  106. #endif
  107. /* SPL */
  108. #ifdef CONFIG_SPL_BUILD
  109. void spl_board_init(void)
  110. {
  111. wb50n_nand_hw_init();
  112. }
  113. static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
  114. {
  115. ddr2->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_LPDDR_SDRAM);
  116. ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_9 |
  117. ATMEL_MPDDRC_CR_NR_ROW_13 |
  118. ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
  119. ATMEL_MPDDRC_CR_NDQS_DISABLED |
  120. ATMEL_MPDDRC_CR_DECOD_INTERLEAVED |
  121. ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
  122. ddr2->rtr = 0x411;
  123. ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
  124. 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
  125. 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
  126. 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
  127. 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
  128. 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
  129. 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
  130. 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
  131. ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
  132. 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
  133. 19 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
  134. 18 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
  135. ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
  136. 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
  137. 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
  138. 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
  139. 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
  140. }
  141. void mem_init(void)
  142. {
  143. struct atmel_sfr *sfr = (struct atmel_sfr *)ATMEL_BASE_SFR;
  144. struct atmel_mpddrc_config ddr2;
  145. ddr2_conf(&ddr2);
  146. writel(ATMEL_SFR_DDRCFG_FDQIEN | ATMEL_SFR_DDRCFG_FDQSIEN,
  147. &sfr->ddrcfg);
  148. /* enable MPDDR clock */
  149. at91_periph_clk_enable(ATMEL_ID_MPDDRC);
  150. at91_system_clk_enable(AT91_PMC_DDR);
  151. /* DDRAM2 Controller initialize */
  152. ddr2_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddr2);
  153. }
  154. void at91_pmc_init(void)
  155. {
  156. u32 tmp;
  157. tmp = AT91_PMC_PLLAR_29 |
  158. AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
  159. AT91_PMC_PLLXR_MUL(43) | AT91_PMC_PLLXR_DIV(1);
  160. at91_plla_init(tmp);
  161. at91_pllicpr_init(AT91_PMC_IPLL_PLLA(0x3));
  162. tmp = AT91_PMC_MCKR_MDIV_4 | AT91_PMC_MCKR_CSS_PLLA;
  163. at91_mck_init(tmp);
  164. }
  165. #endif