sandpoint.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /*
  2. * arch/ppc/platforms/sandpoint_setup.c
  3. *
  4. * Board setup routines for the Motorola SPS Sandpoint Test Platform.
  5. *
  6. * Author: Mark A. Greer
  7. * mgreer@mvista.com
  8. *
  9. * 2000-2003 (c) MontaVista Software, Inc. This file is licensed under
  10. * the terms of the GNU General Public License version 2. This program
  11. * is licensed "as is" without any warranty of any kind, whether express
  12. * or implied.
  13. */
  14. /*
  15. * This file adds support for the Motorola SPS Sandpoint Test Platform.
  16. * These boards have a PPMC slot for the processor so any combination
  17. * of cpu and host bridge can be attached. This port is for an 8240 PPMC
  18. * module from Motorola SPS and other closely related cpu/host bridge
  19. * combinations (e.g., 750/755/7400 with MPC107 host bridge).
  20. * The sandpoint itself has a Windbond 83c553 (PCI-ISA bridge, 2 DMA ctlrs, 2
  21. * cascaded 8259 interrupt ctlrs, 8254 Timer/Counter, and an IDE ctlr), a
  22. * National 87308 (RTC, 2 UARTs, Keyboard & mouse ctlrs, and a floppy ctlr),
  23. * and 4 PCI slots (only 2 of which are usable; the other 2 are keyed for 3.3V
  24. * but are really 5V).
  25. *
  26. * The firmware on the sandpoint is called DINK (not my acronym :). This port
  27. * depends on DINK to do some basic initialization (e.g., initialize the memory
  28. * ctlr) and to ensure that the processor is using MAP B (CHRP map).
  29. *
  30. * The switch settings for the Sandpoint board MUST be as follows:
  31. * S3: down
  32. * S4: up
  33. * S5: up
  34. * S6: down
  35. *
  36. * 'down' is in the direction from the PCI slots towards the PPMC slot;
  37. * 'up' is in the direction from the PPMC slot towards the PCI slots.
  38. * Be careful, the way the sandpoint board is installed in XT chasses will
  39. * make the directions reversed.
  40. *
  41. * Since Motorola listened to our suggestions for improvement, we now have
  42. * the Sandpoint X3 board. All of the PCI slots are available, it uses
  43. * the serial interrupt interface (just a hardware thing we need to
  44. * configure properly).
  45. *
  46. * Use the default X3 switch settings. The interrupts are then:
  47. * EPIC Source
  48. * 0 SIOINT (8259, active low)
  49. * 1 PCI #1
  50. * 2 PCI #2
  51. * 3 PCI #3
  52. * 4 PCI #4
  53. * 7 Winbond INTC (IDE interrupt)
  54. * 8 Winbond INTD (IDE interrupt)
  55. *
  56. *
  57. * Motorola has finally released a version of DINK32 that correctly
  58. * (seemingly) initalizes the memory controller correctly, regardless
  59. * of the amount of memory in the system. Once a method of determining
  60. * what version of DINK initializes the system for us, if applicable, is
  61. * found, we can hopefully stop hardcoding 32MB of RAM.
  62. */
  63. #include <linux/config.h>
  64. #include <linux/stddef.h>
  65. #include <linux/kernel.h>
  66. #include <linux/init.h>
  67. #include <linux/errno.h>
  68. #include <linux/reboot.h>
  69. #include <linux/pci.h>
  70. #include <linux/kdev_t.h>
  71. #include <linux/major.h>
  72. #include <linux/initrd.h>
  73. #include <linux/console.h>
  74. #include <linux/delay.h>
  75. #include <linux/ide.h>
  76. #include <linux/seq_file.h>
  77. #include <linux/root_dev.h>
  78. #include <linux/serial.h>
  79. #include <linux/tty.h> /* for linux/serial_core.h */
  80. #include <linux/serial_core.h>
  81. #include <linux/serial_8250.h>
  82. #include <asm/system.h>
  83. #include <asm/pgtable.h>
  84. #include <asm/page.h>
  85. #include <asm/time.h>
  86. #include <asm/dma.h>
  87. #include <asm/io.h>
  88. #include <asm/machdep.h>
  89. #include <asm/prom.h>
  90. #include <asm/smp.h>
  91. #include <asm/vga.h>
  92. #include <asm/open_pic.h>
  93. #include <asm/i8259.h>
  94. #include <asm/todc.h>
  95. #include <asm/bootinfo.h>
  96. #include <asm/mpc10x.h>
  97. #include <asm/pci-bridge.h>
  98. #include <asm/kgdb.h>
  99. #include <asm/ppc_sys.h>
  100. #include "sandpoint.h"
  101. /* Set non-zero if an X2 Sandpoint detected. */
  102. static int sandpoint_is_x2;
  103. unsigned char __res[sizeof(bd_t)];
  104. static void sandpoint_halt(void);
  105. static void sandpoint_probe_type(void);
  106. /*
  107. * Define all of the IRQ senses and polarities. Taken from the
  108. * Sandpoint X3 User's manual.
  109. */
  110. static u_char sandpoint_openpic_initsenses[] __initdata = {
  111. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* 0: SIOINT */
  112. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* 2: PCI Slot 1 */
  113. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* 3: PCI Slot 2 */
  114. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* 4: PCI Slot 3 */
  115. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* 5: PCI Slot 4 */
  116. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* 8: IDE (INT C) */
  117. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE) /* 9: IDE (INT D) */
  118. };
  119. /*
  120. * Motorola SPS Sandpoint interrupt routing.
  121. */
  122. static inline int
  123. x3_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  124. {
  125. static char pci_irq_table[][4] =
  126. /*
  127. * PCI IDSEL/INTPIN->INTLINE
  128. * A B C D
  129. */
  130. {
  131. { 16, 0, 0, 0 }, /* IDSEL 11 - i8259 on Winbond */
  132. { 0, 0, 0, 0 }, /* IDSEL 12 - unused */
  133. { 18, 21, 20, 19 }, /* IDSEL 13 - PCI slot 1 */
  134. { 19, 18, 21, 20 }, /* IDSEL 14 - PCI slot 2 */
  135. { 20, 19, 18, 21 }, /* IDSEL 15 - PCI slot 3 */
  136. { 21, 20, 19, 18 }, /* IDSEL 16 - PCI slot 4 */
  137. };
  138. const long min_idsel = 11, max_idsel = 16, irqs_per_slot = 4;
  139. return PCI_IRQ_TABLE_LOOKUP;
  140. }
  141. static inline int
  142. x2_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  143. {
  144. static char pci_irq_table[][4] =
  145. /*
  146. * PCI IDSEL/INTPIN->INTLINE
  147. * A B C D
  148. */
  149. {
  150. { 18, 0, 0, 0 }, /* IDSEL 11 - i8259 on Windbond */
  151. { 0, 0, 0, 0 }, /* IDSEL 12 - unused */
  152. { 16, 17, 18, 19 }, /* IDSEL 13 - PCI slot 1 */
  153. { 17, 18, 19, 16 }, /* IDSEL 14 - PCI slot 2 */
  154. { 18, 19, 16, 17 }, /* IDSEL 15 - PCI slot 3 */
  155. { 19, 16, 17, 18 }, /* IDSEL 16 - PCI slot 4 */
  156. };
  157. const long min_idsel = 11, max_idsel = 16, irqs_per_slot = 4;
  158. return PCI_IRQ_TABLE_LOOKUP;
  159. }
  160. static void __init
  161. sandpoint_setup_winbond_83553(struct pci_controller *hose)
  162. {
  163. int devfn;
  164. /*
  165. * Route IDE interrupts directly to the 8259's IRQ 14 & 15.
  166. * We can't route the IDE interrupt to PCI INTC# or INTD# because those
  167. * woule interfere with the PMC's INTC# and INTD# lines.
  168. */
  169. /*
  170. * Winbond Fcn 0
  171. */
  172. devfn = PCI_DEVFN(11,0);
  173. early_write_config_byte(hose,
  174. 0,
  175. devfn,
  176. 0x43, /* IDE Interrupt Routing Control */
  177. 0xef);
  178. early_write_config_word(hose,
  179. 0,
  180. devfn,
  181. 0x44, /* PCI Interrupt Routing Control */
  182. 0x0000);
  183. /* Want ISA memory cycles to be forwarded to PCI bus */
  184. early_write_config_byte(hose,
  185. 0,
  186. devfn,
  187. 0x48, /* ISA-to-PCI Addr Decoder Control */
  188. 0xf0);
  189. /* Enable Port 92. */
  190. early_write_config_byte(hose,
  191. 0,
  192. devfn,
  193. 0x4e, /* AT System Control Register */
  194. 0x06);
  195. /*
  196. * Winbond Fcn 1
  197. */
  198. devfn = PCI_DEVFN(11,1);
  199. /* Put IDE controller into native mode. */
  200. early_write_config_byte(hose,
  201. 0,
  202. devfn,
  203. 0x09, /* Programming interface Register */
  204. 0x8f);
  205. /* Init IRQ routing, enable both ports, disable fast 16 */
  206. early_write_config_dword(hose,
  207. 0,
  208. devfn,
  209. 0x40, /* IDE Control/Status Register */
  210. 0x00ff0011);
  211. return;
  212. }
  213. /* On the sandpoint X2, we must avoid sending configuration cycles to
  214. * device #12 (IDSEL addr = AD12).
  215. */
  216. static int
  217. x2_exclude_device(u_char bus, u_char devfn)
  218. {
  219. if ((bus == 0) && (PCI_SLOT(devfn) == SANDPOINT_HOST_BRIDGE_IDSEL))
  220. return PCIBIOS_DEVICE_NOT_FOUND;
  221. else
  222. return PCIBIOS_SUCCESSFUL;
  223. }
  224. static void __init
  225. sandpoint_find_bridges(void)
  226. {
  227. struct pci_controller *hose;
  228. hose = pcibios_alloc_controller();
  229. if (!hose)
  230. return;
  231. hose->first_busno = 0;
  232. hose->last_busno = 0xff;
  233. if (mpc10x_bridge_init(hose,
  234. MPC10X_MEM_MAP_B,
  235. MPC10X_MEM_MAP_B,
  236. MPC10X_MAPB_EUMB_BASE) == 0) {
  237. /* Do early winbond init, then scan PCI bus */
  238. sandpoint_setup_winbond_83553(hose);
  239. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  240. ppc_md.pcibios_fixup = NULL;
  241. ppc_md.pcibios_fixup_bus = NULL;
  242. ppc_md.pci_swizzle = common_swizzle;
  243. if (sandpoint_is_x2) {
  244. ppc_md.pci_map_irq = x2_map_irq;
  245. ppc_md.pci_exclude_device = x2_exclude_device;
  246. } else
  247. ppc_md.pci_map_irq = x3_map_irq;
  248. }
  249. else {
  250. if (ppc_md.progress)
  251. ppc_md.progress("Bridge init failed", 0x100);
  252. printk("Host bridge init failed\n");
  253. }
  254. return;
  255. }
  256. static void __init
  257. sandpoint_setup_arch(void)
  258. {
  259. /* Probe for Sandpoint model */
  260. sandpoint_probe_type();
  261. if (sandpoint_is_x2)
  262. epic_serial_mode = 0;
  263. loops_per_jiffy = 100000000 / HZ;
  264. #ifdef CONFIG_BLK_DEV_INITRD
  265. if (initrd_start)
  266. ROOT_DEV = Root_RAM0;
  267. else
  268. #endif
  269. #ifdef CONFIG_ROOT_NFS
  270. ROOT_DEV = Root_NFS;
  271. #else
  272. ROOT_DEV = Root_HDA1;
  273. #endif
  274. /* Lookup PCI host bridges */
  275. sandpoint_find_bridges();
  276. if (strncmp (cur_ppc_sys_spec->ppc_sys_name, "8245", 4) == 0)
  277. {
  278. bd_t *bp = (bd_t *)__res;
  279. struct plat_serial8250_port *pdata;
  280. pdata = (struct plat_serial8250_port *) ppc_sys_get_pdata(MPC10X_UART0);
  281. if (pdata)
  282. {
  283. pdata[0].uartclk = bp->bi_busfreq;
  284. }
  285. #ifdef CONFIG_SANDPOINT_ENABLE_UART1
  286. pdata = (struct plat_serial8250_port *) ppc_sys_get_pdata(MPC10X_UART1);
  287. if (pdata)
  288. {
  289. pdata[0].uartclk = bp->bi_busfreq;
  290. }
  291. #else
  292. ppc_sys_device_remove(MPC10X_UART1);
  293. #endif
  294. }
  295. printk(KERN_INFO "Motorola SPS Sandpoint Test Platform\n");
  296. printk(KERN_INFO "Port by MontaVista Software, Inc. (source@mvista.com)\n");
  297. /* DINK32 12.3 and below do not correctly enable any caches.
  298. * We will do this now with good known values. Future versions
  299. * of DINK32 are supposed to get this correct.
  300. */
  301. if (cpu_has_feature(CPU_FTR_SPEC7450))
  302. /* 745x is different. We only want to pass along enable. */
  303. _set_L2CR(L2CR_L2E);
  304. else if (cpu_has_feature(CPU_FTR_L2CR))
  305. /* All modules have 1MB of L2. We also assume that an
  306. * L2 divisor of 3 will work.
  307. */
  308. _set_L2CR(L2CR_L2E | L2CR_L2SIZ_1MB | L2CR_L2CLK_DIV3
  309. | L2CR_L2RAM_PIPE | L2CR_L2OH_1_0 | L2CR_L2DF);
  310. #if 0
  311. /* Untested right now. */
  312. if (cpu_has_feature(CPU_FTR_L3CR)) {
  313. /* Magic value. */
  314. _set_L3CR(0x8f032000);
  315. }
  316. #endif
  317. }
  318. #define SANDPOINT_87308_CFG_ADDR 0x15c
  319. #define SANDPOINT_87308_CFG_DATA 0x15d
  320. #define SANDPOINT_87308_CFG_INB(addr, byte) { \
  321. outb((addr), SANDPOINT_87308_CFG_ADDR); \
  322. (byte) = inb(SANDPOINT_87308_CFG_DATA); \
  323. }
  324. #define SANDPOINT_87308_CFG_OUTB(addr, byte) { \
  325. outb((addr), SANDPOINT_87308_CFG_ADDR); \
  326. outb((byte), SANDPOINT_87308_CFG_DATA); \
  327. }
  328. #define SANDPOINT_87308_SELECT_DEV(dev_num) { \
  329. SANDPOINT_87308_CFG_OUTB(0x07, (dev_num)); \
  330. }
  331. #define SANDPOINT_87308_DEV_ENABLE(dev_num) { \
  332. SANDPOINT_87308_SELECT_DEV(dev_num); \
  333. SANDPOINT_87308_CFG_OUTB(0x30, 0x01); \
  334. }
  335. /*
  336. * To probe the Sandpoint type, we need to check for a connection between GPIO
  337. * pins 6 and 7 on the NS87308 SuperIO.
  338. */
  339. static void __init sandpoint_probe_type(void)
  340. {
  341. u8 x;
  342. /* First, ensure that the GPIO pins are enabled. */
  343. SANDPOINT_87308_SELECT_DEV(0x07); /* Select GPIO logical device */
  344. SANDPOINT_87308_CFG_OUTB(0x60, 0x07); /* Base address 0x700 */
  345. SANDPOINT_87308_CFG_OUTB(0x61, 0x00);
  346. SANDPOINT_87308_CFG_OUTB(0x30, 0x01); /* Enable */
  347. /* Now, set pin 7 to output and pin 6 to input. */
  348. outb((inb(0x701) | 0x80) & 0xbf, 0x701);
  349. /* Set push-pull output */
  350. outb(inb(0x702) | 0x80, 0x702);
  351. /* Set pull-up on input */
  352. outb(inb(0x703) | 0x40, 0x703);
  353. /* Set output high and check */
  354. x = inb(0x700);
  355. outb(x | 0x80, 0x700);
  356. x = inb(0x700);
  357. sandpoint_is_x2 = ! (x & 0x40);
  358. if (ppc_md.progress && sandpoint_is_x2)
  359. ppc_md.progress("High output says X2", 0);
  360. /* Set output low and check */
  361. outb(x & 0x7f, 0x700);
  362. sandpoint_is_x2 |= inb(0x700) & 0x40;
  363. if (ppc_md.progress && sandpoint_is_x2)
  364. ppc_md.progress("Low output says X2", 0);
  365. if (ppc_md.progress && ! sandpoint_is_x2)
  366. ppc_md.progress("Sandpoint is X3", 0);
  367. }
  368. /*
  369. * Fix IDE interrupts.
  370. */
  371. static int __init
  372. sandpoint_fix_winbond_83553(void)
  373. {
  374. /* Make some 8259 interrupt level sensitive */
  375. outb(0xe0, 0x4d0);
  376. outb(0xde, 0x4d1);
  377. return 0;
  378. }
  379. arch_initcall(sandpoint_fix_winbond_83553);
  380. /*
  381. * Initialize the ISA devices on the Nat'l PC87308VUL SuperIO chip.
  382. */
  383. static int __init
  384. sandpoint_setup_natl_87308(void)
  385. {
  386. u_char reg;
  387. /*
  388. * Enable all the devices on the Super I/O chip.
  389. */
  390. SANDPOINT_87308_SELECT_DEV(0x00); /* Select kbd logical device */
  391. SANDPOINT_87308_CFG_OUTB(0xf0, 0x00); /* Set KBC clock to 8 Mhz */
  392. SANDPOINT_87308_DEV_ENABLE(0x00); /* Enable keyboard */
  393. SANDPOINT_87308_DEV_ENABLE(0x01); /* Enable mouse */
  394. SANDPOINT_87308_DEV_ENABLE(0x02); /* Enable rtc */
  395. SANDPOINT_87308_DEV_ENABLE(0x03); /* Enable fdc (floppy) */
  396. SANDPOINT_87308_DEV_ENABLE(0x04); /* Enable parallel */
  397. SANDPOINT_87308_DEV_ENABLE(0x05); /* Enable UART 2 */
  398. SANDPOINT_87308_CFG_OUTB(0xf0, 0x82); /* Enable bank select regs */
  399. SANDPOINT_87308_DEV_ENABLE(0x06); /* Enable UART 1 */
  400. SANDPOINT_87308_CFG_OUTB(0xf0, 0x82); /* Enable bank select regs */
  401. /* Set up floppy in PS/2 mode */
  402. outb(0x09, SIO_CONFIG_RA);
  403. reg = inb(SIO_CONFIG_RD);
  404. reg = (reg & 0x3F) | 0x40;
  405. outb(reg, SIO_CONFIG_RD);
  406. outb(reg, SIO_CONFIG_RD); /* Have to write twice to change! */
  407. return 0;
  408. }
  409. arch_initcall(sandpoint_setup_natl_87308);
  410. static int __init
  411. sandpoint_request_io(void)
  412. {
  413. request_region(0x00,0x20,"dma1");
  414. request_region(0x20,0x20,"pic1");
  415. request_region(0x40,0x20,"timer");
  416. request_region(0x80,0x10,"dma page reg");
  417. request_region(0xa0,0x20,"pic2");
  418. request_region(0xc0,0x20,"dma2");
  419. return 0;
  420. }
  421. arch_initcall(sandpoint_request_io);
  422. /*
  423. * Interrupt setup and service. Interrrupts on the Sandpoint come
  424. * from the four PCI slots plus the 8259 in the Winbond Super I/O (SIO).
  425. * The 8259 is cascaded from EPIC IRQ0, IRQ1-4 map to PCI slots 1-4,
  426. * IDE is on EPIC 7 and 8.
  427. */
  428. static void __init
  429. sandpoint_init_IRQ(void)
  430. {
  431. int i;
  432. OpenPIC_InitSenses = sandpoint_openpic_initsenses;
  433. OpenPIC_NumInitSenses = sizeof(sandpoint_openpic_initsenses);
  434. mpc10x_set_openpic();
  435. openpic_hookup_cascade(sandpoint_is_x2 ? 17 : NUM_8259_INTERRUPTS, "82c59 cascade",
  436. i8259_irq);
  437. /*
  438. * The EPIC allows for a read in the range of 0xFEF00000 ->
  439. * 0xFEFFFFFF to generate a PCI interrupt-acknowledge transaction.
  440. */
  441. i8259_init(0xfef00000, 0);
  442. }
  443. static unsigned long __init
  444. sandpoint_find_end_of_memory(void)
  445. {
  446. bd_t *bp = (bd_t *)__res;
  447. if (bp->bi_memsize)
  448. return bp->bi_memsize;
  449. /* DINK32 13.0 correctly initalizes things, so iff you use
  450. * this you _should_ be able to change this instead of a
  451. * hardcoded value. */
  452. #if 0
  453. return mpc10x_get_mem_size(MPC10X_MEM_MAP_B);
  454. #else
  455. return 32*1024*1024;
  456. #endif
  457. }
  458. static void __init
  459. sandpoint_map_io(void)
  460. {
  461. io_block_mapping(0xfe000000, 0xfe000000, 0x02000000, _PAGE_IO);
  462. }
  463. static void
  464. sandpoint_restart(char *cmd)
  465. {
  466. local_irq_disable();
  467. /* Set exception prefix high - to the firmware */
  468. _nmask_and_or_msr(0, MSR_IP);
  469. /* Reset system via Port 92 */
  470. outb(0x00, 0x92);
  471. outb(0x01, 0x92);
  472. for(;;); /* Spin until reset happens */
  473. }
  474. static void
  475. sandpoint_power_off(void)
  476. {
  477. local_irq_disable();
  478. for(;;); /* No way to shut power off with software */
  479. /* NOTREACHED */
  480. }
  481. static void
  482. sandpoint_halt(void)
  483. {
  484. sandpoint_power_off();
  485. /* NOTREACHED */
  486. }
  487. static int
  488. sandpoint_show_cpuinfo(struct seq_file *m)
  489. {
  490. seq_printf(m, "vendor\t\t: Motorola SPS\n");
  491. seq_printf(m, "machine\t\t: Sandpoint\n");
  492. return 0;
  493. }
  494. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
  495. /*
  496. * IDE support.
  497. */
  498. static int sandpoint_ide_ports_known = 0;
  499. static unsigned long sandpoint_ide_regbase[MAX_HWIFS];
  500. static unsigned long sandpoint_ide_ctl_regbase[MAX_HWIFS];
  501. static unsigned long sandpoint_idedma_regbase;
  502. static void
  503. sandpoint_ide_probe(void)
  504. {
  505. struct pci_dev *pdev = pci_get_device(PCI_VENDOR_ID_WINBOND,
  506. PCI_DEVICE_ID_WINBOND_82C105, NULL);
  507. if (pdev) {
  508. sandpoint_ide_regbase[0]=pdev->resource[0].start;
  509. sandpoint_ide_regbase[1]=pdev->resource[2].start;
  510. sandpoint_ide_ctl_regbase[0]=pdev->resource[1].start;
  511. sandpoint_ide_ctl_regbase[1]=pdev->resource[3].start;
  512. sandpoint_idedma_regbase=pdev->resource[4].start;
  513. pci_dev_put(pdev);
  514. }
  515. sandpoint_ide_ports_known = 1;
  516. }
  517. static int
  518. sandpoint_ide_default_irq(unsigned long base)
  519. {
  520. if (sandpoint_ide_ports_known == 0)
  521. sandpoint_ide_probe();
  522. if (base == sandpoint_ide_regbase[0])
  523. return SANDPOINT_IDE_INT0;
  524. else if (base == sandpoint_ide_regbase[1])
  525. return SANDPOINT_IDE_INT1;
  526. else
  527. return 0;
  528. }
  529. static unsigned long
  530. sandpoint_ide_default_io_base(int index)
  531. {
  532. if (sandpoint_ide_ports_known == 0)
  533. sandpoint_ide_probe();
  534. return sandpoint_ide_regbase[index];
  535. }
  536. static void __init
  537. sandpoint_ide_init_hwif_ports(hw_regs_t *hw, unsigned long data_port,
  538. unsigned long ctrl_port, int *irq)
  539. {
  540. unsigned long reg = data_port;
  541. uint alt_status_base;
  542. int i;
  543. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
  544. hw->io_ports[i] = reg++;
  545. }
  546. if (data_port == sandpoint_ide_regbase[0]) {
  547. alt_status_base = sandpoint_ide_ctl_regbase[0] + 2;
  548. hw->irq = 14;
  549. }
  550. else if (data_port == sandpoint_ide_regbase[1]) {
  551. alt_status_base = sandpoint_ide_ctl_regbase[1] + 2;
  552. hw->irq = 15;
  553. }
  554. else {
  555. alt_status_base = 0;
  556. hw->irq = 0;
  557. }
  558. if (ctrl_port) {
  559. hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
  560. } else {
  561. hw->io_ports[IDE_CONTROL_OFFSET] = alt_status_base;
  562. }
  563. if (irq != NULL) {
  564. *irq = hw->irq;
  565. }
  566. }
  567. #endif
  568. /*
  569. * Set BAT 3 to map 0xf8000000 to end of physical memory space 1-to-1.
  570. */
  571. static __inline__ void
  572. sandpoint_set_bat(void)
  573. {
  574. unsigned long bat3u, bat3l;
  575. __asm__ __volatile__(
  576. " lis %0,0xf800\n \
  577. ori %1,%0,0x002a\n \
  578. ori %0,%0,0x0ffe\n \
  579. mtspr 0x21e,%0\n \
  580. mtspr 0x21f,%1\n \
  581. isync\n \
  582. sync "
  583. : "=r" (bat3u), "=r" (bat3l));
  584. }
  585. TODC_ALLOC();
  586. void __init
  587. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  588. unsigned long r6, unsigned long r7)
  589. {
  590. parse_bootinfo(find_bootinfo());
  591. /* ASSUMPTION: If both r3 (bd_t pointer) and r6 (cmdline pointer)
  592. * are non-zero, then we should use the board info from the bd_t
  593. * structure and the cmdline pointed to by r6 instead of the
  594. * information from birecs, if any. Otherwise, use the information
  595. * from birecs as discovered by the preceeding call to
  596. * parse_bootinfo(). This rule should work with both PPCBoot, which
  597. * uses a bd_t board info structure, and the kernel boot wrapper,
  598. * which uses birecs.
  599. */
  600. if (r3 && r6) {
  601. /* copy board info structure */
  602. memcpy( (void *)__res,(void *)(r3+KERNELBASE), sizeof(bd_t) );
  603. /* copy command line */
  604. *(char *)(r7+KERNELBASE) = 0;
  605. strcpy(cmd_line, (char *)(r6+KERNELBASE));
  606. }
  607. #ifdef CONFIG_BLK_DEV_INITRD
  608. /* take care of initrd if we have one */
  609. if (r4) {
  610. initrd_start = r4 + KERNELBASE;
  611. initrd_end = r5 + KERNELBASE;
  612. }
  613. #endif /* CONFIG_BLK_DEV_INITRD */
  614. /* Map in board regs, etc. */
  615. sandpoint_set_bat();
  616. isa_io_base = MPC10X_MAPB_ISA_IO_BASE;
  617. isa_mem_base = MPC10X_MAPB_ISA_MEM_BASE;
  618. pci_dram_offset = MPC10X_MAPB_DRAM_OFFSET;
  619. ISA_DMA_THRESHOLD = 0x00ffffff;
  620. DMA_MODE_READ = 0x44;
  621. DMA_MODE_WRITE = 0x48;
  622. ppc_do_canonicalize_irqs = 1;
  623. ppc_md.setup_arch = sandpoint_setup_arch;
  624. ppc_md.show_cpuinfo = sandpoint_show_cpuinfo;
  625. ppc_md.init_IRQ = sandpoint_init_IRQ;
  626. ppc_md.get_irq = openpic_get_irq;
  627. ppc_md.restart = sandpoint_restart;
  628. ppc_md.power_off = sandpoint_power_off;
  629. ppc_md.halt = sandpoint_halt;
  630. ppc_md.find_end_of_memory = sandpoint_find_end_of_memory;
  631. ppc_md.setup_io_mappings = sandpoint_map_io;
  632. TODC_INIT(TODC_TYPE_PC97307, 0x70, 0x00, 0x71, 8);
  633. ppc_md.time_init = todc_time_init;
  634. ppc_md.set_rtc_time = todc_set_rtc_time;
  635. ppc_md.get_rtc_time = todc_get_rtc_time;
  636. ppc_md.calibrate_decr = todc_calibrate_decr;
  637. ppc_md.nvram_read_val = todc_mc146818_read_val;
  638. ppc_md.nvram_write_val = todc_mc146818_write_val;
  639. #ifdef CONFIG_KGDB
  640. ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
  641. #endif
  642. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  643. ppc_md.progress = gen550_progress;
  644. #endif
  645. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
  646. ppc_ide_md.default_irq = sandpoint_ide_default_irq;
  647. ppc_ide_md.default_io_base = sandpoint_ide_default_io_base;
  648. ppc_ide_md.ide_init_hwif = sandpoint_ide_init_hwif_ports;
  649. #endif
  650. }