smartweb.c 6.6 KB

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