smartweb.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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/clk.h>
  28. #include <asm/arch/gpio.h>
  29. #include <watchdog.h>
  30. #ifdef CONFIG_MACB
  31. # include <net.h>
  32. # include <netdev.h>
  33. #endif
  34. DECLARE_GLOBAL_DATA_PTR;
  35. static void smartweb_nand_hw_init(void)
  36. {
  37. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  38. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  39. unsigned long csa;
  40. /* Assign CS3 to NAND/SmartMedia Interface */
  41. csa = readl(&matrix->ebicsa);
  42. csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
  43. writel(csa, &matrix->ebicsa);
  44. /* Configure SMC CS3 for NAND/SmartMedia */
  45. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  46. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  47. &smc->cs[3].setup);
  48. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  49. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  50. &smc->cs[3].pulse);
  51. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  52. &smc->cs[3].cycle);
  53. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  54. AT91_SMC_MODE_TDF_CYCLE(2),
  55. &smc->cs[3].mode);
  56. /* Configure RDY/BSY */
  57. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  58. /* Enable NandFlash */
  59. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  60. }
  61. #ifdef CONFIG_MACB
  62. static void smartweb_macb_hw_init(void)
  63. {
  64. struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
  65. /* Enable the PHY Chip via PA26 on the Stamp 2 Adaptor */
  66. at91_set_gpio_output(AT91_PIN_PA26, 0);
  67. /*
  68. * Disable pull-up on:
  69. * RXDV (PA17) => PHY normal mode (not Test mode)
  70. * ERX0 (PA14) => PHY ADDR0
  71. * ERX1 (PA15) => PHY ADDR1
  72. * ERX2 (PA25) => PHY ADDR2
  73. * ERX3 (PA26) => PHY ADDR3
  74. * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
  75. *
  76. * PHY has internal pull-down
  77. */
  78. writel(pin_to_mask(AT91_PIN_PA14) |
  79. pin_to_mask(AT91_PIN_PA15) |
  80. pin_to_mask(AT91_PIN_PA17) |
  81. pin_to_mask(AT91_PIN_PA25) |
  82. pin_to_mask(AT91_PIN_PA26) |
  83. pin_to_mask(AT91_PIN_PA28) |
  84. pin_to_mask(AT91_PIN_PA29),
  85. &pioa->pudr);
  86. at91_phy_reset();
  87. /* Re-enable pull-up */
  88. writel(pin_to_mask(AT91_PIN_PA14) |
  89. pin_to_mask(AT91_PIN_PA15) |
  90. pin_to_mask(AT91_PIN_PA17) |
  91. pin_to_mask(AT91_PIN_PA25) |
  92. pin_to_mask(AT91_PIN_PA26) |
  93. pin_to_mask(AT91_PIN_PA28) |
  94. pin_to_mask(AT91_PIN_PA29),
  95. &pioa->puer);
  96. /* Initialize EMAC=MACB hardware */
  97. at91_macb_hw_init();
  98. }
  99. #endif /* CONFIG_MACB */
  100. #ifdef CONFIG_USB_GADGET_AT91
  101. #include <linux/usb/at91_udc.h>
  102. void at91_udp_hw_init(void)
  103. {
  104. at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
  105. /* Enable PLLB */
  106. writel(get_pllb_init(), &pmc->pllbr);
  107. while ((readl(&pmc->sr) & AT91_PMC_LOCKB) != AT91_PMC_LOCKB)
  108. ;
  109. /* Enable UDPCK clock, MCK is enabled in at91_clock_init() */
  110. at91_periph_clk_enable(ATMEL_ID_UDP);
  111. writel(AT91SAM926x_PMC_UDP, &pmc->scer);
  112. }
  113. struct at91_udc_data board_udc_data = {
  114. .baseaddr = ATMEL_BASE_UDP0,
  115. };
  116. #endif
  117. int board_early_init_f(void)
  118. {
  119. /* enable this here, as we have SPL without serial support */
  120. at91_seriald_hw_init();
  121. return 0;
  122. }
  123. int board_init(void)
  124. {
  125. /* power LED red */
  126. at91_set_gpio_output(AT91_PIN_PC6, 0);
  127. at91_set_gpio_output(AT91_PIN_PC7, 1);
  128. /* alarm LED off */
  129. at91_set_gpio_output(AT91_PIN_PC8, 0);
  130. at91_set_gpio_output(AT91_PIN_PC9, 0);
  131. /* prog LED red */
  132. at91_set_gpio_output(AT91_PIN_PC10, 0);
  133. at91_set_gpio_output(AT91_PIN_PC11, 1);
  134. #ifdef CONFIG_USB_GADGET_AT91
  135. at91_udp_hw_init();
  136. at91_udc_probe(&board_udc_data);
  137. #endif
  138. /* Adress of boot parameters */
  139. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  140. smartweb_nand_hw_init();
  141. #ifdef CONFIG_MACB
  142. smartweb_macb_hw_init();
  143. #endif
  144. return 0;
  145. }
  146. int dram_init(void)
  147. {
  148. gd->ram_size = get_ram_size(
  149. (void *)CONFIG_SYS_SDRAM_BASE,
  150. CONFIG_SYS_SDRAM_SIZE);
  151. return 0;
  152. }
  153. #ifdef CONFIG_MACB
  154. int board_eth_init(bd_t *bis)
  155. {
  156. return macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
  157. }
  158. #endif /* CONFIG_MACB */
  159. #if defined(CONFIG_SPL_BUILD)
  160. #include <spl.h>
  161. #include <nand.h>
  162. #include <spi_flash.h>
  163. void matrix_init(void)
  164. {
  165. struct at91_matrix *mat = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  166. writel((readl(&mat->scfg[3]) & (~AT91_MATRIX_SLOT_CYCLE))
  167. | AT91_MATRIX_SLOT_CYCLE_(0x40),
  168. &mat->scfg[3]);
  169. }
  170. void spl_board_init(void)
  171. {
  172. /* power LED orange */
  173. at91_set_gpio_output(AT91_PIN_PC6, 1);
  174. at91_set_gpio_output(AT91_PIN_PC7, 1);
  175. /* alarm LED orange */
  176. at91_set_gpio_output(AT91_PIN_PC8, 1);
  177. at91_set_gpio_output(AT91_PIN_PC9, 1);
  178. /* prog LED red */
  179. at91_set_gpio_output(AT91_PIN_PC10, 0);
  180. at91_set_gpio_output(AT91_PIN_PC11, 1);
  181. smartweb_nand_hw_init();
  182. at91_set_gpio_input(AT91_PIN_PA28, 1);
  183. at91_set_gpio_input(AT91_PIN_PA29, 1);
  184. /* check if both button are pressed */
  185. if (at91_get_gpio_value(AT91_PIN_PA28) == 0 &&
  186. at91_get_gpio_value(AT91_PIN_PA29) == 0) {
  187. smartweb_nand_hw_init();
  188. nand_init();
  189. spl_nand_erase_one(0, 0);
  190. }
  191. }
  192. #define SDRAM_BASE_CONF (AT91_SDRAMC_NC_9 | AT91_SDRAMC_NR_13 \
  193. | AT91_SDRAMC_CAS_2 \
  194. | AT91_SDRAMC_NB_4 | AT91_SDRAMC_DBW_32 \
  195. | AT91_SDRAMC_TWR_VAL(2) | AT91_SDRAMC_TRC_VAL(7) \
  196. | AT91_SDRAMC_TRP_VAL(2) | AT91_SDRAMC_TRCD_VAL(2) \
  197. | AT91_SDRAMC_TRAS_VAL(5) | AT91_SDRAMC_TXSR_VAL(8))
  198. void mem_init(void)
  199. {
  200. struct at91_matrix *ma = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  201. struct at91_port *port = (struct at91_port *)ATMEL_BASE_PIOC;
  202. struct sdramc_reg setting;
  203. setting.cr = SDRAM_BASE_CONF;
  204. setting.mdr = AT91_SDRAMC_MD_SDRAM;
  205. setting.tr = (CONFIG_SYS_MASTER_CLOCK * 7) / 1000000;
  206. /*
  207. * I write here directly in this register, because this
  208. * approach is smaller than calling at91_set_a_periph() in a
  209. * for loop. This saved me 96 bytes.
  210. */
  211. writel(0xffff0000, &port->pdr);
  212. writel(readl(&ma->ebicsa) | AT91_MATRIX_CS1A_SDRAMC, &ma->ebicsa);
  213. sdramc_initialize(ATMEL_BASE_CS1, &setting);
  214. }
  215. #endif