snapper9260.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Bluewater Systems Snapper 9260/9G20 modules
  4. *
  5. * (C) Copyright 2011 Bluewater Systems
  6. * Author: Andre Renaud <andre@bluewatersys.com>
  7. * Author: Ryan Mallon <ryan@bluewatersys.com>
  8. */
  9. #include <common.h>
  10. #include <dm.h>
  11. #include <init.h>
  12. #include <asm/global_data.h>
  13. #include <asm/io.h>
  14. #include <asm/gpio.h>
  15. #include <asm/mach-types.h>
  16. #include <asm/arch/at91sam9260_matrix.h>
  17. #include <asm/arch/at91sam9_smc.h>
  18. #include <asm/arch/at91_common.h>
  19. #include <asm/arch/clk.h>
  20. #include <asm/arch/gpio.h>
  21. #include <asm/arch/atmel_serial.h>
  22. #include <net.h>
  23. #include <netdev.h>
  24. #include <i2c.h>
  25. #include <pca953x.h>
  26. #include <linux/delay.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. /* IO Expander pins */
  29. #define IO_EXP_ETH_RESET (0 << 1)
  30. #define IO_EXP_ETH_POWER (1 << 1)
  31. static void macb_hw_init(void)
  32. {
  33. struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
  34. at91_periph_clk_enable(ATMEL_ID_EMAC0);
  35. /* Disable pull-ups to prevent PHY going into test mode */
  36. writel(pin_to_mask(AT91_PIN_PA14) |
  37. pin_to_mask(AT91_PIN_PA15) |
  38. pin_to_mask(AT91_PIN_PA18),
  39. &pioa->pudr);
  40. /* Power down ethernet */
  41. pca953x_set_dir(0x28, IO_EXP_ETH_POWER, PCA953X_DIR_OUT);
  42. pca953x_set_val(0x28, IO_EXP_ETH_POWER, 1);
  43. /* Hold ethernet in reset */
  44. pca953x_set_dir(0x28, IO_EXP_ETH_RESET, PCA953X_DIR_OUT);
  45. pca953x_set_val(0x28, IO_EXP_ETH_RESET, 0);
  46. /* Enable ethernet power */
  47. pca953x_set_val(0x28, IO_EXP_ETH_POWER, 0);
  48. at91_phy_reset();
  49. /* Bring the ethernet out of reset */
  50. pca953x_set_val(0x28, IO_EXP_ETH_RESET, 1);
  51. /* The phy internal reset take 21ms */
  52. udelay(21 * 1000);
  53. /* Re-enable pull-up */
  54. writel(pin_to_mask(AT91_PIN_PA14) |
  55. pin_to_mask(AT91_PIN_PA15) |
  56. pin_to_mask(AT91_PIN_PA18),
  57. &pioa->puer);
  58. at91_macb_hw_init();
  59. }
  60. static void nand_hw_init(void)
  61. {
  62. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  63. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  64. unsigned long csa;
  65. /* Enable CS3 as NAND/SmartMedia */
  66. csa = readl(&matrix->ebicsa);
  67. csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
  68. writel(csa, &matrix->ebicsa);
  69. /* Configure SMC CS3 for NAND/SmartMedia */
  70. writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
  71. AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
  72. &smc->cs[3].setup);
  73. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(4) |
  74. AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(4),
  75. &smc->cs[3].pulse);
  76. writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7),
  77. &smc->cs[3].cycle);
  78. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  79. AT91_SMC_MODE_EXNW_DISABLE |
  80. AT91_SMC_MODE_DBW_8 |
  81. AT91_SMC_MODE_TDF_CYCLE(3),
  82. &smc->cs[3].mode);
  83. /* Configure RDY/BSY */
  84. gpio_request(CONFIG_SYS_NAND_READY_PIN, "nand_rdy");
  85. gpio_direction_input(CONFIG_SYS_NAND_READY_PIN);
  86. /* Enable NandFlash */
  87. gpio_request(CONFIG_SYS_NAND_ENABLE_PIN, "nand_ce");
  88. gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  89. }
  90. int board_init(void)
  91. {
  92. at91_periph_clk_enable(ATMEL_ID_PIOA);
  93. at91_periph_clk_enable(ATMEL_ID_PIOB);
  94. at91_periph_clk_enable(ATMEL_ID_PIOC);
  95. /* The mach-type is the same for both Snapper 9260 and 9G20 */
  96. gd->bd->bi_arch_number = MACH_TYPE_SNAPPER_9260;
  97. /* Address of boot parameters */
  98. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  99. /* Initialise peripherals */
  100. at91_seriald_hw_init();
  101. i2c_set_bus_num(0);
  102. nand_hw_init();
  103. macb_hw_init();
  104. return 0;
  105. }
  106. int board_eth_init(struct bd_info *bis)
  107. {
  108. return macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x1f);
  109. }
  110. int dram_init(void)
  111. {
  112. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  113. CONFIG_SYS_SDRAM_SIZE);
  114. return 0;
  115. }
  116. void reset_phy(void)
  117. {
  118. }
  119. static struct atmel_serial_plat at91sam9260_serial_plat = {
  120. .base_addr = ATMEL_BASE_DBGU,
  121. };
  122. U_BOOT_DRVINFO(at91sam9260_serial) = {
  123. .name = "serial_atmel",
  124. .plat = &at91sam9260_serial_plat,
  125. };