sc520_spunk.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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 <pci.h>
  26. #include <ssi.h>
  27. #include <netdev.h>
  28. #include <asm/io.h>
  29. #include <asm/pci.h>
  30. #include <asm/ic/sc520.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. /*
  33. * Theory:
  34. * We first set up all IRQs to be non-pci, edge triggered,
  35. * when we later enumerate the pci bus and pci_sc520_fixup_irq() gets
  36. * called we reallocate irqs to the pci bus with sc520_pci_set_irq()
  37. * as needed. Whe choose the irqs to gram from a configurable list
  38. * inside pci_sc520_fixup_irq() (If this list contains stupid irq's
  39. * such as 0 thngas will not work)
  40. */
  41. static void irq_init(void)
  42. {
  43. /* disable global interrupt mode */
  44. write_mmcr_byte(SC520_PICICR, 0x40);
  45. /* set all irqs to edge */
  46. write_mmcr_byte(SC520_MPICMODE, 0x00);
  47. write_mmcr_byte(SC520_SL1PICMODE, 0x00);
  48. write_mmcr_byte(SC520_SL2PICMODE, 0x00);
  49. /* active low polarity on PIC interrupt pins,
  50. * active high polarity on all other irq pins */
  51. write_mmcr_word(SC520_INTPINPOL, 0x0000);
  52. /* set irq number mapping */
  53. write_mmcr_byte(SC520_GPTMR0MAP, SC520_IRQ_DISABLED); /* disable GP timer 0 INT */
  54. write_mmcr_byte(SC520_GPTMR1MAP, SC520_IRQ_DISABLED); /* disable GP timer 1 INT */
  55. write_mmcr_byte(SC520_GPTMR2MAP, SC520_IRQ_DISABLED); /* disable GP timer 2 INT */
  56. write_mmcr_byte(SC520_PIT0MAP, SC520_IRQ0); /* Set PIT timer 0 INT to IRQ0 */
  57. write_mmcr_byte(SC520_PIT1MAP, SC520_IRQ_DISABLED); /* disable PIT timer 1 INT */
  58. write_mmcr_byte(SC520_PIT2MAP, SC520_IRQ_DISABLED); /* disable PIT timer 2 INT */
  59. write_mmcr_byte(SC520_PCIINTAMAP, SC520_IRQ_DISABLED); /* disable PCI INT A */
  60. write_mmcr_byte(SC520_PCIINTBMAP, SC520_IRQ_DISABLED); /* disable PCI INT B */
  61. write_mmcr_byte(SC520_PCIINTCMAP, SC520_IRQ_DISABLED); /* disable PCI INT C */
  62. write_mmcr_byte(SC520_PCIINTDMAP, SC520_IRQ_DISABLED); /* disable PCI INT D */
  63. write_mmcr_byte(SC520_DMABCINTMAP, SC520_IRQ_DISABLED); /* disable DMA INT */
  64. write_mmcr_byte(SC520_SSIMAP, SC520_IRQ6); /* Set Synchronius serial INT to IRQ6*/
  65. write_mmcr_byte(SC520_WDTMAP, SC520_IRQ_DISABLED); /* disable Watchdog INT */
  66. write_mmcr_byte(SC520_RTCMAP, SC520_IRQ8); /* Set RTC int to 8 */
  67. write_mmcr_byte(SC520_WPVMAP, SC520_IRQ_DISABLED); /* disable write protect INT */
  68. write_mmcr_byte(SC520_ICEMAP, SC520_IRQ1); /* Set ICE Debug Serielport INT to IRQ1 */
  69. write_mmcr_byte(SC520_FERRMAP,SC520_IRQ13); /* Set FP error INT to IRQ13 */
  70. write_mmcr_byte(SC520_UART1MAP, SC520_IRQ4); /* Set internal UART2 INT to IRQ4 */
  71. write_mmcr_byte(SC520_UART2MAP, SC520_IRQ3); /* Set internal UART2 INT to IRQ3 */
  72. write_mmcr_byte(SC520_GP0IMAP, SC520_IRQ7); /* Set GPIRQ0 (PC-Card AUX IRQ) to IRQ7 */
  73. write_mmcr_byte(SC520_GP1IMAP, SC520_IRQ14); /* Set GPIRQ1 (CF IRQ) to IRQ14 */
  74. write_mmcr_byte(SC520_GP3IMAP, SC520_IRQ5); /* Set GPIRQ3 ( CAN IRQ ) ti IRQ5 */
  75. write_mmcr_byte(SC520_GP4IMAP, SC520_IRQ_DISABLED); /* disbale GIRQ4 ( IRR IRQ ) */
  76. write_mmcr_byte(SC520_GP5IMAP, SC520_IRQ_DISABLED); /* disable GPIRQ5 */
  77. write_mmcr_byte(SC520_GP6IMAP, SC520_IRQ_DISABLED); /* disable GPIRQ6 */
  78. write_mmcr_byte(SC520_GP7IMAP, SC520_IRQ_DISABLED); /* disable GPIRQ7 */
  79. write_mmcr_byte(SC520_GP8IMAP, SC520_IRQ_DISABLED); /* disable GPIRQ8 */
  80. write_mmcr_byte(SC520_GP9IMAP, SC520_IRQ_DISABLED); /* disable GPIRQ9 */
  81. write_mmcr_byte(SC520_GP2IMAP, SC520_IRQ_DISABLED); /* disable GPIRQ2 */
  82. write_mmcr_byte(SC520_GP10IMAP,SC520_IRQ_DISABLED); /* disable GPIRQ10 */
  83. write_mmcr_word(SC520_PCIHOSTMAP, 0x11f); /* Map PCI hostbridge INT to NMI */
  84. write_mmcr_word(SC520_ECCMAP, 0x100); /* Map SDRAM ECC failure INT to NMI */
  85. }
  86. /* PCI stuff */
  87. static void pci_sc520_spunk_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  88. {
  89. int version = read_mmcr_byte(SC520_SYSINFO);
  90. /* a configurable lists of irqs to steal
  91. * when we need one (a board with more pci interrupt pins
  92. * would use a larger table */
  93. static int irq_list[] = {
  94. CONFIG_SYS_FIRST_PCI_IRQ,
  95. CONFIG_SYS_SECOND_PCI_IRQ,
  96. CONFIG_SYS_THIRD_PCI_IRQ,
  97. CONFIG_SYS_FORTH_PCI_IRQ
  98. };
  99. static int next_irq_index=0;
  100. char tmp_pin;
  101. int pin;
  102. pci_hose_read_config_byte(hose, dev, PCI_INTERRUPT_PIN, &tmp_pin);
  103. pin = tmp_pin;
  104. pin-=1; /* pci config space use 1-based numbering */
  105. if (-1 == pin) {
  106. return; /* device use no irq */
  107. }
  108. /* map device number + pin to a pin on the sc520 */
  109. switch (PCI_DEV(dev)) {
  110. case 6: /* ETH0 */
  111. pin+=SC520_PCI_INTA;
  112. break;
  113. case 7: /* ETH1 */
  114. pin+=SC520_PCI_INTB;
  115. break;
  116. case 8: /* Crypto */
  117. pin+=SC520_PCI_INTC;
  118. break;
  119. case 9: /* PMC slot */
  120. pin+=SC520_PCI_INTD;
  121. break;
  122. case 10: /* PC-Card */
  123. if (version < 10) {
  124. pin+=SC520_PCI_INTD;
  125. } else {
  126. pin+=SC520_PCI_INTC;
  127. }
  128. break;
  129. default:
  130. return;
  131. }
  132. pin&=3; /* wrap around */
  133. if (sc520_pci_ints[pin] == -1) {
  134. /* re-route one interrupt for us */
  135. if (next_irq_index > 3) {
  136. return;
  137. }
  138. if (pci_sc520_set_irq(pin, irq_list[next_irq_index])) {
  139. return;
  140. }
  141. next_irq_index++;
  142. }
  143. if (-1 != sc520_pci_ints[pin]) {
  144. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE,
  145. sc520_pci_ints[pin]);
  146. }
  147. #if 0
  148. printf("fixup_irq: device %d pin %c irq %d\n",
  149. PCI_DEV(dev), 'A' + pin, sc520_pci_ints[pin]);
  150. #endif
  151. }
  152. static void pci_sc520_spunk_configure_cardbus(struct pci_controller *hose,
  153. pci_dev_t dev, struct pci_config_table *te)
  154. {
  155. u32 io_base;
  156. u32 temp;
  157. pciauto_config_device(hose, dev);
  158. pci_hose_write_config_word(hose, dev, PCI_COMMAND, 0x07); /* enable device */
  159. pci_hose_write_config_byte(hose, dev, 0x0c, 0x10); /* cacheline size */
  160. pci_hose_write_config_byte(hose, dev, 0x0d, 0x40); /* latency timer */
  161. pci_hose_write_config_byte(hose, dev, 0x1b, 0x40); /* cardbus latency timer */
  162. pci_hose_write_config_word(hose, dev, PCI_BRIDGE_CONTROL, 0x0040); /* reset cardbus */
  163. pci_hose_write_config_word(hose, dev, PCI_BRIDGE_CONTROL, 0x0080); /* route interrupts though ExCA */
  164. pci_hose_write_config_word(hose, dev, 0x44, 0x3e0); /* map legacy I/O port to 0x3e0 */
  165. pci_hose_read_config_dword(hose, dev, 0x80, &temp); /* System control */
  166. pci_hose_write_config_dword(hose, dev, 0x80, temp | 0x60); /* System control: disable clockrun */
  167. /* route MF0 to ~INT and MF3 to IRQ7
  168. * reserve all others */
  169. pci_hose_write_config_dword(hose, dev, 0x8c, 0x00007002);
  170. pci_hose_write_config_byte(hose, dev, 0x91, 0x00); /* card control */
  171. pci_hose_write_config_byte(hose, dev, 0x92, 0x62); /* device control */
  172. if (te->device != 0xac56) {
  173. pci_hose_write_config_byte(hose, dev, 0x93, 0x21); /* async interrupt enable */
  174. pci_hose_write_config_word(hose, dev, 0xa8, 0x0000); /* reset GPIO */
  175. pci_hose_write_config_word(hose, dev, 0xac, 0x0000); /* reset GPIO */
  176. pci_hose_write_config_word(hose, dev, 0xaa, 0x0000); /* reset GPIO */
  177. pci_hose_write_config_word(hose, dev, 0xae, 0x0000); /* reset GPIO */
  178. } else {
  179. pci_hose_write_config_byte(hose, dev, 0x93, 0x20); /* */
  180. }
  181. pci_hose_write_config_word(hose, dev, 0xa4, 0x8000); /* reset power management */
  182. pci_hose_read_config_dword(hose, dev, PCI_BASE_ADDRESS_0, &io_base);
  183. io_base &= ~0xfL;
  184. writeb(0x07, io_base+0x803); /* route CSC irq though ExCA and enable IRQ7 */
  185. writel(0, io_base+0x10); /* CLKRUN default */
  186. writel(0, io_base+0x20); /* CLKRUN default */
  187. }
  188. static struct pci_config_table pci_sc520_spunk_config_table[] = {
  189. { 0x104c, 0xac50, PCI_ANY_ID, 0, 0x0a, 0, pci_sc520_spunk_configure_cardbus, { 0, 0, 0} },
  190. { 0x104c, 0xac56, PCI_ANY_ID, 0, 0x0a, 0, pci_sc520_spunk_configure_cardbus, { 0, 0, 0} },
  191. { 0, 0, 0, 0, 0, 0, NULL, {0,0,0}}
  192. };
  193. static struct pci_controller sc520_spunk_hose = {
  194. fixup_irq: pci_sc520_spunk_fixup_irq,
  195. config_table: pci_sc520_spunk_config_table,
  196. first_busno: 0x00,
  197. last_busno: 0xff,
  198. };
  199. void pci_init_board(void)
  200. {
  201. pci_sc520_init(&sc520_spunk_hose);
  202. }
  203. /* set up the ISA bus timing and system address mappings */
  204. static void bus_init(void)
  205. {
  206. /* versions
  207. * 0 Hyglo versions 0.95 and 0.96 (large baords)
  208. * ?? Hyglo version 0.97 (small board)
  209. * 10 Spunk board
  210. */
  211. int version = read_mmcr_byte(SC520_SYSINFO);
  212. if (version) {
  213. /* set up the GP IO pins (for the Spunk board) */
  214. write_mmcr_word(SC520_PIOPFS31_16, 0xfff0); /* set the GPIO pin function 31-16 reg */
  215. write_mmcr_word(SC520_PIOPFS15_0, 0x000f); /* set the GPIO pin function 15-0 reg */
  216. write_mmcr_word(SC520_PIODIR31_16, 0x000f); /* set the GPIO direction 31-16 reg */
  217. write_mmcr_word(SC520_PIODIR15_0, 0x1ff0); /* set the GPIO direction 15-0 reg */
  218. write_mmcr_byte(SC520_CSPFS, 0xc0); /* set the CS pin function reg */
  219. write_mmcr_byte(SC520_CLKSEL, 0x70);
  220. write_mmcr_word(SC520_PIOCLR31_16, 0x0003); /* reset SSI chip-selects */
  221. write_mmcr_word(SC520_PIOSET31_16, 0x000c);
  222. } else {
  223. /* set up the GP IO pins (for the Hyglo board) */
  224. write_mmcr_word(SC520_PIOPFS31_16, 0xffc0); /* set the GPIO pin function 31-16 reg */
  225. write_mmcr_word(SC520_PIOPFS15_0, 0x1e7f); /* set the GPIO pin function 15-0 reg */
  226. write_mmcr_word(SC520_PIODIR31_16, 0x003f); /* set the GPIO direction 31-16 reg */
  227. write_mmcr_word(SC520_PIODIR15_0, 0xe180); /* set the GPIO direction 15-0 reg */
  228. write_mmcr_byte(SC520_CSPFS, 0x00); /* set the CS pin function reg */
  229. write_mmcr_byte(SC520_CLKSEL, 0x70);
  230. write_mmcr_word(SC520_PIOCLR15_0, 0x0180); /* reset SSI chip-selects */
  231. }
  232. write_mmcr_byte(SC520_GPCSRT, 1); /* set the GP CS offset */
  233. write_mmcr_byte(SC520_GPCSPW, 3); /* set the GP CS pulse width */
  234. write_mmcr_byte(SC520_GPCSOFF, 1); /* set the GP CS offset */
  235. write_mmcr_byte(SC520_GPRDW, 3); /* set the RD pulse width */
  236. write_mmcr_byte(SC520_GPRDOFF, 1); /* set the GP RD offset */
  237. write_mmcr_byte(SC520_GPWRW, 3); /* set the GP WR pulse width */
  238. write_mmcr_byte(SC520_GPWROFF, 1); /* set the GP WR offset */
  239. write_mmcr_word(SC520_BOOTCSCTL, 0x0407); /* set up timing of BOOTCS */
  240. /* adjust the memory map:
  241. * by default the first 256MB (0x00000000 - 0x0fffffff) is mapped to SDRAM
  242. * and 256MB to 1G-128k (0x1000000 - 0x37ffffff) is mapped to PCI mmio
  243. * we need to map 1G-128k - 1G (0x38000000 - 0x3fffffff) to CS1 */
  244. /* bootcs */
  245. write_mmcr_long(SC520_PAR12, 0x8bffe800);
  246. /* IDE0 = GPCS6 1f0-1f7 */
  247. write_mmcr_long(SC520_PAR3, 0x380801f0);
  248. /* IDE1 = GPCS7 3f6 */
  249. write_mmcr_long(SC520_PAR4, 0x3c0003f6);
  250. asm ("wbinvd\n"); /* Flush cache, req. after setting the unchached attribute ona PAR */
  251. write_mmcr_byte(SC520_ADDDECCTL, read_mmcr_byte(SC520_ADDDECCTL) & ~(UART2_DIS|UART1_DIS));
  252. }
  253. /* par usage:
  254. * PAR0 (legacy_video)
  255. * PAR1 (PCI ROM mapping)
  256. * PAR2
  257. * PAR3 IDE
  258. * PAR4 IDE
  259. * PAR5 (legacy_video)
  260. * PAR6
  261. * PAR7 (legacy_video)
  262. * PAR8 (legacy_video)
  263. * PAR9 (legacy_video)
  264. * PAR10
  265. * PAR11 (ISAROM)
  266. * PAR12 BOOTCS
  267. * PAR13
  268. * PAR14
  269. * PAR15
  270. */
  271. /*
  272. * This function should map a chunk of size bytes
  273. * of the system address space to the ISA bus
  274. *
  275. * The function will return the memory address
  276. * as seen by the host (which may very will be the
  277. * same as the bus address)
  278. */
  279. u32 isa_map_rom(u32 bus_addr, int size)
  280. {
  281. u32 par;
  282. printf("isa_map_rom asked to map %d bytes at %x\n",
  283. size, bus_addr);
  284. par = size;
  285. if (par < 0x80000) {
  286. par = 0x80000;
  287. }
  288. par >>= 12;
  289. par--;
  290. par&=0x7f;
  291. par <<= 18;
  292. par |= (bus_addr>>12);
  293. par |= 0x50000000;
  294. printf ("setting PAR11 to %x\n", par);
  295. /* Map rom 0x10000 with PAR1 */
  296. write_mmcr_long(SC520_PAR11, par);
  297. return bus_addr;
  298. }
  299. /*
  300. * this function removed any mapping created
  301. * with pci_get_rom_window()
  302. */
  303. void isa_unmap_rom(u32 addr)
  304. {
  305. printf("isa_unmap_rom asked to unmap %x", addr);
  306. if ((addr>>12) == (read_mmcr_long(SC520_PAR11)&0x3ffff)) {
  307. write_mmcr_long(SC520_PAR11, 0);
  308. printf(" done\n");
  309. return;
  310. }
  311. printf(" not ours\n");
  312. }
  313. #ifdef CONFIG_PCI
  314. #define PCI_ROM_TEMP_SPACE 0x10000
  315. /*
  316. * This function should map a chunk of size bytes
  317. * of the system address space to the PCI bus,
  318. * suitable to map PCI ROMS (bus address < 16M)
  319. * the function will return the host memory address
  320. * which should be converted into a bus address
  321. * before used to configure the PCI rom address
  322. * decoder
  323. */
  324. u32 pci_get_rom_window(struct pci_controller *hose, int size)
  325. {
  326. u32 par;
  327. par = size;
  328. if (par < 0x80000) {
  329. par = 0x80000;
  330. }
  331. par >>= 16;
  332. par--;
  333. par&=0x7ff;
  334. par <<= 14;
  335. par |= (PCI_ROM_TEMP_SPACE>>16);
  336. par |= 0x72000000;
  337. printf ("setting PAR1 to %x\n", par);
  338. /* Map rom 0x10000 with PAR1 */
  339. write_mmcr_long(SC520_PAR1, par);
  340. return PCI_ROM_TEMP_SPACE;
  341. }
  342. /*
  343. * this function removed any mapping created
  344. * with pci_get_rom_window()
  345. */
  346. void pci_remove_rom_window(struct pci_controller *hose, u32 addr)
  347. {
  348. printf("pci_remove_rom_window: %x", addr);
  349. if (addr == PCI_ROM_TEMP_SPACE) {
  350. write_mmcr_long(SC520_PAR1, 0);
  351. printf(" done\n");
  352. return;
  353. }
  354. printf(" not ours\n");
  355. }
  356. /*
  357. * This function is called in order to provide acces to the
  358. * legacy video I/O ports on the PCI bus.
  359. * After this function accesses to I/O ports 0x3b0-0x3bb and
  360. * 0x3c0-0x3df shuld result in transactions on the PCI bus.
  361. *
  362. */
  363. int pci_enable_legacy_video_ports(struct pci_controller *hose)
  364. {
  365. /* Map video memory to 0xa0000*/
  366. write_mmcr_long(SC520_PAR0, 0x7200400a);
  367. /* forward all I/O accesses to PCI */
  368. write_mmcr_byte(SC520_ADDDECCTL,
  369. read_mmcr_byte(SC520_ADDDECCTL) | IO_HOLE_DEST_PCI);
  370. /* so we map away all io ports to pci (only way to access pci io
  371. * below 0x400. But then we have to map back the portions that we dont
  372. * use so that the generate cycles on the GPIO bus where the sio and
  373. * ISA slots are connected, this requre the use of several PAR registers
  374. */
  375. /* bring 0x100 - 0x2f7 back to ISA using PAR5 */
  376. write_mmcr_long(SC520_PAR5, 0x31f70100);
  377. /* com2 use 2f8-2ff */
  378. /* bring 0x300 - 0x3af back to ISA using PAR7 */
  379. write_mmcr_long(SC520_PAR7, 0x30af0300);
  380. /* vga use 3b0-3bb */
  381. /* bring 0x3bc - 0x3bf back to ISA using PAR8 */
  382. write_mmcr_long(SC520_PAR8, 0x300303bc);
  383. /* vga use 3c0-3df */
  384. /* bring 0x3e0 - 0x3f7 back to ISA using PAR9 */
  385. write_mmcr_long(SC520_PAR9, 0x301703e0);
  386. /* com1 use 3f8-3ff */
  387. return 0;
  388. }
  389. #endif
  390. /*
  391. * Miscelaneous platform dependent initialisations
  392. */
  393. int board_init(void)
  394. {
  395. init_sc520();
  396. bus_init();
  397. irq_init();
  398. /* max drive current on SDRAM */
  399. write_mmcr_word(SC520_DSCTL, 0x0100);
  400. /* enter debug mode after next reset (only if jumper is also set) */
  401. write_mmcr_byte(SC520_RESCFG, 0x08);
  402. /* configure the software timer to 33.000MHz */
  403. write_mmcr_byte(SC520_SWTMRCFG, 1);
  404. gd->bus_clk = 33000000;
  405. return 0;
  406. }
  407. int dram_init(void)
  408. {
  409. init_sc520_dram();
  410. return 0;
  411. }
  412. void show_boot_progress(int val)
  413. {
  414. int version = read_mmcr_byte(SC520_SYSINFO);
  415. if (val < -32) val = -1; /* let things compatible */
  416. if (version == 0) {
  417. /* PIO31-PIO16 Data */
  418. write_mmcr_word(SC520_PIODATA31_16,
  419. (read_mmcr_word(SC520_PIODATA31_16) & 0xffc0)| ((val&0x7e)>>1)); /* 0x1f8 >> 3 */
  420. /* PIO0-PIO15 Data */
  421. write_mmcr_word(SC520_PIODATA15_0,
  422. (read_mmcr_word(SC520_PIODATA15_0) & 0x1fff)| ((val&0x7)<<13));
  423. } else {
  424. /* newer boards use PIO4-PIO12 */
  425. /* PIO0-PIO15 Data */
  426. #if 0
  427. val = (val & 0x007) | ((val & 0x038) << 3) | ((val & 0x1c0) >> 3);
  428. #else
  429. val = (val & 0x007) | ((val & 0x07e) << 2);
  430. #endif
  431. write_mmcr_word(SC520_PIODATA15_0,
  432. (read_mmcr_word(SC520_PIODATA15_0) & 0xe00f) | ((val&0x01ff)<<4));
  433. }
  434. }
  435. int last_stage_init(void)
  436. {
  437. int version = read_mmcr_byte(SC520_SYSINFO);
  438. printf("Omicron Ceti SC520 Spunk revision %x\n", version);
  439. #if 0
  440. if (version) {
  441. int x, y;
  442. printf("eeprom probe %d\n", spi_eeprom_probe(1));
  443. spi_eeprom_read(1, 0, (u8*)&x, 2);
  444. spi_eeprom_read(1, 1, (u8*)&y, 2);
  445. printf("eeprom bytes %04x%04x\n", x, y);
  446. x ^= 0xffff;
  447. y ^= 0xffff;
  448. spi_eeprom_write(1, 0, (u8*)&x, 2);
  449. spi_eeprom_write(1, 1, (u8*)&y, 2);
  450. spi_eeprom_read(1, 0, (u8*)&x, 2);
  451. spi_eeprom_read(1, 1, (u8*)&y, 2);
  452. printf("eeprom bytes %04x%04x\n", x, y);
  453. } else {
  454. int x, y;
  455. printf("eeprom probe %d\n", mw_eeprom_probe(1));
  456. mw_eeprom_read(1, 0, (u8*)&x, 2);
  457. mw_eeprom_read(1, 1, (u8*)&y, 2);
  458. printf("eeprom bytes %04x%04x\n", x, y);
  459. x ^= 0xffff;
  460. y ^= 0xffff;
  461. mw_eeprom_write(1, 0, (u8*)&x, 2);
  462. mw_eeprom_write(1, 1, (u8*)&y, 2);
  463. mw_eeprom_read(1, 0, (u8*)&x, 2);
  464. mw_eeprom_read(1, 1, (u8*)&y, 2);
  465. printf("eeprom bytes %04x%04x\n", x, y);
  466. }
  467. #endif
  468. ds1722_probe(2);
  469. return 0;
  470. }
  471. void ssi_chip_select(int dev)
  472. {
  473. int version = read_mmcr_byte(SC520_SYSINFO);
  474. if (version) {
  475. /* Spunk board: EEPROM and CAN are actove-low, TEMP and AUX are active high */
  476. switch (dev) {
  477. case 1: /* EEPROM */
  478. write_mmcr_word(SC520_PIOCLR31_16, 0x0004);
  479. break;
  480. case 2: /* Temp Probe */
  481. write_mmcr_word(SC520_PIOSET31_16, 0x0002);
  482. break;
  483. case 3: /* CAN */
  484. write_mmcr_word(SC520_PIOCLR31_16, 0x0008);
  485. break;
  486. case 4: /* AUX */
  487. write_mmcr_word(SC520_PIOSET31_16, 0x0001);
  488. break;
  489. case 0:
  490. write_mmcr_word(SC520_PIOCLR31_16, 0x0003);
  491. write_mmcr_word(SC520_PIOSET31_16, 0x000c);
  492. break;
  493. default:
  494. printf("Illegal SSI device requested: %d\n", dev);
  495. }
  496. } else {
  497. /* Globox board: Both EEPROM and TEMP are active-high */
  498. switch (dev) {
  499. case 1: /* EEPROM */
  500. write_mmcr_word(SC520_PIOSET15_0, 0x0100);
  501. break;
  502. case 2: /* Temp Probe */
  503. write_mmcr_word(SC520_PIOSET15_0, 0x0080);
  504. break;
  505. case 0:
  506. write_mmcr_word(SC520_PIOCLR15_0, 0x0180);
  507. break;
  508. default:
  509. printf("Illegal SSI device requested: %d\n", dev);
  510. }
  511. }
  512. }
  513. void spi_init_f(void)
  514. {
  515. read_mmcr_byte(SC520_SYSINFO) ?
  516. spi_eeprom_probe(1) :
  517. mw_eeprom_probe(1);
  518. }
  519. ssize_t spi_read(uchar *addr, int alen, uchar *buffer, int len)
  520. {
  521. int offset;
  522. int i;
  523. offset = 0;
  524. for (i=0;i<alen;i++) {
  525. offset <<= 8;
  526. offset |= addr[i];
  527. }
  528. return read_mmcr_byte(SC520_SYSINFO) ?
  529. spi_eeprom_read(1, offset, buffer, len) :
  530. mw_eeprom_read(1, offset, buffer, len);
  531. }
  532. ssize_t spi_write(uchar *addr, int alen, uchar *buffer, int len)
  533. {
  534. int offset;
  535. int i;
  536. offset = 0;
  537. for (i=0;i<alen;i++) {
  538. offset <<= 8;
  539. offset |= addr[i];
  540. }
  541. return read_mmcr_byte(SC520_SYSINFO) ?
  542. spi_eeprom_write(1, offset, buffer, len) :
  543. mw_eeprom_write(1, offset, buffer, len);
  544. }
  545. int board_eth_init(bd_t *bis)
  546. {
  547. return pci_eth_init(bis);
  548. }