m501sk.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * (C) Copyright 2008
  3. * Based on modifications by Alan Lu / Artila
  4. * Author : Timo Tuunainen / Sysart
  5. Kimmo Leppala / Sysart
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <asm/io.h>
  27. #include <netdev.h>
  28. #if defined(CONFIG_DRIVER_ETHER)
  29. #include <at91rm9200_net.h>
  30. #include <dm9161.h>
  31. #endif
  32. #include "m501sk.h"
  33. #include "net.h"
  34. #ifdef CONFIG_M501SK
  35. void m501sk_gpio_init(void)
  36. {
  37. AT91C_BASE_PIOD->PIO_PER = 1 << (M501SK_DEBUG_LED1 - 96) |
  38. 1 << (M501SK_DEBUG_LED2 - 96) | 1 << (M501SK_DEBUG_LED3 - 96) |
  39. 1 << (M501SK_DEBUG_LED4 - 96) | 1 << (M501SK_READY_LED - 96);
  40. AT91C_BASE_PIOD->PIO_OER = 1 << (M501SK_DEBUG_LED1 - 96) |
  41. 1 << (M501SK_DEBUG_LED2 - 96) | 1 << (M501SK_DEBUG_LED3 - 96) |
  42. 1 << (M501SK_DEBUG_LED4 - 96) | 1 << (M501SK_READY_LED - 96);
  43. AT91C_BASE_PIOD->PIO_SODR = 1 << (M501SK_READY_LED - 96);
  44. AT91C_BASE_PIOD->PIO_CODR = 1 << (M501SK_DEBUG_LED3 - 96);
  45. AT91C_BASE_PIOB->PIO_PER = 1 << (M501SK_BUZZER - 32);
  46. AT91C_BASE_PIOB->PIO_OER = 1 << (M501SK_BUZZER - 32);
  47. AT91C_BASE_PIOC->PIO_PDR = (1 << 7) | (1 << 8);
  48. /* Power OFF all USART's LEDs */
  49. AT91C_BASE_PIOA->PIO_PER = AT91C_PA5_TXD3 | AT91C_PA6_RXD3 |
  50. AT91C_PA17_TXD0 | AT91C_PA18_RXD0 | AT91C_PA22_RXD2 | \
  51. AT91C_PA23_TXD2;
  52. AT91C_BASE_PIOA->PIO_OER = AT91C_PA5_TXD3 | AT91C_PA6_RXD3 |
  53. AT91C_PA17_TXD0 | AT91C_PA18_RXD0 | AT91C_PA22_RXD2 | \
  54. AT91C_PA23_TXD2;
  55. AT91C_BASE_PIOA->PIO_SODR = AT91C_PA5_TXD3 | AT91C_PA6_RXD3 |
  56. AT91C_PA17_TXD0 | AT91C_PA18_RXD0 | AT91C_PA22_RXD2 | \
  57. AT91C_PA23_TXD2;
  58. AT91C_BASE_PIOB->PIO_PER = AT91C_PB20_RXD1 | AT91C_PB21_TXD1;
  59. AT91C_BASE_PIOB->PIO_OER = AT91C_PB20_RXD1 | AT91C_PB21_TXD1;
  60. AT91C_BASE_PIOB->PIO_SODR = AT91C_PB20_RXD1 | AT91C_PB21_TXD1;
  61. }
  62. uchar m501sk_gpio_set(M501SK_PIO io)
  63. {
  64. uchar status = 0xff;
  65. switch (io) {
  66. case M501SK_DEBUG_LED1:
  67. case M501SK_DEBUG_LED2:
  68. case M501SK_DEBUG_LED3:
  69. case M501SK_DEBUG_LED4:
  70. case M501SK_READY_LED:
  71. AT91C_BASE_PIOD->PIO_SODR = 1 << (io - 96);
  72. status = AT91C_BASE_PIOD->PIO_ODSR & (1 << (io - 96));
  73. break;
  74. case M501SK_BUZZER:
  75. AT91C_BASE_PIOB->PIO_SODR = 1 << (io - 32);
  76. status = AT91C_BASE_PIOB->PIO_ODSR & (1 << (io - 32));
  77. break;
  78. }
  79. return status;
  80. }
  81. uchar m501sk_gpio_clear(M501SK_PIO io)
  82. {
  83. uchar status = 0xff;
  84. switch (io) {
  85. case M501SK_DEBUG_LED1:
  86. case M501SK_DEBUG_LED2:
  87. case M501SK_DEBUG_LED3:
  88. case M501SK_DEBUG_LED4:
  89. case M501SK_READY_LED:
  90. AT91C_BASE_PIOD->PIO_CODR = 1 << (io - 96);
  91. status = AT91C_BASE_PIOD->PIO_ODSR & (1 << (io - 96));
  92. break;
  93. case M501SK_BUZZER:
  94. AT91C_BASE_PIOB->PIO_CODR = 1 << (io - 32);
  95. status = AT91C_BASE_PIOB->PIO_ODSR & (1 << (io - 32));
  96. break;
  97. }
  98. return status;
  99. }
  100. /*
  101. * Miscelaneous platform dependent initialisations
  102. */
  103. DECLARE_GLOBAL_DATA_PTR;
  104. int board_init(void)
  105. {
  106. /* Enable Ctrlc */
  107. console_init_f();
  108. /* Correct IRDA resistor problem */
  109. /* Set PA23_TXD in Output */
  110. ((AT91PS_PIO)AT91C_BASE_PIOA)->PIO_OER = AT91C_PA23_TXD2;
  111. /* memory and cpu-speed are setup before relocation */
  112. /* so we do _nothing_ here */
  113. gd->bd->bi_arch_number = MACH_TYPE_M501;
  114. /* adress of boot parameters */
  115. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  116. m501sk_gpio_init();
  117. /* Do interrupt init here, because flash needs timers */
  118. timer_init();
  119. flash_init();
  120. return 0;
  121. }
  122. int dram_init(void)
  123. {
  124. int i = 0;
  125. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  126. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  127. for (i = 0; i < 500; i++) {
  128. m501sk_gpio_clear(M501SK_DEBUG_LED3);
  129. m501sk_gpio_clear(M501SK_BUZZER);
  130. udelay(250);
  131. m501sk_gpio_set(M501SK_DEBUG_LED3);
  132. m501sk_gpio_set(M501SK_BUZZER);
  133. udelay(80);
  134. }
  135. m501sk_gpio_clear(M501SK_BUZZER);
  136. m501sk_gpio_clear(M501SK_DEBUG_LED3);
  137. return 0;
  138. }
  139. int board_late_init(void)
  140. {
  141. #if defined(CONFIG_CMD_NET)
  142. eth_init(gd->bd);
  143. eth_halt();
  144. #endif
  145. /* Protect U-Boot, kernel & ramdisk memory addresses */
  146. run_command("protect on 10000000 1041ffff", 0);
  147. return 0;
  148. }
  149. #ifdef CONFIG_DRIVER_ETHER
  150. #if defined(CONFIG_CMD_NET)
  151. /*
  152. * Name:
  153. * at91rm9200_GetPhyInterface
  154. * Description:
  155. * Initialise the interface functions to the PHY
  156. * Arguments:
  157. * None
  158. * Return value:
  159. * None
  160. */
  161. void at91rm9200_GetPhyInterface(AT91PS_PhyOps p_phyops)
  162. {
  163. p_phyops->Init = dm9161_InitPhy;
  164. p_phyops->IsPhyConnected = dm9161_IsPhyConnected;
  165. p_phyops->GetLinkSpeed = dm9161_GetLinkSpeed;
  166. p_phyops->AutoNegotiate = dm9161_AutoNegotiate;
  167. }
  168. #endif /* CONFIG_CMD_NET */
  169. #endif /* CONFIG_DRIVER_ETHER */
  170. #ifdef CONFIG_DRIVER_AT91EMAC
  171. int board_eth_init(bd_t *bis)
  172. {
  173. int rc = 0;
  174. rc = at91emac_register(bis, 0);
  175. return rc;
  176. }
  177. #endif
  178. #endif /* CONFIG_M501SK */