smartweb.c 6.5 KB

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