eNET.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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/arch/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. unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
  34. static void enet_timer_isr(void);
  35. static void enet_toggle_run_led(void);
  36. static void enet_setup_pars(void);
  37. /*
  38. * Miscellaneous platform dependent initializations
  39. */
  40. int board_early_init_f(void)
  41. {
  42. u16 pio_out_cfg = 0x0000;
  43. /* Configure General Purpose Bus timing */
  44. writeb(CONFIG_SYS_SC520_GPCSRT, &sc520_mmcr->gpcsrt);
  45. writeb(CONFIG_SYS_SC520_GPCSPW, &sc520_mmcr->gpcspw);
  46. writeb(CONFIG_SYS_SC520_GPCSOFF, &sc520_mmcr->gpcsoff);
  47. writeb(CONFIG_SYS_SC520_GPRDW, &sc520_mmcr->gprdw);
  48. writeb(CONFIG_SYS_SC520_GPRDOFF, &sc520_mmcr->gprdoff);
  49. writeb(CONFIG_SYS_SC520_GPWRW, &sc520_mmcr->gpwrw);
  50. writeb(CONFIG_SYS_SC520_GPWROFF, &sc520_mmcr->gpwroff);
  51. /* Configure Programmable Input/Output Pins */
  52. writew(CONFIG_SYS_SC520_PIODIR15_0, &sc520_mmcr->piodir15_0);
  53. writew(CONFIG_SYS_SC520_PIODIR31_16, &sc520_mmcr->piodir31_16);
  54. writew(CONFIG_SYS_SC520_PIOPFS31_16, &sc520_mmcr->piopfs31_16);
  55. writew(CONFIG_SYS_SC520_PIOPFS15_0, &sc520_mmcr->piopfs15_0);
  56. writeb(CONFIG_SYS_SC520_CSPFS, &sc520_mmcr->cspfs);
  57. writeb(CONFIG_SYS_SC520_CLKSEL, &sc520_mmcr->clksel);
  58. /*
  59. * Turn off top board
  60. * Set StrataFlash chips to 16-bit width
  61. * Set StrataFlash chips to normal (non reset/power down) mode
  62. */
  63. pio_out_cfg |= CONFIG_SYS_ENET_TOP_BRD_PWR;
  64. pio_out_cfg |= CONFIG_SYS_ENET_SF_WIDTH;
  65. pio_out_cfg |= CONFIG_SYS_ENET_SF1_MODE;
  66. pio_out_cfg |= CONFIG_SYS_ENET_SF2_MODE;
  67. writew(pio_out_cfg, &sc520_mmcr->pioset15_0);
  68. /* Turn off auxiliary power output */
  69. writew(CONFIG_SYS_ENET_AUX_PWR, &sc520_mmcr->pioclr15_0);
  70. /* Clear FPGA program mode */
  71. writew(CONFIG_SYS_ENET_FPGA_PROG, &sc520_mmcr->pioset31_16);
  72. enet_setup_pars();
  73. /* Disable Watchdog */
  74. writew(0x3333, &sc520_mmcr->wdtmrctl);
  75. writew(0xcccc, &sc520_mmcr->wdtmrctl);
  76. writew(0x0000, &sc520_mmcr->wdtmrctl);
  77. /* Chip Select Configuration */
  78. writew(CONFIG_SYS_SC520_BOOTCS_CTRL, &sc520_mmcr->bootcsctl);
  79. writew(CONFIG_SYS_SC520_ROMCS1_CTRL, &sc520_mmcr->romcs1ctl);
  80. writew(CONFIG_SYS_SC520_ROMCS2_CTRL, &sc520_mmcr->romcs2ctl);
  81. writeb(CONFIG_SYS_SC520_ADDDECCTL, &sc520_mmcr->adddecctl);
  82. writeb(CONFIG_SYS_SC520_UART1CTL, &sc520_mmcr->uart1ctl);
  83. writeb(CONFIG_SYS_SC520_UART2CTL, &sc520_mmcr->uart2ctl);
  84. writeb(CONFIG_SYS_SC520_SYSARBCTL, &sc520_mmcr->sysarbctl);
  85. writew(CONFIG_SYS_SC520_SYSARBMENB, &sc520_mmcr->sysarbmenb);
  86. /* enable posted-writes */
  87. writeb(CONFIG_SYS_SC520_HBCTL, &sc520_mmcr->hbctl);
  88. return 0;
  89. }
  90. static void enet_setup_pars(void)
  91. {
  92. /*
  93. * PARs 11 and 12 are 2MB SRAM @ 0x19000000
  94. *
  95. * These are setup now because older version of U-Boot have them
  96. * mapped to a different PAR which gets clobbered which prevents
  97. * using SRAM for warm-booting a new image
  98. */
  99. writel(CONFIG_SYS_SC520_SRAM1_PAR, &sc520_mmcr->par[11]);
  100. writel(CONFIG_SYS_SC520_SRAM2_PAR, &sc520_mmcr->par[12]);
  101. /* PARs 0 and 1 are Compact Flash slots (4kB each) */
  102. writel(CONFIG_SYS_SC520_CF1_PAR, &sc520_mmcr->par[0]);
  103. writel(CONFIG_SYS_SC520_CF2_PAR, &sc520_mmcr->par[1]);
  104. /* PAR 2 is used for Cache-As-RAM */
  105. /*
  106. * PARs 5 through 8 are additional NS16550 UARTS
  107. * 8 bytes each @ 0x013f8, 0x012f8, 0x011f8 and 0x010f8
  108. */
  109. writel(CONFIG_SYS_SC520_UARTA_PAR, &sc520_mmcr->par[5]);
  110. writel(CONFIG_SYS_SC520_UARTB_PAR, &sc520_mmcr->par[6]);
  111. writel(CONFIG_SYS_SC520_UARTC_PAR, &sc520_mmcr->par[7]);
  112. writel(CONFIG_SYS_SC520_UARTD_PAR, &sc520_mmcr->par[8]);
  113. /* PARs 9 and 10 are 32MB StrataFlash @ 0x10000000 */
  114. writel(CONFIG_SYS_SC520_SF1_PAR, &sc520_mmcr->par[9]);
  115. writel(CONFIG_SYS_SC520_SF2_PAR, &sc520_mmcr->par[10]);
  116. /* PAR 13 is 4kB DPRAM @ 0x18100000 (implemented in FPGA) */
  117. writel(CONFIG_SYS_SC520_DPRAM_PAR, &sc520_mmcr->par[13]);
  118. /*
  119. * PAR 14 is Low Level I/O (LEDs, Hex Switches etc)
  120. * Already configured in board_init16 (eNET_start16.S)
  121. *
  122. * PAR 15 is Boot ROM
  123. * Already configured in board_init16 (eNET_start16.S)
  124. */
  125. }
  126. int board_early_init_r(void)
  127. {
  128. /* CPU Speed to 100MHz */
  129. gd->cpu_clk = 100000000;
  130. /* Crystal is 33.000MHz */
  131. gd->bus_clk = 33000000;
  132. return 0;
  133. }
  134. void show_boot_progress(int val)
  135. {
  136. uchar led_mask;
  137. led_mask = 0x00;
  138. if (val < 0)
  139. led_mask |= LED_ERR_BITMASK;
  140. led_mask |= (uchar)(val & 0x001f);
  141. outb(led_mask, LED_LATCH_ADDRESS);
  142. }
  143. int last_stage_init(void)
  144. {
  145. int minor;
  146. int major;
  147. major = minor = 0;
  148. outb(0x00, LED_LATCH_ADDRESS);
  149. register_timer_isr(enet_timer_isr);
  150. printf("Serck Controls eNET\n");
  151. return 0;
  152. }
  153. ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
  154. {
  155. if (banknum == 0) { /* non-CFI boot flash */
  156. info->portwidth = FLASH_CFI_8BIT;
  157. info->chipwidth = FLASH_CFI_BY8;
  158. info->interface = FLASH_CFI_X8;
  159. return 1;
  160. } else {
  161. return 0;
  162. }
  163. }
  164. int board_eth_init(bd_t *bis)
  165. {
  166. return pci_eth_init(bis);
  167. }
  168. void setup_pcat_compatibility()
  169. {
  170. /* disable global interrupt mode */
  171. writeb(0x40, &sc520_mmcr->picicr);
  172. /* set all irqs to edge */
  173. writeb(0x00, &sc520_mmcr->pic_mode[0]);
  174. writeb(0x00, &sc520_mmcr->pic_mode[1]);
  175. writeb(0x00, &sc520_mmcr->pic_mode[2]);
  176. /*
  177. * active low polarity on PIC interrupt pins,
  178. * active high polarity on all other irq pins
  179. */
  180. writew(0x0000, &sc520_mmcr->intpinpol);
  181. /*
  182. * PIT 0 -> IRQ0
  183. * RTC -> IRQ8
  184. * FP error -> IRQ13
  185. * UART1 -> IRQ4
  186. * UART2 -> IRQ3
  187. */
  188. writeb(SC520_IRQ0, &sc520_mmcr->pit_int_map[0]);
  189. writeb(SC520_IRQ8, &sc520_mmcr->rtcmap);
  190. writeb(SC520_IRQ13, &sc520_mmcr->ferrmap);
  191. writeb(SC520_IRQ4, &sc520_mmcr->uart_int_map[0]);
  192. writeb(SC520_IRQ3, &sc520_mmcr->uart_int_map[1]);
  193. /* Disable all other interrupt sources */
  194. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_tmr_int_map[0]);
  195. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_tmr_int_map[1]);
  196. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_tmr_int_map[2]);
  197. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pit_int_map[1]);
  198. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pit_int_map[2]);
  199. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->ssimap);
  200. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->wdtmap);
  201. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->wpvmap);
  202. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->icemap);
  203. }
  204. void enet_timer_isr(void)
  205. {
  206. static long enet_ticks;
  207. enet_ticks++;
  208. /* Toggle Watchdog every 100ms */
  209. if ((enet_ticks % 100) == 0)
  210. hw_watchdog_reset();
  211. /* Toggle Run LED every 500ms */
  212. if ((enet_ticks % 500) == 0)
  213. enet_toggle_run_led();
  214. }
  215. void hw_watchdog_reset(void)
  216. {
  217. /* Watchdog Reset must be atomic */
  218. long flag = disable_interrupts();
  219. if (sc520_mmcr->piodata15_0 & WATCHDOG_PIO_BIT)
  220. sc520_mmcr->pioclr15_0 = WATCHDOG_PIO_BIT;
  221. else
  222. sc520_mmcr->pioset15_0 = WATCHDOG_PIO_BIT;
  223. if (flag)
  224. enable_interrupts();
  225. }
  226. void enet_toggle_run_led(void)
  227. {
  228. unsigned char leds_state = inb(LED_LATCH_ADDRESS);
  229. if (leds_state & LED_RUN_BITMASK)
  230. outb(leds_state & ~LED_RUN_BITMASK, LED_LATCH_ADDRESS);
  231. else
  232. outb(leds_state | LED_RUN_BITMASK, LED_LATCH_ADDRESS);
  233. }