eNET.c 7.3 KB

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