sc520_spunk.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /*
  2. *
  3. * (C) Copyright 2002
  4. * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <netdev.h>
  26. #include <ds1722.h>
  27. #include <asm/io.h>
  28. #include <asm/ic/sc520.h>
  29. #include <asm/ic/ssi.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. /*
  32. * Theory:
  33. * We first set up all IRQs to be non-pci, edge triggered,
  34. * when we later enumerate the pci bus and pci_sc520_fixup_irq() gets
  35. * called we reallocate irqs to the pci bus with sc520_pci_set_irq()
  36. * as needed. Whe choose the irqs to gram from a configurable list
  37. * inside pci_sc520_fixup_irq() (If this list contains stupid irq's
  38. * such as 0 thngas will not work)
  39. */
  40. static void irq_init(void)
  41. {
  42. /* disable global interrupt mode */
  43. sc520_mmcr->picicr = 0x40;
  44. /* set all irqs to edge */
  45. sc520_mmcr->pic_mode[0] = 0x00;
  46. sc520_mmcr->pic_mode[1] = 0x00;
  47. sc520_mmcr->pic_mode[2] = 0x00;
  48. /* active low polarity on PIC interrupt pins,
  49. * active high polarity on all other irq pins */
  50. sc520_mmcr->intpinpol = 0x0000;
  51. /* set irq number mapping */
  52. sc520_mmcr->gp_tmr_int_map[0] = SC520_IRQ_DISABLED; /* disable GP timer 0 INT */
  53. sc520_mmcr->gp_tmr_int_map[1] = SC520_IRQ_DISABLED; /* disable GP timer 1 INT */
  54. sc520_mmcr->gp_tmr_int_map[2] = SC520_IRQ_DISABLED; /* disable GP timer 2 INT */
  55. sc520_mmcr->pit_int_map[0] = SC520_IRQ0; /* Set PIT timer 0 INT to IRQ0 */
  56. sc520_mmcr->pit_int_map[1] = SC520_IRQ_DISABLED; /* disable PIT timer 1 INT */
  57. sc520_mmcr->pit_int_map[2] = SC520_IRQ_DISABLED; /* disable PIT timer 2 INT */
  58. sc520_mmcr->pci_int_map[0] = SC520_IRQ_DISABLED; /* disable PCI INT A */
  59. sc520_mmcr->pci_int_map[1] = SC520_IRQ_DISABLED; /* disable PCI INT B */
  60. sc520_mmcr->pci_int_map[2] = SC520_IRQ_DISABLED; /* disable PCI INT C */
  61. sc520_mmcr->pci_int_map[3] = SC520_IRQ_DISABLED; /* disable PCI INT D */
  62. sc520_mmcr->dmabcintmap = SC520_IRQ_DISABLED; /* disable DMA INT */
  63. sc520_mmcr->ssimap = SC520_IRQ6; /* Set Synchronius serial INT to IRQ6*/
  64. sc520_mmcr->wdtmap = SC520_IRQ_DISABLED; /* disable Watchdog INT */
  65. sc520_mmcr->rtcmap = SC520_IRQ8; /* Set RTC int to 8 */
  66. sc520_mmcr->wpvmap = SC520_IRQ_DISABLED; /* disable write protect INT */
  67. sc520_mmcr->icemap = SC520_IRQ1; /* Set ICE Debug Serielport INT to IRQ1 */
  68. sc520_mmcr->ferrmap = SC520_IRQ13; /* Set FP error INT to IRQ13 */
  69. sc520_mmcr->uart_int_map[0] = SC520_IRQ4; /* Set internal UART1 INT to IRQ4 */
  70. sc520_mmcr->uart_int_map[1] = SC520_IRQ3; /* Set internal UART2 INT to IRQ3 */
  71. sc520_mmcr->gp_int_map[0] = SC520_IRQ7; /* Set GPIRQ0 (PC-Card AUX IRQ) to IRQ7 */
  72. sc520_mmcr->gp_int_map[1] = SC520_IRQ14; /* Set GPIRQ1 (CF IRQ) to IRQ14 */
  73. sc520_mmcr->gp_int_map[3] = SC520_IRQ5; /* Set GPIRQ3 ( CAN IRQ ) ti IRQ5 */
  74. sc520_mmcr->gp_int_map[4] = SC520_IRQ_DISABLED; /* disbale GIRQ4 ( IRR IRQ ) */
  75. sc520_mmcr->gp_int_map[5] = SC520_IRQ_DISABLED; /* disable GPIRQ5 */
  76. sc520_mmcr->gp_int_map[6] = SC520_IRQ_DISABLED; /* disable GPIRQ6 */
  77. sc520_mmcr->gp_int_map[7] = SC520_IRQ_DISABLED; /* disable GPIRQ7 */
  78. sc520_mmcr->gp_int_map[8] = SC520_IRQ_DISABLED; /* disable GPIRQ8 */
  79. sc520_mmcr->gp_int_map[9] = SC520_IRQ_DISABLED; /* disable GPIRQ9 */
  80. sc520_mmcr->gp_int_map[2] = SC520_IRQ_DISABLED; /* disable GPIRQ2 */
  81. sc520_mmcr->gp_int_map[10] = SC520_IRQ_DISABLED; /* disable GPIRQ10 */
  82. sc520_mmcr->pcihostmap = 0x11f; /* Map PCI hostbridge INT to NMI */
  83. sc520_mmcr->eccmap = 0x100; /* Map SDRAM ECC failure INT to NMI */
  84. }
  85. /* set up the ISA bus timing and system address mappings */
  86. static void bus_init(void)
  87. {
  88. /* versions
  89. * 0 Hyglo versions 0.95 and 0.96 (large baords)
  90. * ?? Hyglo version 0.97 (small board)
  91. * 10 Spunk board
  92. */
  93. int version = sc520_mmcr->sysinfo;
  94. if (version) {
  95. /* set up the GP IO pins (for the Spunk board) */
  96. sc520_mmcr->piopfs31_16 = 0xfff0; /* set the GPIO pin function 31-16 reg */
  97. sc520_mmcr->piopfs15_0 = 0x000f; /* set the GPIO pin function 15-0 reg */
  98. sc520_mmcr->piodir31_16 = 0x000f; /* set the GPIO direction 31-16 reg */
  99. sc520_mmcr->piodir15_0 = 0x1ff0; /* set the GPIO direction 15-0 reg */
  100. sc520_mmcr->cspfs = 0xc0; /* set the CS pin function reg */
  101. sc520_mmcr->clksel = 0x70;
  102. sc520_mmcr->pioclr31_16 = 0x0003; /* reset SSI chip-selects */
  103. sc520_mmcr->pioset31_16 = 0x000c;
  104. } else {
  105. /* set up the GP IO pins (for the Hyglo board) */
  106. sc520_mmcr->piopfs31_16 = 0xffc0; /* set the GPIO pin function 31-16 reg */
  107. sc520_mmcr->piopfs15_0 = 0x1e7f; /* set the GPIO pin function 15-0 reg */
  108. sc520_mmcr->piodir31_16 = 0x003f; /* set the GPIO direction 31-16 reg */
  109. sc520_mmcr->piodir15_0 = 0xe180; /* set the GPIO direction 15-0 reg */
  110. sc520_mmcr->cspfs = 0x00; /* set the CS pin function reg */
  111. sc520_mmcr->clksel = 0x70;
  112. sc520_mmcr->pioclr15_0 = 0x0180; /* reset SSI chip-selects */
  113. }
  114. sc520_mmcr->gpcsrt = 1; /* set the GP CS offset */
  115. sc520_mmcr->gpcspw = 3; /* set the GP CS pulse width */
  116. sc520_mmcr->gpcsoff = 1; /* set the GP CS offset */
  117. sc520_mmcr->gprdw = 3; /* set the RD pulse width */
  118. sc520_mmcr->gprdoff = 1; /* set the GP RD offset */
  119. sc520_mmcr->gpwrw = 3; /* set the GP WR pulse width */
  120. sc520_mmcr->gpwroff = 1; /* set the GP WR offset */
  121. sc520_mmcr->bootcsctl = 0x0407; /* set up timing of BOOTCS */
  122. /* adjust the memory map:
  123. * by default the first 256MB (0x00000000 - 0x0fffffff) is mapped to SDRAM
  124. * and 256MB to 1G-128k (0x1000000 - 0x37ffffff) is mapped to PCI mmio
  125. * we need to map 1G-128k - 1G (0x38000000 - 0x3fffffff) to CS1 */
  126. /* bootcs */
  127. sc520_mmcr->par[12] = 0x8bffe800;
  128. /* IDE0 = GPCS6 1f0-1f7 */
  129. sc520_mmcr->par[3] = 0x380801f0;
  130. /* IDE1 = GPCS7 3f6 */
  131. sc520_mmcr->par[4] = 0x3c0003f6;
  132. asm ("wbinvd\n"); /* Flush cache, req. after setting the unchached attribute ona PAR */
  133. sc520_mmcr->adddecctl = sc520_mmcr->adddecctl & ~(UART2_DIS|UART1_DIS);
  134. }
  135. /* par usage:
  136. * PAR0 (legacy_video)
  137. * PAR1 (PCI ROM mapping)
  138. * PAR2
  139. * PAR3 IDE
  140. * PAR4 IDE
  141. * PAR5 (legacy_video)
  142. * PAR6
  143. * PAR7 (legacy_video)
  144. * PAR8 (legacy_video)
  145. * PAR9 (legacy_video)
  146. * PAR10
  147. * PAR11 (ISAROM)
  148. * PAR12 BOOTCS
  149. * PAR13
  150. * PAR14
  151. * PAR15
  152. */
  153. /*
  154. * Miscelaneous platform dependent initialisations
  155. */
  156. int board_init(void)
  157. {
  158. init_sc520();
  159. bus_init();
  160. irq_init();
  161. /* max drive current on SDRAM */
  162. sc520_mmcr->dsctl = 0x0100;
  163. /* enter debug mode after next reset (only if jumper is also set) */
  164. sc520_mmcr->rescfg = 0x08;
  165. /* configure the software timer to 33.000MHz */
  166. sc520_mmcr->swtmrcfg = 1;
  167. gd->bus_clk = 33000000;
  168. return 0;
  169. }
  170. int dram_init(void)
  171. {
  172. init_sc520_dram();
  173. return 0;
  174. }
  175. void show_boot_progress(int val)
  176. {
  177. int version = sc520_mmcr->sysinfo;
  178. if (val < -32) val = -1; /* let things compatible */
  179. if (version == 0) {
  180. /* PIO31-PIO16 Data */
  181. sc520_mmcr->piodata31_16 = (sc520_mmcr->piodata31_16 & 0xffc0) | ((val&0x7e)>>1); /* 0x1f8 >> 3 */
  182. /* PIO0-PIO15 Data */
  183. sc520_mmcr->piodata15_0 = (sc520_mmcr->piodata15_0 & 0x1fff)| ((val&0x7)<<13);
  184. } else {
  185. /* newer boards use PIO4-PIO12 */
  186. /* PIO0-PIO15 Data */
  187. #if 0
  188. val = (val & 0x007) | ((val & 0x038) << 3) | ((val & 0x1c0) >> 3);
  189. #else
  190. val = (val & 0x007) | ((val & 0x07e) << 2);
  191. #endif
  192. sc520_mmcr->piodata15_0 = (sc520_mmcr->piodata15_0 & 0xe00f) | ((val&0x01ff)<<4);
  193. }
  194. }
  195. int last_stage_init(void)
  196. {
  197. int version = sc520_mmcr->sysinfo;
  198. printf("Omicron Ceti SC520 Spunk revision %x\n", version);
  199. #if 0
  200. if (version) {
  201. int x, y;
  202. printf("eeprom probe %d\n", spi_eeprom_probe(1));
  203. spi_eeprom_read(1, 0, (u8*)&x, 2);
  204. spi_eeprom_read(1, 1, (u8*)&y, 2);
  205. printf("eeprom bytes %04x%04x\n", x, y);
  206. x ^= 0xffff;
  207. y ^= 0xffff;
  208. spi_eeprom_write(1, 0, (u8*)&x, 2);
  209. spi_eeprom_write(1, 1, (u8*)&y, 2);
  210. spi_eeprom_read(1, 0, (u8*)&x, 2);
  211. spi_eeprom_read(1, 1, (u8*)&y, 2);
  212. printf("eeprom bytes %04x%04x\n", x, y);
  213. } else {
  214. int x, y;
  215. printf("eeprom probe %d\n", mw_eeprom_probe(1));
  216. mw_eeprom_read(1, 0, (u8*)&x, 2);
  217. mw_eeprom_read(1, 1, (u8*)&y, 2);
  218. printf("eeprom bytes %04x%04x\n", x, y);
  219. x ^= 0xffff;
  220. y ^= 0xffff;
  221. mw_eeprom_write(1, 0, (u8*)&x, 2);
  222. mw_eeprom_write(1, 1, (u8*)&y, 2);
  223. mw_eeprom_read(1, 0, (u8*)&x, 2);
  224. mw_eeprom_read(1, 1, (u8*)&y, 2);
  225. printf("eeprom bytes %04x%04x\n", x, y);
  226. }
  227. #endif
  228. ds1722_probe(2);
  229. return 0;
  230. }
  231. void ssi_chip_select(int dev)
  232. {
  233. int version = sc520_mmcr->sysinfo;
  234. if (version) {
  235. /* Spunk board: EEPROM and CAN are actove-low, TEMP and AUX are active high */
  236. switch (dev) {
  237. case 1: /* EEPROM */
  238. sc520_mmcr->pioclr31_16 = 0x0004;
  239. break;
  240. case 2: /* Temp Probe */
  241. sc520_mmcr->pioset31_16 = 0x0002;
  242. break;
  243. case 3: /* CAN */
  244. sc520_mmcr->pioclr31_16 = 0x0008;
  245. break;
  246. case 4: /* AUX */
  247. sc520_mmcr->pioset31_16 = 0x0001;
  248. break;
  249. case 0:
  250. sc520_mmcr->pioclr31_16 = 0x0003;
  251. sc520_mmcr->pioset31_16 = 0x000c;
  252. break;
  253. default:
  254. printf("Illegal SSI device requested: %d\n", dev);
  255. }
  256. } else {
  257. /* Globox board: Both EEPROM and TEMP are active-high */
  258. switch (dev) {
  259. case 1: /* EEPROM */
  260. sc520_mmcr->pioset15_0 = 0x0100;
  261. break;
  262. case 2: /* Temp Probe */
  263. sc520_mmcr->pioset15_0 = 0x0080;
  264. break;
  265. case 0:
  266. sc520_mmcr->pioclr15_0 = 0x0180;
  267. break;
  268. default:
  269. printf("Illegal SSI device requested: %d\n", dev);
  270. }
  271. }
  272. }
  273. void spi_eeprom_probe(int x)
  274. {
  275. }
  276. int spi_eeprom_read(int x, int offset, uchar *buffer, int len)
  277. {
  278. return 0;
  279. }
  280. int spi_eeprom_write(int x, int offset, uchar *buffer, int len)
  281. {
  282. return 0;
  283. }
  284. void mw_eeprom_probe(int x)
  285. {
  286. }
  287. int mw_eeprom_read(int x, int offset, uchar *buffer, int len)
  288. {
  289. return 0;
  290. }
  291. int mw_eeprom_write(int x, int offset, uchar *buffer, int len)
  292. {
  293. return 0;
  294. }
  295. void spi_init_f(void)
  296. {
  297. sc520_mmcr->sysinfo ? spi_eeprom_probe(1) : mw_eeprom_probe(1);
  298. }
  299. ssize_t spi_read(uchar *addr, int alen, uchar *buffer, int len)
  300. {
  301. int offset;
  302. int i;
  303. offset = 0;
  304. for (i=0;i<alen;i++) {
  305. offset <<= 8;
  306. offset |= addr[i];
  307. }
  308. return sc520_mmcr->sysinfo ?
  309. spi_eeprom_read(1, offset, buffer, len) :
  310. mw_eeprom_read(1, offset, buffer, len);
  311. }
  312. ssize_t spi_write(uchar *addr, int alen, uchar *buffer, int len)
  313. {
  314. int offset;
  315. int i;
  316. offset = 0;
  317. for (i=0;i<alen;i++) {
  318. offset <<= 8;
  319. offset |= addr[i];
  320. }
  321. return sc520_mmcr->sysinfo ?
  322. spi_eeprom_write(1, offset, buffer, len) :
  323. mw_eeprom_write(1, offset, buffer, len);
  324. }
  325. int board_eth_init(bd_t *bis)
  326. {
  327. return pci_eth_init(bis);
  328. }