m501sk.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 <at91rm9200_net.h>
  27. #include <dm9161.h>
  28. #include "m501sk.h"
  29. #include "net.h"
  30. #ifdef CONFIG_M501SK
  31. void m501sk_gpio_init(void)
  32. {
  33. AT91C_BASE_PIOD->PIO_PER = 1 << (M501SK_DEBUG_LED1 - 96) |
  34. 1 << (M501SK_DEBUG_LED2 - 96) | 1 << (M501SK_DEBUG_LED3 - 96) |
  35. 1 << (M501SK_DEBUG_LED4 - 96) | 1 << (M501SK_READY_LED - 96);
  36. AT91C_BASE_PIOD->PIO_OER = 1 << (M501SK_DEBUG_LED1 - 96) |
  37. 1 << (M501SK_DEBUG_LED2 - 96) | 1 << (M501SK_DEBUG_LED3 - 96) |
  38. 1 << (M501SK_DEBUG_LED4 - 96) | 1 << (M501SK_READY_LED - 96);
  39. AT91C_BASE_PIOD->PIO_SODR = 1 << (M501SK_READY_LED - 96);
  40. AT91C_BASE_PIOD->PIO_CODR = 1 << (M501SK_DEBUG_LED3 - 96);
  41. AT91C_BASE_PIOB->PIO_PER = 1 << (M501SK_BUZZER - 32);
  42. AT91C_BASE_PIOB->PIO_OER = 1 << (M501SK_BUZZER - 32);
  43. AT91C_BASE_PIOC->PIO_PDR = (1 << 7) | (1 << 8);
  44. /* Power OFF all USART's LEDs */
  45. AT91C_BASE_PIOA->PIO_PER = AT91C_PA5_TXD3 | AT91C_PA6_RXD3 |
  46. AT91C_PA17_TXD0 | AT91C_PA18_RXD0 | AT91C_PA22_RXD2 | \
  47. AT91C_PA23_TXD2;
  48. AT91C_BASE_PIOA->PIO_OER = AT91C_PA5_TXD3 | AT91C_PA6_RXD3 |
  49. AT91C_PA17_TXD0 | AT91C_PA18_RXD0 | AT91C_PA22_RXD2 | \
  50. AT91C_PA23_TXD2;
  51. AT91C_BASE_PIOA->PIO_SODR = AT91C_PA5_TXD3 | AT91C_PA6_RXD3 |
  52. AT91C_PA17_TXD0 | AT91C_PA18_RXD0 | AT91C_PA22_RXD2 | \
  53. AT91C_PA23_TXD2;
  54. AT91C_BASE_PIOB->PIO_PER = AT91C_PB20_RXD1 | AT91C_PB21_TXD1;
  55. AT91C_BASE_PIOB->PIO_OER = AT91C_PB20_RXD1 | AT91C_PB21_TXD1;
  56. AT91C_BASE_PIOB->PIO_SODR = AT91C_PB20_RXD1 | AT91C_PB21_TXD1;
  57. }
  58. uchar m501sk_gpio_set(M501SK_PIO io)
  59. {
  60. uchar status = 0xff;
  61. switch (io) {
  62. case M501SK_DEBUG_LED1:
  63. case M501SK_DEBUG_LED2:
  64. case M501SK_DEBUG_LED3:
  65. case M501SK_DEBUG_LED4:
  66. case M501SK_READY_LED:
  67. AT91C_BASE_PIOD->PIO_SODR = 1 << (io - 96);
  68. status = AT91C_BASE_PIOD->PIO_ODSR & (1 << (io - 96));
  69. break;
  70. case M501SK_BUZZER:
  71. AT91C_BASE_PIOB->PIO_SODR = 1 << (io - 32);
  72. status = AT91C_BASE_PIOB->PIO_ODSR & (1 << (io - 32));
  73. break;
  74. }
  75. return status;
  76. }
  77. uchar m501sk_gpio_clear(M501SK_PIO io)
  78. {
  79. uchar status = 0xff;
  80. switch (io) {
  81. case M501SK_DEBUG_LED1:
  82. case M501SK_DEBUG_LED2:
  83. case M501SK_DEBUG_LED3:
  84. case M501SK_DEBUG_LED4:
  85. case M501SK_READY_LED:
  86. AT91C_BASE_PIOD->PIO_CODR = 1 << (io - 96);
  87. status = AT91C_BASE_PIOD->PIO_ODSR & (1 << (io - 96));
  88. break;
  89. case M501SK_BUZZER:
  90. AT91C_BASE_PIOB->PIO_CODR = 1 << (io - 32);
  91. status = AT91C_BASE_PIOB->PIO_ODSR & (1 << (io - 32));
  92. break;
  93. }
  94. return status;
  95. }
  96. /*
  97. * Miscelaneous platform dependent initialisations
  98. */
  99. DECLARE_GLOBAL_DATA_PTR;
  100. int board_init(void)
  101. {
  102. /* Enable Ctrlc */
  103. console_init_f();
  104. /* Correct IRDA resistor problem */
  105. /* Set PA23_TXD in Output */
  106. ((AT91PS_PIO)AT91C_BASE_PIOA)->PIO_OER = AT91C_PA23_TXD2;
  107. /* memory and cpu-speed are setup before relocation */
  108. /* so we do _nothing_ here */
  109. gd->bd->bi_arch_number = MACH_TYPE_M501;
  110. /* adress of boot parameters */
  111. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  112. m501sk_gpio_init();
  113. /* Do interrupt init here, because flash needs timers */
  114. interrupt_init();
  115. flash_init();
  116. return 0;
  117. }
  118. int dram_init(void)
  119. {
  120. int i = 0;
  121. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  122. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  123. for (i = 0; i < 500; i++) {
  124. m501sk_gpio_clear(M501SK_DEBUG_LED3);
  125. m501sk_gpio_clear(M501SK_BUZZER);
  126. udelay(250);
  127. m501sk_gpio_set(M501SK_DEBUG_LED3);
  128. m501sk_gpio_set(M501SK_BUZZER);
  129. udelay(80);
  130. }
  131. m501sk_gpio_clear(M501SK_BUZZER);
  132. m501sk_gpio_clear(M501SK_DEBUG_LED3);
  133. return 0;
  134. }
  135. int board_late_init(void)
  136. {
  137. #if defined(CONFIG_CMD_NET)
  138. eth_init(gd->bd);
  139. eth_halt();
  140. #endif
  141. /* Protect U-Boot, kernel & ramdisk memory addresses */
  142. run_command("protect on 10000000 1041ffff", 0);
  143. return 0;
  144. }
  145. #ifdef CONFIG_DRIVER_ETHER
  146. #if defined(CONFIG_CMD_NET)
  147. /*
  148. * Name:
  149. * at91rm9200_GetPhyInterface
  150. * Description:
  151. * Initialise the interface functions to the PHY
  152. * Arguments:
  153. * None
  154. * Return value:
  155. * None
  156. */
  157. void at91rm9200_GetPhyInterface(AT91PS_PhyOps p_phyops)
  158. {
  159. p_phyops->Init = dm9161_InitPhy;
  160. p_phyops->IsPhyConnected = dm9161_IsPhyConnected;
  161. p_phyops->GetLinkSpeed = dm9161_GetLinkSpeed;
  162. p_phyops->AutoNegotiate = dm9161_AutoNegotiate;
  163. }
  164. #endif /* CONFIG_CMD_NET */
  165. #endif /* CONFIG_DRIVER_ETHER */
  166. #endif /* CONFIG_M501SK */