ve8313.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright (C) Freescale Semiconductor, Inc. 2006-2007
  3. *
  4. * Author: Scott Wood <scottwood@freescale.com>
  5. *
  6. * (C) Copyright 2010
  7. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <libfdt.h>
  29. #include <pci.h>
  30. #include <mpc83xx.h>
  31. #include <ns16550.h>
  32. #include <nand.h>
  33. #include <asm/bitops.h>
  34. #include <asm/io.h>
  35. DECLARE_GLOBAL_DATA_PTR;
  36. extern void disable_addr_trans (void);
  37. extern void enable_addr_trans (void);
  38. int checkboard(void)
  39. {
  40. puts("Board: ve8313\n");
  41. return 0;
  42. }
  43. static long fixed_sdram(void)
  44. {
  45. u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
  46. #ifndef CONFIG_SYS_RAMBOOT
  47. volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
  48. u32 msize_log2 = __ilog2(msize);
  49. out_be32(&im->sysconf.ddrlaw[0].bar,
  50. (CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000));
  51. out_be32(&im->sysconf.ddrlaw[0].ar, (LBLAWAR_EN | (msize_log2 - 1)));
  52. out_be32(&im->sysconf.ddrcdr, CONFIG_SYS_DDRCDR_VALUE);
  53. /*
  54. * Erratum DDR3 requires a 50ms delay after clearing DDRCDR[DDR_cfg],
  55. * or the DDR2 controller may fail to initialize correctly.
  56. */
  57. __udelay(50000);
  58. out_be32(&im->ddr.csbnds[0].csbnds, (msize - 1) >> 24);
  59. out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CONFIG);
  60. /* Currently we use only one CS, so disable the other bank. */
  61. out_be32(&im->ddr.cs_config[1], 0);
  62. out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_CLK_CNTL);
  63. out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
  64. out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
  65. out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
  66. out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
  67. out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_SDRAM_CFG);
  68. out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_SDRAM_CFG2);
  69. out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE);
  70. out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE_2);
  71. out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL);
  72. sync();
  73. /* enable DDR controller */
  74. setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
  75. /* now check the real size */
  76. disable_addr_trans ();
  77. msize = get_ram_size (CONFIG_SYS_DDR_BASE, msize);
  78. enable_addr_trans ();
  79. #endif
  80. return msize;
  81. }
  82. phys_size_t initdram(int board_type)
  83. {
  84. volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
  85. volatile fsl_lbc_t *lbc = &im->im_lbc;
  86. u32 msize;
  87. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
  88. return -1;
  89. /* DDR SDRAM - Main SODIMM */
  90. msize = fixed_sdram();
  91. /* Local Bus setup lbcr and mrtpr */
  92. out_be32(&lbc->lbcr, CONFIG_SYS_LBC_LBCR);
  93. out_be32(&lbc->mrtpr, CONFIG_SYS_LBC_MRTPR);
  94. sync();
  95. /* return total bus SDRAM size(bytes) -- DDR */
  96. return msize;
  97. }
  98. #define VE8313_WDT_EN 0x00020000
  99. #define VE8313_WDT_TRIG 0x00040000
  100. int board_early_init_f (void)
  101. {
  102. volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
  103. volatile gpio83xx_t *gpio = (volatile gpio83xx_t *)im->gpio;
  104. #if defined(CONFIG_HW_WATCHDOG)
  105. /* enable WDT */
  106. clrbits_be32(&gpio->dat, VE8313_WDT_EN | VE8313_WDT_TRIG);
  107. #else
  108. /* disable WDT */
  109. setbits_be32(&gpio->dat, VE8313_WDT_EN | VE8313_WDT_TRIG);
  110. #endif
  111. /* set WDT pins as output */
  112. setbits_be32(&gpio->dir, VE8313_WDT_EN | VE8313_WDT_TRIG);
  113. return 0;
  114. }
  115. #if defined(CONFIG_HW_WATCHDOG)
  116. void hw_watchdog_reset(void)
  117. {
  118. volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
  119. volatile gpio83xx_t *gpio = (volatile gpio83xx_t *)im->gpio;
  120. unsigned long reg;
  121. reg = in_be32(&gpio->dat);
  122. if (reg & VE8313_WDT_TRIG)
  123. clrbits_be32(&gpio->dat, VE8313_WDT_TRIG);
  124. else
  125. setbits_be32(&gpio->dat, VE8313_WDT_TRIG);
  126. }
  127. #endif
  128. #if defined(CONFIG_PCI)
  129. static struct pci_region pci_regions[] = {
  130. {
  131. bus_start: CONFIG_SYS_PCI1_MEM_BASE,
  132. phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
  133. size: CONFIG_SYS_PCI1_MEM_SIZE,
  134. flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
  135. },
  136. {
  137. bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
  138. phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
  139. size: CONFIG_SYS_PCI1_MMIO_SIZE,
  140. flags: PCI_REGION_MEM
  141. },
  142. {
  143. bus_start: CONFIG_SYS_PCI1_IO_BASE,
  144. phys_start: CONFIG_SYS_PCI1_IO_PHYS,
  145. size: CONFIG_SYS_PCI1_IO_SIZE,
  146. flags: PCI_REGION_IO
  147. }
  148. };
  149. void pci_init_board(void)
  150. {
  151. volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
  152. volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
  153. volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
  154. struct pci_region *reg[] = { pci_regions };
  155. /* Enable all 3 PCI_CLK_OUTPUTs. */
  156. setbits_be32(&clk->occr, 0xe0000000);
  157. /*
  158. * Configure PCI Local Access Windows
  159. */
  160. out_be32(&pci_law[0].bar, CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR);
  161. out_be32(&pci_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
  162. out_be32(&pci_law[1].bar, CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR);
  163. out_be32(&pci_law[1].ar, LBLAWAR_EN | LBLAWAR_1MB);
  164. mpc83xx_pci_init(1, reg);
  165. }
  166. #endif
  167. #if defined(CONFIG_OF_BOARD_SETUP)
  168. void ft_board_setup(void *blob, bd_t *bd)
  169. {
  170. ft_cpu_setup(blob, bd);
  171. #ifdef CONFIG_PCI
  172. ft_pci_setup(blob, bd);
  173. #endif
  174. }
  175. #endif