hcu4.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. *(C) Copyright 2005-2007 Netstal Maschinen AG
  3. * Niklaus Giger (Niklaus.Giger@netstal.com)
  4. *
  5. * This source code is free software; you can redistribute it
  6. * and/or modify it in source code form under the terms of the GNU
  7. * General Public License as published by the Free Software
  8. * Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  19. */
  20. #include <common.h>
  21. #include <ppc4xx.h>
  22. #include <asm/processor.h>
  23. #include <asm/io.h>
  24. #include <asm-ppc/u-boot.h>
  25. #include "../common/nm.h"
  26. DECLARE_GLOBAL_DATA_PTR;
  27. #define HCU_MACH_VERSIONS_REGISTER (0x7C000000 + 0xF00000)
  28. #define SYS_SLOT_ADDRESS (0x7C000000 + 0x400000)
  29. #define HCU3_DIGITAL_IO_REGISTER (0x7C000000 + 0x500000)
  30. #define HCU_SW_INSTALL_REQUESTED 0x10
  31. #undef DEBUG
  32. #if defined(DEBUG)
  33. void show_sdram_registers(void);
  34. #endif
  35. long int fixed_hcu4_sdram (unsigned int dram_size);
  36. /*
  37. * This function is run very early, out of flash, and before devices are
  38. * initialized. It is called by lib_ppc/board.c:board_init_f by virtue
  39. * of being in the init_sequence array.
  40. *
  41. * The SDRAM has been initialized already -- start.S:start called
  42. * init.S:init_sdram early on -- but it is not yet being used for
  43. * anything, not even stack. So be careful.
  44. */
  45. #define CPC0_CR0 0xb1 /* Chip control register 0 */
  46. #define CPC0_CR1 0xb2 /* Chip control register 1 */
  47. /* Attention: If you want 1 microsecs times from the external oscillator
  48. * use 0x00804051. But this causes problems with u-boot and linux!
  49. */
  50. #define CPC0_CR0_VALUE 0x0030103c
  51. #define CPC0_CR1_VALUE 0x00004051
  52. #define CPC0_ECR 0xaa /* Edge condition register */
  53. #define EBC0_CFG 0x23 /* External Peripheral Control Register */
  54. #define CPC0_EIRR 0xb6 /* External Interrupt Register */
  55. int board_early_init_f (void)
  56. {
  57. /*
  58. * Interrupt controller setup for the HCU4 board.
  59. * Note: IRQ 0-15 405GP internally generated; high; level sensitive
  60. * IRQ 16 405GP internally generated; low; level sensitive
  61. * IRQ 17-24 RESERVED/UNUSED
  62. * IRQ 31 (EXT IRQ 6) (unused)
  63. */
  64. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  65. mtdcr (uicer, 0x00000000); /* disable all ints */
  66. mtdcr (uiccr, 0x00000000); /* set all to be non-critical */
  67. mtdcr (uicpr, 0xFFFFE000); /* set int polarities */
  68. mtdcr (uictr, 0x00000000); /* set int trigger levels */
  69. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  70. mtdcr(CPC0_CR1, CPC0_CR1_VALUE);
  71. mtdcr(CPC0_ECR, 0x60606000);
  72. mtdcr(CPC0_EIRR, 0x7c000000);
  73. return 0;
  74. }
  75. #ifdef CONFIG_BOARD_PRE_INIT
  76. int board_pre_init (void)
  77. {
  78. return board_early_init_f ();
  79. }
  80. #endif
  81. int sys_install_requested(void)
  82. {
  83. u16 *ioValuePtr = (u16 *)HCU3_DIGITAL_IO_REGISTER;
  84. return (in_be16(ioValuePtr) & HCU_SW_INSTALL_REQUESTED) != 0;
  85. }
  86. int checkboard (void)
  87. {
  88. u16 *boardVersReg = (u16 *)HCU_MACH_VERSIONS_REGISTER;
  89. u16 generation = in_be16(boardVersReg) & 0xf0;
  90. u16 index = in_be16(boardVersReg) & 0x0f;
  91. /* Cannot be done, in board_early_init */
  92. mtdcr(CPC0_CR0, CPC0_CR0_VALUE);
  93. /* Force /RTS to active. The board it not wired quite
  94. * correctly to use cts/rtc flow control, so just force the
  95. * /RST active and forget about it.
  96. */
  97. writeb (readb (0xef600404) | 0x03, 0xef600404);
  98. nm_show_print(generation, index, 0);
  99. return 0;
  100. }
  101. u32 hcu_led_get(void)
  102. {
  103. return (~(in_be32((u32 *)GPIO0_OR)) >> 23) & 0xff;
  104. }
  105. /*
  106. * hcu_led_set value to be placed into the LEDs (max 6 bit)
  107. */
  108. void hcu_led_set(u32 value)
  109. {
  110. u32 tmp = ~value;
  111. tmp = (tmp << 23) | 0x7FFFFF;
  112. out_be32((u32 *)GPIO0_OR, tmp);
  113. }
  114. /*
  115. * sdram_init - Dummy implementation for start.S, spd_sdram or initdram
  116. * used for HCUx
  117. */
  118. void sdram_init(void)
  119. {
  120. return;
  121. }
  122. /*
  123. * hcu_get_slot
  124. */
  125. u32 hcu_get_slot(void)
  126. {
  127. u16 *slot = (u16 *)SYS_SLOT_ADDRESS;
  128. return in_be16(slot) & 0x7f;
  129. }
  130. /*
  131. * get_serial_number
  132. */
  133. u32 get_serial_number(void)
  134. {
  135. u32 *serial = (u32 *)CFG_FLASH_BASE;
  136. if (in_be32(serial) == 0xffffffff)
  137. return 0;
  138. return in_be32(serial);
  139. }
  140. /*
  141. * misc_init_r.
  142. */
  143. int misc_init_r(void)
  144. {
  145. common_misc_init_r();
  146. set_params_for_sw_install( sys_install_requested(), "hcu4" );
  147. return 0;
  148. }
  149. long int initdram(int board_type)
  150. {
  151. long dram_size = 0;
  152. u16 *boardVersReg = (u16 *) HCU_MACH_VERSIONS_REGISTER;
  153. u16 generation = in_be16(boardVersReg) & 0xf0;
  154. if (generation == HW_GENERATION_HCU3)
  155. dram_size = 32*1024*1024;
  156. else dram_size = 64*1024*1024;
  157. fixed_hcu4_sdram(dram_size);
  158. #ifdef DEBUG
  159. show_sdram_registers();
  160. #endif
  161. return dram_size;
  162. }
  163. #if defined(CONFIG_POST)
  164. /*
  165. * Returns 1 if keys pressed to start the power-on long-running tests
  166. * Called from board_init_f().
  167. */
  168. int post_hotkeys_pressed(void)
  169. {
  170. return 0; /* No hotkeys supported */
  171. }
  172. #endif /* CONFIG_POST */
  173. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  174. void ft_board_setup(void *blob, bd_t *bd)
  175. {
  176. ft_cpu_setup(blob, bd);
  177. }
  178. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */