nand_boot.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright 2009 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. *
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. *
  20. */
  21. #include <common.h>
  22. #include <mpc85xx.h>
  23. #include <asm-ppc/io.h>
  24. #include <ns16550.h>
  25. #include <nand.h>
  26. #include <asm/mmu.h>
  27. #include <asm/immap_85xx.h>
  28. #include <asm/fsl_ddr_sdram.h>
  29. #include <asm/fsl_law.h>
  30. #define SYSCLK_MASK 0x00200000
  31. #define BOARDREV_MASK 0x10100000
  32. #define BOARDREV_B 0x10100000
  33. #define BOARDREV_C 0x00100000
  34. #define SYSCLK_66 66666666
  35. #define SYSCLK_50 50000000
  36. #define SYSCLK_100 100000000
  37. DECLARE_GLOBAL_DATA_PTR;
  38. void board_init_f(ulong bootflag)
  39. {
  40. uint plat_ratio, bus_clk, sys_clk;
  41. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  42. volatile ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
  43. uint val, temp, sysclk_mask;
  44. val = pgpio->gpdat;
  45. sysclk_mask = val & SYSCLK_MASK;
  46. temp = val & BOARDREV_MASK;
  47. if (temp == BOARDREV_C) {
  48. if(sysclk_mask == 0)
  49. sys_clk = SYSCLK_66;
  50. else
  51. sys_clk = SYSCLK_100;
  52. } else if (temp == BOARDREV_B) {
  53. if(sysclk_mask == 0)
  54. sys_clk = SYSCLK_66;
  55. else
  56. sys_clk = SYSCLK_50;
  57. }
  58. plat_ratio = gur->porpllsr & 0x0000003e;
  59. plat_ratio >>= 1;
  60. bus_clk = plat_ratio * sys_clk;
  61. NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
  62. bus_clk / 16 / CONFIG_BAUDRATE);
  63. puts("\nNAND boot... ");
  64. /* copy code to DDR and jump to it - this should not return */
  65. /* NOTE - code has to be copied out of NAND buffer before
  66. * other blocks can be read.
  67. */
  68. relocate_code(CONFIG_SYS_NAND_U_BOOT_RELOC_SP, 0,
  69. CONFIG_SYS_NAND_U_BOOT_RELOC);
  70. }
  71. void board_init_r(gd_t *gd, ulong dest_addr)
  72. {
  73. nand_boot();
  74. }
  75. void putc(char c)
  76. {
  77. if (c == '\n')
  78. NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r');
  79. NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c);
  80. }
  81. void puts(const char *str)
  82. {
  83. while (*str)
  84. putc(*str++);
  85. }