sc520_spunk.c 19 KB

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