eNET.c 7.7 KB

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