smartweb.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian@popies.net>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. *
  6. * Achim Ehrlich <aehrlich@taskit.de>
  7. * taskit GmbH <www.taskit.de>
  8. *
  9. * (C) Copyright 2012-
  10. * Markus Hubig <mhubig@imko.de>
  11. * IMKO GmbH <www.imko.de>
  12. * (C) Copyright 2014
  13. * Heiko Schocher <hs@denx.de>
  14. * DENX Software Engineering GmbH
  15. *
  16. * SPDX-License-Identifier: GPL-2.0+
  17. */
  18. #include <common.h>
  19. #include <asm/io.h>
  20. #include <asm/arch/at91sam9_sdramc.h>
  21. #include <asm/arch/at91sam9260_matrix.h>
  22. #include <asm/arch/at91sam9_smc.h>
  23. #include <asm/arch/at91_common.h>
  24. #include <asm/arch/at91_pmc.h>
  25. #include <asm/arch/at91_spi.h>
  26. #include <spi.h>
  27. #include <asm/arch/gpio.h>
  28. #include <watchdog.h>
  29. #ifdef CONFIG_MACB
  30. # include <net.h>
  31. # include <netdev.h>
  32. #endif
  33. DECLARE_GLOBAL_DATA_PTR;
  34. static void smartweb_nand_hw_init(void)
  35. {
  36. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  37. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  38. unsigned long csa;
  39. /* Assign CS3 to NAND/SmartMedia Interface */
  40. csa = readl(&matrix->ebicsa);
  41. csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
  42. writel(csa, &matrix->ebicsa);
  43. /* Configure SMC CS3 for NAND/SmartMedia */
  44. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  45. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  46. &smc->cs[3].setup);
  47. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  48. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  49. &smc->cs[3].pulse);
  50. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  51. &smc->cs[3].cycle);
  52. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  53. AT91_SMC_MODE_TDF_CYCLE(2),
  54. &smc->cs[3].mode);
  55. /* Configure RDY/BSY */
  56. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  57. /* Enable NandFlash */
  58. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  59. }
  60. #ifdef CONFIG_MACB
  61. static void smartweb_macb_hw_init(void)
  62. {
  63. struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
  64. /* Enable the PHY Chip via PA26 on the Stamp 2 Adaptor */
  65. at91_set_gpio_output(AT91_PIN_PA26, 0);
  66. /*
  67. * Disable pull-up on:
  68. * RXDV (PA17) => PHY normal mode (not Test mode)
  69. * ERX0 (PA14) => PHY ADDR0
  70. * ERX1 (PA15) => PHY ADDR1
  71. * ERX2 (PA25) => PHY ADDR2
  72. * ERX3 (PA26) => PHY ADDR3
  73. * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
  74. *
  75. * PHY has internal pull-down
  76. */
  77. writel(pin_to_mask(AT91_PIN_PA14) |
  78. pin_to_mask(AT91_PIN_PA15) |
  79. pin_to_mask(AT91_PIN_PA17) |
  80. pin_to_mask(AT91_PIN_PA25) |
  81. pin_to_mask(AT91_PIN_PA26) |
  82. pin_to_mask(AT91_PIN_PA28),
  83. &pioa->pudr);
  84. at91_phy_reset();
  85. /* Re-enable pull-up */
  86. writel(pin_to_mask(AT91_PIN_PA14) |
  87. pin_to_mask(AT91_PIN_PA15) |
  88. pin_to_mask(AT91_PIN_PA17) |
  89. pin_to_mask(AT91_PIN_PA25) |
  90. pin_to_mask(AT91_PIN_PA26) |
  91. pin_to_mask(AT91_PIN_PA28),
  92. &pioa->puer);
  93. /* Initialize EMAC=MACB hardware */
  94. at91_macb_hw_init();
  95. }
  96. #endif /* CONFIG_MACB */
  97. int board_early_init_f(void)
  98. {
  99. /* enable this here, as we have SPL without serial support */
  100. at91_seriald_hw_init();
  101. return 0;
  102. }
  103. int board_init(void)
  104. {
  105. /* Adress of boot parameters */
  106. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  107. smartweb_nand_hw_init();
  108. #ifdef CONFIG_MACB
  109. smartweb_macb_hw_init();
  110. #endif
  111. /* power LED red */
  112. at91_set_gpio_output(AT91_PIN_PC6, 0);
  113. at91_set_gpio_output(AT91_PIN_PC7, 1);
  114. /* alarm LED off */
  115. at91_set_gpio_output(AT91_PIN_PC8, 0);
  116. at91_set_gpio_output(AT91_PIN_PC9, 0);
  117. /* prog LED red */
  118. at91_set_gpio_output(AT91_PIN_PC10, 0);
  119. at91_set_gpio_output(AT91_PIN_PC11, 1);
  120. return 0;
  121. }
  122. int dram_init(void)
  123. {
  124. gd->ram_size = get_ram_size(
  125. (void *)CONFIG_SYS_SDRAM_BASE,
  126. CONFIG_SYS_SDRAM_SIZE);
  127. return 0;
  128. }
  129. #ifdef CONFIG_MACB
  130. int board_eth_init(bd_t *bis)
  131. {
  132. return macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
  133. }
  134. #endif /* CONFIG_MACB */
  135. #if defined(CONFIG_SPL_BUILD)
  136. #include <spl.h>
  137. #include <nand.h>
  138. #include <spi_flash.h>
  139. void matrix_init(void)
  140. {
  141. struct at91_matrix *mat = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  142. writel((readl(&mat->scfg[3]) & (~AT91_MATRIX_SLOT_CYCLE))
  143. | AT91_MATRIX_SLOT_CYCLE_(0x40),
  144. &mat->scfg[3]);
  145. }
  146. void spl_board_init(void)
  147. {
  148. at91_set_gpio_output(AT91_PIN_PC6, 1);
  149. at91_set_gpio_output(AT91_PIN_PC7, 1);
  150. /* alarm LED orange */
  151. at91_set_gpio_output(AT91_PIN_PC8, 1);
  152. at91_set_gpio_output(AT91_PIN_PC9, 1);
  153. /* prog LED red */
  154. at91_set_gpio_output(AT91_PIN_PC10, 0);
  155. at91_set_gpio_output(AT91_PIN_PC11, 1);
  156. smartweb_nand_hw_init();
  157. at91_set_gpio_input(AT91_PIN_PA28, 1);
  158. at91_set_gpio_input(AT91_PIN_PA29, 1);
  159. /* check if both button are pressed */
  160. if (at91_get_gpio_value(AT91_PIN_PA28) == 0 &&
  161. at91_get_gpio_value(AT91_PIN_PA29) == 0) {
  162. debug("Recovery button pressed\n");
  163. nand_init();
  164. spl_nand_erase_one(0, 0);
  165. }
  166. }
  167. #define SDRAM_BASE_CONF (AT91_SDRAMC_NC_9 | AT91_SDRAMC_NR_13 \
  168. | AT91_SDRAMC_CAS_2 \
  169. | AT91_SDRAMC_NB_4 | AT91_SDRAMC_DBW_32 \
  170. | AT91_SDRAMC_TWR_VAL(2) | AT91_SDRAMC_TRC_VAL(7) \
  171. | AT91_SDRAMC_TRP_VAL(2) | AT91_SDRAMC_TRCD_VAL(2) \
  172. | AT91_SDRAMC_TRAS_VAL(5) | AT91_SDRAMC_TXSR_VAL(8))
  173. void mem_init(void)
  174. {
  175. struct at91_matrix *ma = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  176. struct at91_port *port = (struct at91_port *)ATMEL_BASE_PIOC;
  177. struct sdramc_reg setting;
  178. setting.cr = SDRAM_BASE_CONF;
  179. setting.mdr = AT91_SDRAMC_MD_SDRAM;
  180. setting.tr = (CONFIG_SYS_MASTER_CLOCK * 7) / 1000000;
  181. /*
  182. * I write here directly in this register, because this
  183. * approach is smaller than calling at91_set_a_periph() in a
  184. * for loop. This saved me 96 bytes.
  185. */
  186. writel(0xffff0000, &port->pdr);
  187. writel(readl(&ma->ebicsa) | AT91_MATRIX_CS1A_SDRAMC, &ma->ebicsa);
  188. sdramc_initialize(ATMEL_BASE_CS1, &setting);
  189. }
  190. #endif