nand_boot.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright 2010-2011 Freescale Semiconductor, Inc.
  3. * Author: Roy Zang <tie-fei.zang@freescale.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. *
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. *
  21. */
  22. #include <common.h>
  23. #include <ns16550.h>
  24. #include <asm/io.h>
  25. #include <nand.h>
  26. #include <asm/fsl_law.h>
  27. /* Fixed sdram init -- doesn't use serial presence detect. */
  28. void sdram_init(void)
  29. {
  30. ccsr_ddr_t *ddr = (ccsr_ddr_t *)CONFIG_SYS_MPC85xx_DDR_ADDR;
  31. set_next_law(0, LAW_SIZE_2G, LAW_TRGT_IF_DDR_1);
  32. out_be32(&ddr->cs0_bnds, CONFIG_SYS_DDR_CS0_BNDS);
  33. out_be32(&ddr->cs0_config, CONFIG_SYS_DDR_CS0_CONFIG);
  34. out_be32(&ddr->cs1_bnds, CONFIG_SYS_DDR_CS1_BNDS);
  35. out_be32(&ddr->cs1_config, CONFIG_SYS_DDR_CS1_CONFIG);
  36. out_be32(&ddr->timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
  37. out_be32(&ddr->timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
  38. out_be32(&ddr->timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
  39. out_be32(&ddr->timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
  40. out_be32(&ddr->sdram_cfg_2, CONFIG_SYS_DDR_CONTROL2);
  41. out_be32(&ddr->sdram_mode, CONFIG_SYS_DDR_MODE_1);
  42. out_be32(&ddr->sdram_mode_2, CONFIG_SYS_DDR_MODE_2);
  43. out_be32(&ddr->sdram_interval, CONFIG_SYS_DDR_INTERVAL);
  44. out_be32(&ddr->sdram_data_init, CONFIG_SYS_DDR_DATA_INIT);
  45. out_be32(&ddr->sdram_clk_cntl, CONFIG_SYS_DDR_CLK_CTRL);
  46. out_be32(&ddr->timing_cfg_4, CONFIG_SYS_DDR_TIMING_4);
  47. out_be32(&ddr->timing_cfg_5, CONFIG_SYS_DDR_TIMING_5);
  48. out_be32(&ddr->ddr_zq_cntl, CONFIG_SYS_DDR_ZQ_CNTL);
  49. out_be32(&ddr->ddr_wrlvl_cntl, CONFIG_SYS_DDR_WRLVL_CNTL);
  50. out_be32(&ddr->ddr_cdr1, CONFIG_SYS_DDR_CDR_1);
  51. out_be32(&ddr->ddr_cdr2, CONFIG_SYS_DDR_CDR_2);
  52. out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_CONTROL);
  53. }
  54. void board_init_f(ulong bootflag)
  55. {
  56. u32 plat_ratio, bus_clk;
  57. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  58. /* initialize selected port with appropriate baud rate */
  59. plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
  60. plat_ratio >>= 1;
  61. bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
  62. NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
  63. bus_clk / 16 / CONFIG_BAUDRATE);
  64. puts("\nNAND boot... ");
  65. /* Initialize the DDR3 */
  66. sdram_init();
  67. /* copy code to RAM and jump to it - this should not return */
  68. /* NOTE - code has to be copied out of NAND buffer before
  69. * other blocks can be read.
  70. */
  71. relocate_code(CONFIG_SYS_NAND_U_BOOT_RELOC_SP, 0,
  72. CONFIG_SYS_NAND_U_BOOT_RELOC);
  73. }
  74. void board_init_r(gd_t *gd, ulong dest_addr)
  75. {
  76. nand_boot();
  77. }
  78. void putc(char c)
  79. {
  80. if (c == '\n')
  81. NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r');
  82. NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c);
  83. }
  84. void puts(const char *str)
  85. {
  86. while (*str)
  87. putc(*str++);
  88. }