eNET.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * (C) Copyright 2008
  3. * Graeme Russ, graeme.russ@gmail.com.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/io.h>
  25. #include <asm/ic/sc520.h>
  26. #include <net.h>
  27. #include <netdev.h>
  28. #ifdef CONFIG_HW_WATCHDOG
  29. #include <watchdog.h>
  30. #endif
  31. #include "hardware.h"
  32. DECLARE_GLOBAL_DATA_PTR;
  33. #undef SC520_CDP_DEBUG
  34. #ifdef SC520_CDP_DEBUG
  35. #define PRINTF(fmt,args...) printf (fmt ,##args)
  36. #else
  37. #define PRINTF(fmt,args...)
  38. #endif
  39. unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
  40. static void enet_timer_isr(void);
  41. static void enet_toggle_run_led(void);
  42. static void enet_setup_pars(void);
  43. /*
  44. * Miscellaneous platform dependent initializations
  45. */
  46. int board_early_init_f(void)
  47. {
  48. u16 pio_out_cfg = 0x0000;
  49. /* Configure General Purpose Bus timing */
  50. writeb(CONFIG_SYS_SC520_GPCSRT, &sc520_mmcr->gpcsrt);
  51. writeb(CONFIG_SYS_SC520_GPCSPW, &sc520_mmcr->gpcspw);
  52. writeb(CONFIG_SYS_SC520_GPCSOFF, &sc520_mmcr->gpcsoff);
  53. writeb(CONFIG_SYS_SC520_GPRDW, &sc520_mmcr->gprdw);
  54. writeb(CONFIG_SYS_SC520_GPRDOFF, &sc520_mmcr->gprdoff);
  55. writeb(CONFIG_SYS_SC520_GPWRW, &sc520_mmcr->gpwrw);
  56. writeb(CONFIG_SYS_SC520_GPWROFF, &sc520_mmcr->gpwroff);
  57. /* Configure Programmable Input/Output Pins */
  58. writew(CONFIG_SYS_SC520_PIODIR15_0, &sc520_mmcr->piodir15_0);
  59. writew(CONFIG_SYS_SC520_PIODIR31_16, &sc520_mmcr->piodir31_16);
  60. writew(CONFIG_SYS_SC520_PIOPFS31_16, &sc520_mmcr->piopfs31_16);
  61. writew(CONFIG_SYS_SC520_PIOPFS15_0, &sc520_mmcr->piopfs15_0);
  62. writeb(CONFIG_SYS_SC520_CSPFS, &sc520_mmcr->cspfs);
  63. writeb(CONFIG_SYS_SC520_CLKSEL, &sc520_mmcr->clksel);
  64. /*
  65. * Turn off top board
  66. * Set StrataFlash chips to 16-bit width
  67. * Set StrataFlash chips to normal (non reset/power down) mode
  68. */
  69. pio_out_cfg |= CONFIG_SYS_ENET_TOP_BRD_PWR;
  70. pio_out_cfg |= CONFIG_SYS_ENET_SF_WIDTH;
  71. pio_out_cfg |= CONFIG_SYS_ENET_SF1_MODE;
  72. pio_out_cfg |= CONFIG_SYS_ENET_SF2_MODE;
  73. writew(pio_out_cfg, &sc520_mmcr->pioset15_0);
  74. /* Turn off auxiliary power output */
  75. writew(CONFIG_SYS_ENET_AUX_PWR, &sc520_mmcr->pioclr15_0);
  76. /* Clear FPGA program mode */
  77. writew(CONFIG_SYS_ENET_FPGA_PROG, &sc520_mmcr->pioset31_16);
  78. enet_setup_pars();
  79. /* Disable Watchdog */
  80. writew(0x3333, &sc520_mmcr->wdtmrctl);
  81. writew(0xcccc, &sc520_mmcr->wdtmrctl);
  82. writew(0x0000, &sc520_mmcr->wdtmrctl);
  83. /* Chip Select Configuration */
  84. writew(CONFIG_SYS_SC520_BOOTCS_CTRL, &sc520_mmcr->bootcsctl);
  85. writew(CONFIG_SYS_SC520_ROMCS1_CTRL, &sc520_mmcr->romcs1ctl);
  86. writew(CONFIG_SYS_SC520_ROMCS2_CTRL, &sc520_mmcr->romcs2ctl);
  87. writeb(CONFIG_SYS_SC520_ADDDECCTL, &sc520_mmcr->adddecctl);
  88. writeb(CONFIG_SYS_SC520_UART1CTL, &sc520_mmcr->uart1ctl);
  89. writeb(CONFIG_SYS_SC520_UART2CTL, &sc520_mmcr->uart2ctl);
  90. writeb(CONFIG_SYS_SC520_SYSARBCTL, &sc520_mmcr->sysarbctl);
  91. writew(CONFIG_SYS_SC520_SYSARBMENB, &sc520_mmcr->sysarbmenb);
  92. /* enable posted-writes */
  93. writeb(CONFIG_SYS_SC520_HBCTL, &sc520_mmcr->hbctl);
  94. return 0;
  95. }
  96. static void enet_setup_pars(void)
  97. {
  98. /*
  99. * PARs 11 and 12 are 2MB SRAM @ 0x19000000
  100. *
  101. * These are setup now because older version of U-Boot have them
  102. * mapped to a different PAR which gets clobbered which prevents
  103. * using SRAM for warm-booting a new image
  104. */
  105. writel(CONFIG_SYS_SC520_SRAM1_PAR, &sc520_mmcr->par[11]);
  106. writel(CONFIG_SYS_SC520_SRAM2_PAR, &sc520_mmcr->par[12]);
  107. /* PARs 0 and 1 are Compact Flash slots (4kB each) */
  108. writel(CONFIG_SYS_SC520_CF1_PAR, &sc520_mmcr->par[0]);
  109. writel(CONFIG_SYS_SC520_CF2_PAR, &sc520_mmcr->par[1]);
  110. /* PAR 2 is used for Cache-As-RAM */
  111. /*
  112. * PARs 5 through 8 are additional NS16550 UARTS
  113. * 8 bytes each @ 0x013f8, 0x012f8, 0x011f8 and 0x010f8
  114. */
  115. writel(CONFIG_SYS_SC520_UARTA_PAR, &sc520_mmcr->par[5]);
  116. writel(CONFIG_SYS_SC520_UARTB_PAR, &sc520_mmcr->par[6]);
  117. writel(CONFIG_SYS_SC520_UARTC_PAR, &sc520_mmcr->par[7]);
  118. writel(CONFIG_SYS_SC520_UARTD_PAR, &sc520_mmcr->par[8]);
  119. /* PARs 9 and 10 are 32MB StrataFlash @ 0x10000000 */
  120. writel(CONFIG_SYS_SC520_SF1_PAR, &sc520_mmcr->par[9]);
  121. writel(CONFIG_SYS_SC520_SF2_PAR, &sc520_mmcr->par[10]);
  122. /* PAR 13 is 4kB DPRAM @ 0x18100000 (implemented in FPGA) */
  123. writel(CONFIG_SYS_SC520_DPRAM_PAR, &sc520_mmcr->par[13]);
  124. /*
  125. * PAR 14 is Low Level I/O (LEDs, Hex Switches etc)
  126. * Already configured in board_init16 (eNET_start16.S)
  127. *
  128. * PAR 15 is Boot ROM
  129. * Already configured in board_init16 (eNET_start16.S)
  130. */
  131. }
  132. int board_early_init_r(void)
  133. {
  134. /* CPU Speed to 100MHz */
  135. gd->cpu_clk = 100000000;
  136. /* Crystal is 33.000MHz */
  137. gd->bus_clk = 33000000;
  138. return 0;
  139. }
  140. int dram_init(void)
  141. {
  142. init_sc520_dram();
  143. return 0;
  144. }
  145. void show_boot_progress(int val)
  146. {
  147. uchar led_mask;
  148. led_mask = 0x00;
  149. if (val < 0)
  150. led_mask |= LED_ERR_BITMASK;
  151. led_mask |= (uchar)(val & 0x001f);
  152. outb(led_mask, LED_LATCH_ADDRESS);
  153. }
  154. int last_stage_init(void)
  155. {
  156. int minor;
  157. int major;
  158. major = minor = 0;
  159. outb(0x00, LED_LATCH_ADDRESS);
  160. register_timer_isr (enet_timer_isr);
  161. printf("Serck Controls eNET\n");
  162. return 0;
  163. }
  164. ulong board_flash_get_legacy (ulong base, int banknum, flash_info_t * info)
  165. {
  166. if (banknum == 0) { /* non-CFI boot flash */
  167. info->portwidth = FLASH_CFI_8BIT;
  168. info->chipwidth = FLASH_CFI_BY8;
  169. info->interface = FLASH_CFI_X8;
  170. return 1;
  171. } else
  172. return 0;
  173. }
  174. int board_eth_init(bd_t *bis)
  175. {
  176. return pci_eth_init(bis);
  177. }
  178. void setup_pcat_compatibility()
  179. {
  180. /* disable global interrupt mode */
  181. writeb(0x40, &sc520_mmcr->picicr);
  182. /* set all irqs to edge */
  183. writeb(0x00, &sc520_mmcr->pic_mode[0]);
  184. writeb(0x00, &sc520_mmcr->pic_mode[1]);
  185. writeb(0x00, &sc520_mmcr->pic_mode[2]);
  186. /*
  187. * active low polarity on PIC interrupt pins,
  188. * active high polarity on all other irq pins
  189. */
  190. writew(0x0000,&sc520_mmcr->intpinpol);
  191. /*
  192. * PIT 0 -> IRQ0
  193. * RTC -> IRQ8
  194. * FP error -> IRQ13
  195. * UART1 -> IRQ4
  196. * UART2 -> IRQ3
  197. */
  198. writeb(SC520_IRQ0, &sc520_mmcr->pit_int_map[0]);
  199. writeb(SC520_IRQ8, &sc520_mmcr->rtcmap);
  200. writeb(SC520_IRQ13, &sc520_mmcr->ferrmap);
  201. writeb(SC520_IRQ4, &sc520_mmcr->uart_int_map[0]);
  202. writeb(SC520_IRQ3, &sc520_mmcr->uart_int_map[1]);
  203. /* Disable all other interrupt sources */
  204. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_tmr_int_map[0]);
  205. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_tmr_int_map[1]);
  206. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_tmr_int_map[2]);
  207. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pit_int_map[1]);
  208. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pit_int_map[2]);
  209. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->ssimap);
  210. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->wdtmap);
  211. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->wpvmap);
  212. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->icemap);
  213. }
  214. void enet_timer_isr(void)
  215. {
  216. static long enet_ticks = 0;
  217. enet_ticks++;
  218. /* Toggle Watchdog every 100ms */
  219. if ((enet_ticks % 100) == 0)
  220. hw_watchdog_reset();
  221. /* Toggle Run LED every 500ms */
  222. if ((enet_ticks % 500) == 0)
  223. enet_toggle_run_led();
  224. }
  225. void hw_watchdog_reset(void)
  226. {
  227. /* Watchdog Reset must be atomic */
  228. long flag = disable_interrupts();
  229. if (sc520_mmcr->piodata15_0 & WATCHDOG_PIO_BIT)
  230. sc520_mmcr->pioclr15_0 = WATCHDOG_PIO_BIT;
  231. else
  232. sc520_mmcr->pioset15_0 = WATCHDOG_PIO_BIT;
  233. if (flag)
  234. enable_interrupts();
  235. }
  236. void enet_toggle_run_led(void)
  237. {
  238. unsigned char leds_state= inb(LED_LATCH_ADDRESS);
  239. if (leds_state & LED_RUN_BITMASK)
  240. outb(leds_state &~ LED_RUN_BITMASK, LED_LATCH_ADDRESS);
  241. else
  242. outb(leds_state | LED_RUN_BITMASK, LED_LATCH_ADDRESS);
  243. }