atngw100mkii.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (C) 2010 Atmel Corporation
  3. *
  4. * Copyright (C) 2012 Andreas Bießmann <andreas.devel@googlemail.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <spi.h>
  26. #include <netdev.h>
  27. #include <asm/io.h>
  28. #include <asm/sdram.h>
  29. #include <asm/arch/clk.h>
  30. #include <asm/arch/gpio.h>
  31. #include <asm/arch/hmatrix.h>
  32. #include <asm/arch/mmu.h>
  33. #include <asm/arch/portmux.h>
  34. DECLARE_GLOBAL_DATA_PTR;
  35. struct mmu_vm_range mmu_vmr_table[CONFIG_SYS_NR_VM_REGIONS] = {
  36. {
  37. /* Atmel AT49BV640D 8 MiB x16 NOR flash on NCS0 */
  38. .virt_pgno = CONFIG_SYS_FLASH_BASE >> PAGE_SHIFT,
  39. .nr_pages = CONFIG_SYS_FLASH_SIZE >> PAGE_SHIFT,
  40. .phys = (CONFIG_SYS_FLASH_BASE >> PAGE_SHIFT)
  41. | MMU_VMR_CACHE_NONE,
  42. }, {
  43. /* Micron MT29F2G16AAD 256 MiB x16 NAND flash on NCS3 */
  44. .virt_pgno = EBI_SRAM_CS3_BASE >> PAGE_SHIFT,
  45. .nr_pages = EBI_SRAM_CS3_SIZE >> PAGE_SHIFT,
  46. .phys = (EBI_SRAM_CS3_BASE >> PAGE_SHIFT)
  47. | MMU_VMR_CACHE_NONE,
  48. }, {
  49. /* 2x16-bit ISSI IS42S16320B 64 MiB SDRAM (128 MiB total) */
  50. .virt_pgno = CONFIG_SYS_SDRAM_BASE >> PAGE_SHIFT,
  51. .nr_pages = EBI_SDRAM_SIZE >> PAGE_SHIFT,
  52. .phys = (CONFIG_SYS_SDRAM_BASE >> PAGE_SHIFT)
  53. | MMU_VMR_CACHE_WRBACK,
  54. },
  55. };
  56. static const struct sdram_config sdram_config = {
  57. .data_bits = SDRAM_DATA_32BIT,
  58. .row_bits = 13,
  59. .col_bits = 10,
  60. .bank_bits = 2,
  61. .cas = 3,
  62. .twr = 2,
  63. .trc = 7,
  64. .trp = 2,
  65. .trcd = 2,
  66. .tras = 5,
  67. .txsr = 6,
  68. /* 7.81 us */
  69. .refresh_period = (781 * (SDRAMC_BUS_HZ / 1000)) / 100000,
  70. };
  71. int board_early_init_f(void)
  72. {
  73. /* Enable SDRAM in the EBI mux */
  74. hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE)
  75. | HMATRIX_BIT(EBI_NAND_ENABLE));
  76. portmux_enable_ebi(32, 23, PORTMUX_EBI_NAND,
  77. PORTMUX_DRIVE_HIGH);
  78. portmux_select_gpio(PORTMUX_PORT_E, 1 << 23,
  79. PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH
  80. | PORTMUX_DRIVE_MIN);
  81. portmux_enable_usart1(PORTMUX_DRIVE_MIN);
  82. #if defined(CONFIG_MACB)
  83. portmux_enable_macb0(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH);
  84. portmux_enable_macb1(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH);
  85. #endif
  86. #if defined(CONFIG_MMC)
  87. portmux_enable_mmci(0, PORTMUX_MMCI_4BIT, PORTMUX_DRIVE_LOW);
  88. #endif
  89. #if defined(CONFIG_ATMEL_SPI)
  90. portmux_enable_spi0(1 << 0, PORTMUX_DRIVE_LOW);
  91. #endif
  92. return 0;
  93. }
  94. phys_size_t initdram(int board_type)
  95. {
  96. unsigned long expected_size;
  97. unsigned long actual_size;
  98. void *sdram_base;
  99. sdram_base = uncached(EBI_SDRAM_BASE);
  100. expected_size = sdram_init(sdram_base, &sdram_config);
  101. actual_size = get_ram_size(sdram_base, expected_size);
  102. if (expected_size != actual_size)
  103. printf("Warning: Only %lu of %lu MiB SDRAM is working\n",
  104. actual_size >> 20, expected_size >> 20);
  105. return actual_size;
  106. }
  107. int board_early_init_r(void)
  108. {
  109. gd->bd->bi_phy_id[0] = 0x01;
  110. gd->bd->bi_phy_id[1] = 0x03;
  111. return 0;
  112. }
  113. #ifdef CONFIG_CMD_NET
  114. int board_eth_init(bd_t *bi)
  115. {
  116. macb_eth_initialize(0, (void *)ATMEL_BASE_MACB0, bi->bi_phy_id[0]);
  117. macb_eth_initialize(1, (void *)ATMEL_BASE_MACB1, bi->bi_phy_id[1]);
  118. return 0;
  119. }
  120. #endif
  121. /* SPI chip select control */
  122. #ifdef CONFIG_ATMEL_SPI
  123. #define ATNGW100_DATAFLASH_CS_PIN GPIO_PIN_PA(3)
  124. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  125. {
  126. return bus == 0 && cs == 0;
  127. }
  128. void spi_cs_activate(struct spi_slave *slave)
  129. {
  130. gpio_set_value(ATNGW100_DATAFLASH_CS_PIN, 0);
  131. }
  132. void spi_cs_deactivate(struct spi_slave *slave)
  133. {
  134. gpio_set_value(ATNGW100_DATAFLASH_CS_PIN, 1);
  135. }
  136. #endif /* CONFIG_ATMEL_SPI */