cradle.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * (C) Copyright 2002
  3. * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net
  4. *
  5. * (C) Copyright 2002
  6. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  7. * Marius Groeger <mgroeger@sysgo.de>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <asm/arch/pxa-regs.h>
  28. #include <common.h>
  29. /* ------------------------------------------------------------------------- */
  30. /* local prototypes */
  31. void set_led (int led, int color);
  32. void error_code_halt (int code);
  33. int init_sio (int led, unsigned long base);
  34. inline void cradle_outb (unsigned short val, unsigned long base,
  35. unsigned long reg);
  36. inline unsigned char cradle_inb (unsigned long base, unsigned long reg);
  37. inline void sleep (int i);
  38. inline void
  39. /**********************************************************/
  40. sleep (int i)
  41. /**********************************************************/
  42. {
  43. while (i--) {
  44. udelay (1000000);
  45. }
  46. }
  47. void
  48. /**********************************************************/
  49. error_code_halt (int code)
  50. /**********************************************************/
  51. {
  52. while (1) {
  53. led_code (code, RED);
  54. sleep (1);
  55. led_code (0, OFF);
  56. sleep (1);
  57. }
  58. }
  59. void
  60. /**********************************************************/
  61. led_code (int code, int color)
  62. /**********************************************************/
  63. {
  64. int i;
  65. code &= 0xf; /* only 4 leds */
  66. for (i = 0; i < 4; i++) {
  67. if (code & (1 << i)) {
  68. set_led (i, color);
  69. } else {
  70. set_led (i, OFF);
  71. }
  72. }
  73. }
  74. void
  75. /**********************************************************/
  76. set_led (int led, int color)
  77. /**********************************************************/
  78. {
  79. int shift = led * 2;
  80. unsigned long mask = 0x3 << shift;
  81. CRADLE_LED_CLR_REG = mask; /* clear bits */
  82. CRADLE_LED_SET_REG = (color << shift); /* set bits */
  83. udelay (5000);
  84. }
  85. inline void
  86. /**********************************************************/
  87. cradle_outb (unsigned short val, unsigned long base, unsigned long reg)
  88. /**********************************************************/
  89. {
  90. *(volatile unsigned short *) (base + (reg * 2)) = val;
  91. }
  92. inline unsigned char
  93. /**********************************************************/
  94. cradle_inb (unsigned long base, unsigned long reg)
  95. /**********************************************************/
  96. {
  97. unsigned short val;
  98. val = *(volatile unsigned short *) (base + (reg * 2));
  99. return (val & 0xff);
  100. }
  101. int
  102. /**********************************************************/
  103. init_sio (int led, unsigned long base)
  104. /**********************************************************/
  105. {
  106. unsigned char val;
  107. set_led (led, YELLOW);
  108. val = cradle_inb (base, CRADLE_SIO_INDEX);
  109. val = cradle_inb (base, CRADLE_SIO_INDEX);
  110. if (val != 0) {
  111. set_led (led, RED);
  112. return -1;
  113. }
  114. /* map SCC2 to COM1 */
  115. cradle_outb (0x01, base, CRADLE_SIO_INDEX);
  116. cradle_outb (0x00, base, CRADLE_SIO_DATA);
  117. /* enable SCC2 extended regs */
  118. cradle_outb (0x40, base, CRADLE_SIO_INDEX);
  119. cradle_outb (0xa0, base, CRADLE_SIO_DATA);
  120. /* enable SCC2 clock multiplier */
  121. cradle_outb (0x51, base, CRADLE_SIO_INDEX);
  122. cradle_outb (0x04, base, CRADLE_SIO_DATA);
  123. /* enable SCC2 */
  124. cradle_outb (0x00, base, CRADLE_SIO_INDEX);
  125. cradle_outb (0x04, base, CRADLE_SIO_DATA);
  126. /* map SCC2 DMA to channel 0 */
  127. cradle_outb (0x4f, base, CRADLE_SIO_INDEX);
  128. cradle_outb (0x09, base, CRADLE_SIO_DATA);
  129. /* read ID from SIO to check operation */
  130. cradle_outb (0xe4, base, 0x3f8 + 0x3);
  131. val = cradle_inb (base, 0x3f8 + 0x0);
  132. if ((val & 0xf0) != 0x20) {
  133. set_led (led, RED);
  134. /* disable SCC2 */
  135. cradle_outb (0, base, CRADLE_SIO_INDEX);
  136. cradle_outb (0, base, CRADLE_SIO_DATA);
  137. return -1;
  138. }
  139. /* set back to bank 0 */
  140. cradle_outb (0, base, 0x3f8 + 0x3);
  141. set_led (led, GREEN);
  142. return 0;
  143. }
  144. /*
  145. * Miscelaneous platform dependent initialisations
  146. */
  147. int
  148. /**********************************************************/
  149. board_late_init (void)
  150. /**********************************************************/
  151. {
  152. return (0);
  153. }
  154. int
  155. /**********************************************************/
  156. board_init (void)
  157. /**********************************************************/
  158. {
  159. DECLARE_GLOBAL_DATA_PTR;
  160. led_code (0xf, YELLOW);
  161. /* arch number of HHP Cradle */
  162. gd->bd->bi_arch_number = 174;
  163. /* adress of boot parameters */
  164. gd->bd->bi_boot_params = 0xa0000100;
  165. /* Init SIOs to enable SCC2 */
  166. udelay (100000); /* delay makes it look neat */
  167. init_sio (0, CRADLE_SIO1_PHYS);
  168. udelay (100000);
  169. init_sio (1, CRADLE_SIO2_PHYS);
  170. udelay (100000);
  171. init_sio (2, CRADLE_SIO3_PHYS);
  172. udelay (100000);
  173. set_led (3, GREEN);
  174. return 1;
  175. }
  176. int
  177. /**********************************************************/
  178. dram_init (void)
  179. /**********************************************************/
  180. {
  181. DECLARE_GLOBAL_DATA_PTR;
  182. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  183. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  184. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  185. gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
  186. gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
  187. gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
  188. gd->bd->bi_dram[3].start = PHYS_SDRAM_4;
  189. gd->bd->bi_dram[3].size = PHYS_SDRAM_4_SIZE;
  190. return (PHYS_SDRAM_1_SIZE +
  191. PHYS_SDRAM_2_SIZE +
  192. PHYS_SDRAM_3_SIZE +
  193. PHYS_SDRAM_4_SIZE );
  194. }